Skip to content

Commit

Permalink
fix: formating test file
Browse files Browse the repository at this point in the history
  • Loading branch information
TayzenDev committed Nov 12, 2024
1 parent 3317486 commit 17b92b2
Showing 1 changed file with 36 additions and 18 deletions.
54 changes: 36 additions & 18 deletions test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,16 @@ Deno.test(

Deno.test("bug #61 generate a tag", () => {
const markdown = "[link](https://example.com)";
const expected = `<p><a href="https://example.com" rel="noopener noreferrer">link</a></p>\n`;
const expected =
`<p><a href="https://example.com" rel="noopener noreferrer">link</a></p>\n`;
const html = render(markdown);
assertEquals(html, expected);
});

Deno.test("bug #61 generate a tag with disableHtmlSanitization", () => {
const markdown = "[link](https://example.com)";
const expected = `<p><a href="https://example.com" rel="noopener noreferrer">link</a></p>\n`;
const expected =
`<p><a href="https://example.com" rel="noopener noreferrer">link</a></p>\n`;
const html = render(markdown, { disableHtmlSanitization: true });
assertEquals(html, expected);
});
Expand Down Expand Up @@ -112,7 +114,8 @@ Deno.test("alerts rendering", async () => {
Deno.test("Iframe rendering", () => {
const markdown =
'Here is an iframe:\n\n<iframe src="https://example.com" width="300" height="200"></iframe>';
const expected = `<p>Here is an iframe:</p>\n<iframe src="https://example.com" width="300" height="200"></iframe>`;
const expected =
`<p>Here is an iframe:</p>\n<iframe src="https://example.com" width="300" height="200"></iframe>`;

const html = render(markdown, { allowIframes: true });
assertEquals(html, expected);
Expand All @@ -130,15 +133,17 @@ Deno.test("Iframe rendering disabled", () => {
Deno.test("Media URL transformation", () => {
const markdown = "![Image](image.jpg)\n\n![Video](video.mp4)";
const mediaBaseUrl = "https://cdn.example.com/";
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`;
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`;

const html = render(markdown, { mediaBaseUrl: mediaBaseUrl });
assertEquals(html, expected);
});

Deno.test("Media URL transformation without base URL", () => {
const markdown = "![Image](image.jpg)\n\n![Video](video.mp4)";
const expectedWithoutTransformation = `<p><img src="image.jpg" alt="Image" /></p>\n<p><img src="video.mp4" alt="Video" /></p>\n`;
const expectedWithoutTransformation =
`<p><img src="image.jpg" alt="Image" /></p>\n<p><img src="video.mp4" alt="Video" /></p>\n`;

const html = render(markdown);
assertEquals(html, expectedWithoutTransformation);
Expand All @@ -163,15 +168,17 @@ Deno.test("Media URL transformation with invalid URL", () => {

Deno.test("Inline rendering", () => {
const markdown = "My [Deno](https://deno.land) Blog";
const expected = `My <a href="https://deno.land" rel="noopener noreferrer">Deno</a> Blog`;
const expected =
`My <a href="https://deno.land" rel="noopener noreferrer">Deno</a> Blog`;

const html = render(markdown, { inline: true });
assertEquals(html, expected);
});

Deno.test("Inline rendering false", () => {
const markdown = "My [Deno](https://deno.land) Blog";
const expected = `<p>My <a href="https://deno.land" rel="noopener noreferrer">Deno</a> Blog</p>\n`;
const expected =
`<p>My <a href="https://deno.land" rel="noopener noreferrer">Deno</a> Blog</p>\n`;

const html = render(markdown, { inline: false });
assertEquals(html, expected);
Expand All @@ -180,15 +187,17 @@ Deno.test("Inline rendering false", () => {
Deno.test("Link URL resolution with base URL", () => {
const markdown = "[Test Link](/path/to/resource)";
const baseUrl = "https://example.com/";
const expected = `<p><a href="https://example.com/path/to/resource" rel="noopener noreferrer">Test Link</a></p>\n`;
const expected =
`<p><a href="https://example.com/path/to/resource" rel="noopener noreferrer">Test Link</a></p>\n`;

const html = render(markdown, { baseUrl: baseUrl });
assertEquals(html, expected);
});

Deno.test("Link URL resolution without base URL", () => {
const markdown = "[Test Link](/path/to/resource)";
const expected = `<p><a href="/path/to/resource" rel="noopener noreferrer">Test Link</a></p>\n`;
const expected =
`<p><a href="/path/to/resource" rel="noopener noreferrer">Test Link</a></p>\n`;

const html = render(markdown);
assertEquals(html, expected);
Expand All @@ -197,7 +206,8 @@ Deno.test("Link URL resolution without base URL", () => {
Deno.test("Link URL resolution with invalid URL and base URL", () => {
const markdown = "[Test Link](/path/to/resource)";
const baseUrl = "this is an invalid url";
const expected = `<p><a href="/path/to/resource" rel="noopener noreferrer">Test Link</a></p>\n`;
const expected =
`<p><a href="/path/to/resource" rel="noopener noreferrer">Test Link</a></p>\n`;

const html = render(markdown, { baseUrl: baseUrl });
assertEquals(html, expected);
Expand Down Expand Up @@ -242,15 +252,17 @@ Deno.test("image title and no alt", () => {

Deno.test("js language", () => {
const markdown = "```js\nconst foo = 'bar';\n```";
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>`;
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>`;

const html = render(markdown);
assertEquals(html, expected);
});

Deno.test("code fence with a title", () => {
const markdown = "```js title=\"index.ts\"\nconst foo = 'bar';\n```";
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>`;
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>`;

const html = render(markdown);
assertEquals(html, expected);
Expand Down Expand Up @@ -292,7 +304,8 @@ Deno.test("code containing mermaid", () => {

Deno.test("link with title", () => {
const markdown = `[link](https://example.com "asdf")`;
const expected = `<p><a href="https://example.com" title="asdf" rel="noopener noreferrer">link</a></p>\n`;
const expected =
`<p><a href="https://example.com" title="asdf" rel="noopener noreferrer">link</a></p>\n`;
const html = render(markdown);
assertEquals(html, expected);
});
Expand All @@ -305,7 +318,8 @@ Deno.test("expect console warning from invalid math", () => {
};

const html = render("$$ +& $$", { allowMath: true });
const expected = `<p>$$ +&amp; <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`;
const expected =
`<p>$$ +&amp; <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`;
assertEquals(html, expected);
assertStringIncludes(
warnCalls[0],
Expand All @@ -326,7 +340,8 @@ Deno.test("expect console warning from invalid math", () => {
Deno.test("render github-slugger not reused", function () {
for (let i = 0; i < 2; i++) {
const html = render("## Hello");
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`;
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`;
assertEquals(html, expected);
}
});
Expand Down Expand Up @@ -398,7 +413,8 @@ Deno.test("del tag test", () => {

Deno.test("h1 test", () => {
const markdown = "# Hello";
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`;
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`;

const html = render(markdown);
assertEquals(html, result);
Expand Down Expand Up @@ -427,8 +443,10 @@ Deno.test("task list", () => {
});

Deno.test("anchor test raw", () => {
const markdown = `<a class="anchor" aria-hidden="true" tabindex="-1" href="#hello">foo</a>`;
const result = `<p><a class="anchor" aria-hidden="true" tabindex="-1" href="#hello">foo</a></p>\n`;
const markdown =
`<a class="anchor" aria-hidden="true" tabindex="-1" href="#hello">foo</a>`;
const result =
`<p><a class="anchor" aria-hidden="true" tabindex="-1" href="#hello">foo</a></p>\n`;

const html = render(markdown);
assertEquals(html, result);
Expand Down

0 comments on commit 17b92b2

Please sign in to comment.