@@ -57,16 +57,14 @@ Deno.test(
57
57
58
58
Deno . test ( "bug #61 generate a tag" , ( ) => {
59
59
const markdown = "[link](https://example.com)" ;
60
- const expected =
61
- `<p><a href="https://example.com" rel="noopener noreferrer">link</a></p>\n` ;
60
+ const expected = `<p><a href="https://example.com" rel="noopener noreferrer">link</a></p>\n` ;
62
61
const html = render ( markdown ) ;
63
62
assertEquals ( html , expected ) ;
64
63
} ) ;
65
64
66
65
Deno . test ( "bug #61 generate a tag with disableHtmlSanitization" , ( ) => {
67
66
const markdown = "[link](https://example.com)" ;
68
- const expected =
69
- `<p><a href="https://example.com" rel="noopener noreferrer">link</a></p>\n` ;
67
+ const expected = `<p><a href="https://example.com" rel="noopener noreferrer">link</a></p>\n` ;
70
68
const html = render ( markdown , { disableHtmlSanitization : true } ) ;
71
69
assertEquals ( html , expected ) ;
72
70
} ) ;
@@ -114,8 +112,7 @@ Deno.test("alerts rendering", async () => {
114
112
Deno . test ( "Iframe rendering" , ( ) => {
115
113
const markdown =
116
114
'Here is an iframe:\n\n<iframe src="https://example.com" width="300" height="200"></iframe>' ;
117
- const expected =
118
- `<p>Here is an iframe:</p>\n<iframe src="https://example.com" width="300" height="200"></iframe>` ;
115
+ const expected = `<p>Here is an iframe:</p>\n<iframe src="https://example.com" width="300" height="200"></iframe>` ;
119
116
120
117
const html = render ( markdown , { allowIframes : true } ) ;
121
118
assertEquals ( html , expected ) ;
@@ -133,17 +130,15 @@ Deno.test("Iframe rendering disabled", () => {
133
130
Deno . test ( "Media URL transformation" , ( ) => {
134
131
const markdown = "\n\n" ;
135
132
const mediaBaseUrl = "https://cdn.example.com/" ;
136
- const expected =
137
- `<p><img src="https://cdn.example.com/image.jpg" alt="Image" /></p>\n<p><img src="https://cdn.example.com/video.mp4" alt="Video" /></p>\n` ;
133
+ const expected = `<p><img src="https://cdn.example.com/image.jpg" alt="Image" /></p>\n<p><img src="https://cdn.example.com/video.mp4" alt="Video" /></p>\n` ;
138
134
139
135
const html = render ( markdown , { mediaBaseUrl : mediaBaseUrl } ) ;
140
136
assertEquals ( html , expected ) ;
141
137
} ) ;
142
138
143
139
Deno . test ( "Media URL transformation without base URL" , ( ) => {
144
140
const markdown = "\n\n" ;
145
- const expectedWithoutTransformation =
146
- `<p><img src="image.jpg" alt="Image" /></p>\n<p><img src="video.mp4" alt="Video" /></p>\n` ;
141
+ const expectedWithoutTransformation = `<p><img src="image.jpg" alt="Image" /></p>\n<p><img src="video.mp4" alt="Video" /></p>\n` ;
147
142
148
143
const html = render ( markdown ) ;
149
144
assertEquals ( html , expectedWithoutTransformation ) ;
@@ -168,17 +163,15 @@ Deno.test("Media URL transformation with invalid URL", () => {
168
163
169
164
Deno . test ( "Inline rendering" , ( ) => {
170
165
const markdown = "My [Deno](https://deno.land) Blog" ;
171
- const expected =
172
- `My <a href="https://deno.land" rel="noopener noreferrer">Deno</a> Blog` ;
166
+ const expected = `My <a href="https://deno.land" rel="noopener noreferrer">Deno</a> Blog` ;
173
167
174
168
const html = render ( markdown , { inline : true } ) ;
175
169
assertEquals ( html , expected ) ;
176
170
} ) ;
177
171
178
172
Deno . test ( "Inline rendering false" , ( ) => {
179
173
const markdown = "My [Deno](https://deno.land) Blog" ;
180
- const expected =
181
- `<p>My <a href="https://deno.land" rel="noopener noreferrer">Deno</a> Blog</p>\n` ;
174
+ const expected = `<p>My <a href="https://deno.land" rel="noopener noreferrer">Deno</a> Blog</p>\n` ;
182
175
183
176
const html = render ( markdown , { inline : false } ) ;
184
177
assertEquals ( html , expected ) ;
@@ -187,17 +180,15 @@ Deno.test("Inline rendering false", () => {
187
180
Deno . test ( "Link URL resolution with base URL" , ( ) => {
188
181
const markdown = "[Test Link](/path/to/resource)" ;
189
182
const baseUrl = "https://example.com/" ;
190
- const expected =
191
- `<p><a href="https://example.com/path/to/resource" rel="noopener noreferrer">Test Link</a></p>\n` ;
183
+ const expected = `<p><a href="https://example.com/path/to/resource" rel="noopener noreferrer">Test Link</a></p>\n` ;
192
184
193
185
const html = render ( markdown , { baseUrl : baseUrl } ) ;
194
186
assertEquals ( html , expected ) ;
195
187
} ) ;
196
188
197
189
Deno . test ( "Link URL resolution without base URL" , ( ) => {
198
190
const markdown = "[Test Link](/path/to/resource)" ;
199
- const expected =
200
- `<p><a href="/path/to/resource" rel="noopener noreferrer">Test Link</a></p>\n` ;
191
+ const expected = `<p><a href="/path/to/resource" rel="noopener noreferrer">Test Link</a></p>\n` ;
201
192
202
193
const html = render ( markdown ) ;
203
194
assertEquals ( html , expected ) ;
@@ -206,8 +197,7 @@ Deno.test("Link URL resolution without base URL", () => {
206
197
Deno . test ( "Link URL resolution with invalid URL and base URL" , ( ) => {
207
198
const markdown = "[Test Link](/path/to/resource)" ;
208
199
const baseUrl = "this is an invalid url" ;
209
- const expected =
210
- `<p><a href="/path/to/resource" rel="noopener noreferrer">Test Link</a></p>\n` ;
200
+ const expected = `<p><a href="/path/to/resource" rel="noopener noreferrer">Test Link</a></p>\n` ;
211
201
212
202
const html = render ( markdown , { baseUrl : baseUrl } ) ;
213
203
assertEquals ( html , expected ) ;
@@ -252,26 +242,57 @@ Deno.test("image title and no alt", () => {
252
242
253
243
Deno . test ( "js language" , ( ) => {
254
244
const markdown = "```js\nconst foo = 'bar';\n```" ;
255
- const expected =
256
- `<div class="highlight highlight-source-js notranslate"><pre><span class="token keyword">const</span> foo <span class="token operator">=</span> <span class="token string">'bar'</span><span class="token punctuation">;</span></pre></div>` ;
245
+ const expected = `<div class="highlight highlight-source-js notranslate"><pre><span class="token keyword">const</span> foo <span class="token operator">=</span> <span class="token string">'bar'</span><span class="token punctuation">;</span></pre></div>` ;
257
246
258
247
const html = render ( markdown ) ;
259
248
assertEquals ( html , expected ) ;
260
249
} ) ;
261
250
262
251
Deno . test ( "code fence with a title" , ( ) => {
263
252
const markdown = "```js title=\"index.ts\"\nconst foo = 'bar';\n```" ;
264
- const expected =
265
- `<div class="highlight highlight-source-js notranslate"><div class="markdown-code-title">index.ts</div><pre><span class="token keyword">const</span> foo <span class="token operator">=</span> <span class="token string">'bar'</span><span class="token punctuation">;</span></pre></div>` ;
253
+ const expected = `<div class="highlight highlight-source-js notranslate"><div class="markdown-code-title">index.ts</div><pre><span class="token keyword">const</span> foo <span class="token operator">=</span> <span class="token string">'bar'</span><span class="token punctuation">;</span></pre></div>` ;
266
254
267
255
const html = render ( markdown ) ;
268
256
assertEquals ( html , expected ) ;
269
257
} ) ;
270
258
259
+ Deno . test ( "code containing mermaid" , ( ) => {
260
+ // test with two code blocks to see if the script and styles are not replicated
261
+ const markdown =
262
+ "```mermaid\ngraph TD;A-->B;A-->C;B-->D;C-->D;\n```\n\n```mermaid\ngraph TD;A-->B;A-->C;B-->D;C-->D;\n```" ;
263
+ const expected = `<script type="module">
264
+ import mermaid from "https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.esm.min.mjs";
265
+ mermaid.initialize({ startOnLoad: false, theme: "neutral" });
266
+ const elements = document.querySelectorAll(".mermaid-container");
267
+ elements.forEach((element) => {
268
+ const code = element.querySelector(".mermaid-code")?.textContent || "";
269
+ if (code) {
270
+ element.innerHTML = \`<div class="mermaid">\${code}</div>\`;
271
+ }
272
+ });
273
+ await mermaid.run();
274
+ </script>
275
+ <style>
276
+ .mermaid-code {
277
+ display: none;
278
+ }
279
+ </style>
280
+ <div class="mermaid-container"><pre><code>graph TD;A-->B;A-->C;B-->D;C-->D;</code></pre><div class="mermaid-code">graph TD;A-->B;A-->C;B-->D;C-->D;</div></div>
281
+ <div class="mermaid-container"><pre><code>graph TD;A-->B;A-->C;B-->D;C-->D;</code></pre><div class="mermaid-code">graph TD;A-->B;A-->C;B-->D;C-->D;</div></div>` ;
282
+
283
+ const html = render ( markdown ) ;
284
+ assertEquals (
285
+ html ,
286
+ expected
287
+ . split ( "\n" )
288
+ . map ( ( line ) => line . trim ( ) )
289
+ . join ( "" ) ,
290
+ ) ;
291
+ } ) ;
292
+
271
293
Deno . test ( "link with title" , ( ) => {
272
294
const markdown = `[link](https://example.com "asdf")` ;
273
- const expected =
274
- `<p><a href="https://example.com" title="asdf" rel="noopener noreferrer">link</a></p>\n` ;
295
+ const expected = `<p><a href="https://example.com" title="asdf" rel="noopener noreferrer">link</a></p>\n` ;
275
296
const html = render ( markdown ) ;
276
297
assertEquals ( html , expected ) ;
277
298
} ) ;
@@ -284,8 +305,7 @@ Deno.test("expect console warning from invalid math", () => {
284
305
} ;
285
306
286
307
const html = render ( "$$ +& $$" , { allowMath : true } ) ;
287
- const expected =
288
- `<p>$$ +& <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow></mrow><annotation encoding="application/x-tex"></annotation></semantics></math></span><span class="katex-html" aria-hidden="true"></span></span></p>\n` ;
308
+ const expected = `<p>$$ +& <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow></mrow><annotation encoding="application/x-tex"></annotation></semantics></math></span><span class="katex-html" aria-hidden="true"></span></span></p>\n` ;
289
309
assertEquals ( html , expected ) ;
290
310
assertStringIncludes (
291
311
warnCalls [ 0 ] ,
@@ -306,8 +326,7 @@ Deno.test("expect console warning from invalid math", () => {
306
326
Deno . test ( "render github-slugger not reused" , function ( ) {
307
327
for ( let i = 0 ; i < 2 ; i ++ ) {
308
328
const html = render ( "## Hello" ) ;
309
- const expected =
310
- `<h2 id="hello"><a class="anchor" aria-hidden="true" tabindex="-1" href="#hello"><svg class="octicon octicon-link" viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a>Hello</h2>\n` ;
329
+ const expected = `<h2 id="hello"><a class="anchor" aria-hidden="true" tabindex="-1" href="#hello"><svg class="octicon octicon-link" viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a>Hello</h2>\n` ;
311
330
assertEquals ( html , expected ) ;
312
331
}
313
332
} ) ;
@@ -379,8 +398,7 @@ Deno.test("del tag test", () => {
379
398
380
399
Deno . test ( "h1 test" , ( ) => {
381
400
const markdown = "# Hello" ;
382
- const result =
383
- `<h1 id="hello"><a class="anchor" aria-hidden="true" tabindex="-1" href="#hello"><svg class="octicon octicon-link" viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a>Hello</h1>\n` ;
401
+ const result = `<h1 id="hello"><a class="anchor" aria-hidden="true" tabindex="-1" href="#hello"><svg class="octicon octicon-link" viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a>Hello</h1>\n` ;
384
402
385
403
const html = render ( markdown ) ;
386
404
assertEquals ( html , result ) ;
@@ -409,10 +427,8 @@ Deno.test("task list", () => {
409
427
} ) ;
410
428
411
429
Deno . test ( "anchor test raw" , ( ) => {
412
- const markdown =
413
- `<a class="anchor" aria-hidden="true" tabindex="-1" href="#hello">foo</a>` ;
414
- const result =
415
- `<p><a class="anchor" aria-hidden="true" tabindex="-1" href="#hello">foo</a></p>\n` ;
430
+ const markdown = `<a class="anchor" aria-hidden="true" tabindex="-1" href="#hello">foo</a>` ;
431
+ const result = `<p><a class="anchor" aria-hidden="true" tabindex="-1" href="#hello">foo</a></p>\n` ;
416
432
417
433
const html = render ( markdown ) ;
418
434
assertEquals ( html , result ) ;
0 commit comments