1+ import assert from 'node:assert' ;
2+ import { describe , it } from 'node:test' ;
3+ import { toHtml , toHtmlWithOptions , toHtmlSync , toHtmlWithOptionsSync } from '../lib/index.mjs' ;
4+
5+ describe ( 'markdown-rs WASM' , ( ) => {
6+ describe ( 'Basic functionality' , ( ) => {
7+ it ( 'converts heading to HTML' , async ( ) => {
8+ const result = await toHtml ( '# Hello World' ) ;
9+ assert . strictEqual ( result , '<h1>Hello World</h1>' ) ;
10+ } ) ;
11+
12+ it ( 'converts paragraph to HTML' , async ( ) => {
13+ const result = await toHtml ( 'This is a paragraph.' ) ;
14+ assert . strictEqual ( result , '<p>This is a paragraph.</p>' ) ;
15+ } ) ;
16+
17+ it ( 'converts emphasis to HTML' , async ( ) => {
18+ const result = await toHtml ( '*italic* and **bold**' ) ;
19+ assert . strictEqual ( result , '<p><em>italic</em> and <strong>bold</strong></p>' ) ;
20+ } ) ;
21+
22+ it ( 'converts links to HTML' , async ( ) => {
23+ const result = await toHtml ( '[GitHub](https://github.com)' ) ;
24+ assert . strictEqual ( result , '<p><a href="https://github.com">GitHub</a></p>' ) ;
25+ } ) ;
26+
27+ it ( 'converts code blocks to HTML' , async ( ) => {
28+ const result = await toHtml ( '```js\nconst x = 1;\n```' ) ;
29+ assert ( result . includes ( '<pre>' ) ) ;
30+ assert ( result . includes ( '<code' ) ) ;
31+ assert ( result . includes ( 'const x = 1;' ) ) ;
32+ } ) ;
33+ } ) ;
34+
35+ describe ( 'GFM options' , ( ) => {
36+ it ( 'enables strikethrough with GFM' , async ( ) => {
37+ const result = await toHtmlWithOptions ( '~strikethrough~' , { gfm : true } ) ;
38+ assert ( result . includes ( '<del>strikethrough</del>' ) ) ;
39+ } ) ;
40+
41+ it ( 'enables tables with GFM' , async ( ) => {
42+ const markdown = '| a | b |\n|---|---|\n| c | d |' ;
43+ const result = await toHtmlWithOptions ( markdown , { gfm : true } ) ;
44+ assert ( result . includes ( '<table>' ) ) ;
45+ assert ( result . includes ( '<td>c</td>' ) ) ;
46+ } ) ;
47+
48+ it ( 'enables autolinks with GFM' , async ( ) => {
49+ const result = await toHtmlWithOptions ( 'https://example.com' , { gfm : true } ) ;
50+ assert ( result . includes ( '<a href="https://example.com">' ) ) ;
51+ } ) ;
52+ } ) ;
53+
54+ describe ( 'MDX options' , ( ) => {
55+ it ( 'handles JSX with MDX enabled' , async ( ) => {
56+ const result = await toHtmlWithOptions ( '# Hello <Component />' , { mdx : true } ) ;
57+ assert ( result . includes ( '<h1>' ) ) ;
58+ } ) ;
59+ } ) ;
60+
61+ describe ( 'Security options' , ( ) => {
62+ it ( 'blocks dangerous HTML by default' , async ( ) => {
63+ const html = '<script>alert("test")</script>' ;
64+ const result = await toHtmlWithOptions ( html , { } ) ;
65+ assert ( ! result . includes ( '<script>' ) ) ;
66+ } ) ;
67+
68+ it ( 'allows dangerous HTML when enabled' , async ( ) => {
69+ const html = '<script>alert("test")</script>' ;
70+ const result = await toHtmlWithOptions ( html , { allowDangerousHtml : true } ) ;
71+ assert ( result . includes ( '<script>' ) ) ;
72+ } ) ;
73+ } ) ;
74+
75+ describe ( 'Sync functions' , ( ) => {
76+ it ( 'sync functions work after initialization' , async ( ) => {
77+ // First initialize with async call
78+ await toHtml ( '# Init' ) ;
79+
80+ // Now sync should work
81+ const result = toHtmlSync ( '# Hello Sync' ) ;
82+ assert . strictEqual ( result , '<h1>Hello Sync</h1>' ) ;
83+ } ) ;
84+
85+ it ( 'sync with options works' , async ( ) => {
86+ await toHtml ( '# Init' ) ;
87+ const result = toHtmlWithOptionsSync ( '~strike~' , { gfm : true } ) ;
88+ assert ( result . includes ( '<del>strike</del>' ) ) ;
89+ } ) ;
90+ } ) ;
91+
92+ describe ( 'Edge cases' , ( ) => {
93+ it ( 'handles empty input' , async ( ) => {
94+ const result = await toHtml ( '' ) ;
95+ assert . strictEqual ( result , '' ) ;
96+ } ) ;
97+
98+ it ( 'handles complex markdown' , async ( ) => {
99+ const markdown = `
100+ # Title
101+
102+ Paragraph with **bold** and *italic*.
103+
104+ - List item 1
105+ - List item 2
106+
107+ \`\`\`js
108+ console.log('code');
109+ \`\`\`
110+
111+ > Blockquote
112+ ` ;
113+ const result = await toHtml ( markdown ) ;
114+ assert ( result . includes ( '<h1>Title</h1>' ) ) ;
115+ assert ( result . includes ( '<ul>' ) ) ;
116+ assert ( result . includes ( '<blockquote>' ) ) ;
117+ } ) ;
118+ } ) ;
119+ } ) ;
0 commit comments