Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F7188873
markdown.test.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
markdown.test.ts
View Options
import
{
JDD
}
from
"../jdd.js"
;
import
{
Registry
}
from
"../registry.js"
;
import
{
Markdown
}
from
"./markdown.js"
;
import
{
documentContainerFromParsed
,
makeSimpleEnglishJDDContext
,
}
from
"../index.js"
;
import
assert
from
"assert"
;
import
{
FileManager
}
from
"@sealcode/file-manager"
;
import
{
formatWithPrettier
}
from
"../test-utils/prettier.js"
;
import
{
simplestContext
}
from
"../test-utils/simplest-context.js"
;
describe
(
"markdown component"
,
()
=>
{
it
(
"renders as a part of a JDD"
,
async
()
=>
{
const
document
=
documentContainerFromParsed
([
{
component_name
:
"markdown"
,
args
:
{
markdown
:
`# Hello World`
}
},
{
component_name
:
"markdown"
,
args
:
{
markdown
:
`Multiple components ftw`
},
},
]);
const
registry
=
new
Registry
();
registry
.
add
(
"markdown"
,
Markdown
);
const
result
=
await
new
JDD
(
registry
,
makeSimpleEnglishJDDContext
({
file_manager
:
new
FileManager
(
"/tmp"
,
"/uploaded_files"
),
}),
document
).
render
();
assert
.
strictEqual
(
await
formatWithPrettier
(
result
,
"html"
),
// note the soft hyphens
await
formatWithPrettier
(
/* HTML */
`<section class="jdd-component component-number-0">
<h1 id="hello-world">
<a class="anchor" href="#hello-world">
<span class="markdown-header-link"></span>
</a>
Hello World
</h1>
</section>
<section class="jdd-component component-number-1">
<p>Multiple components ftw</p>
</section>`
,
"html"
)
);
});
it
(
"properly returns the headings"
,
()
=>
{
const
headings
=
new
Markdown
().
getHeadings
(
makeSimpleEnglishJDDContext
({
file_manager
:
new
FileManager
(
"/tmp"
,
"/uploaded_files"
),
}),
{
markdown
:
`# Heading level 1
some content
## Heading level 2
some content as well
# Another heading level 1`
,
}
);
assert
.
deepStrictEqual
(
headings
,
[
{
text
:
"Heading level 1"
,
level
:
1
,
id
:
"heading-level-1"
},
{
text
:
"Heading level 2"
,
level
:
2
,
id
:
"heading-level-2"
},
{
text
:
"Another heading level 1"
,
level
:
1
,
id
:
"another-heading-level-1"
,
},
]);
});
it
(
"allows for nbsp in headings"
,
async
()
=>
{
const
jdd_context
=
simplestContext
();
const
headings
=
new
Markdown
().
getHeadings
(
jdd_context
,
{
markdown
:
`# Cała prawda o fokach w Sopocie`
,
});
const
html
=
await
jdd_context
.
render_markdown
(
"pl"
,
`# Cała prawda o fokach w Sopocie`
);
assert
.
deepStrictEqual
(
headings
,
[
{
text
:
"Cała prawda o fokach w Sopocie"
,
level
:
1
,
id
:
"cala-prawda-o-fokach-w-sopocie"
,
},
]);
assert
.
deepStrictEqual
(
await
formatWithPrettier
(
html
,
"html"
),
await
formatWithPrettier
(
/* HTML */
`<h1 id="cala-prawda-o-fokach-w-sopocie">
<a class="anchor" href="#cala-prawda-o-fokach-w-sopocie">
<span class="markdown-header-link"></span>
</a>
Cała prawda o fokach w Sopocie
</h1>`
,
"html"
)
);
});
it
(
"doesn't add nbsp to code blocks"
,
async
()
=>
{
const
jdd_context
=
simplestContext
();
const
html
=
await
jdd_context
.
render_markdown
(
"pl"
,
"```\nconsole.log('Cała prawda o fokach w Gdańsku')\n```"
);
assert
.
deepStrictEqual
(
await
formatWithPrettier
(
html
,
"html"
),
await
formatWithPrettier
(
/* HTML */
`<pre><code>console.log('Cała prawda o fokach w Gdańsku')
</code></pre>`
,
"html"
)
);
});
});
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Tue, Jul 8, 08:34 (7 h, 57 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
807726
Default Alt Text
markdown.test.ts (3 KB)
Attached To
Mode
rJDD jdd
Attached
Detach File
Event Timeline
Log In to Comment