-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
63 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,4 +21,4 @@ export { default as sanitizeHtml } from "https://esm.sh/[email protected]?tar | |
|
||
export { escape as htmlEscape } from "https://esm.sh/[email protected]?pin=v135"; | ||
|
||
export { default as katex } from "https://esm.sh/[email protected]/dist/katex.mjs?pin=v135"; | ||
export { default as katex } from "https://esm.sh/[email protected]?pin=v135"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
import { assertEquals } from "https://deno.land/[email protected]/assert/assert_equals.ts"; | ||
import { | ||
assertEquals, | ||
assertStringIncludes, | ||
} from "https://deno.land/[email protected]/assert/mod.ts"; | ||
import { DOMParser } from "https://deno.land/x/[email protected]/deno-dom-wasm.ts"; | ||
import { render, Renderer } from "../mod.ts"; | ||
|
||
|
@@ -232,3 +235,55 @@ Deno.test( | |
assertEquals(html, expected.trim()); | ||
}, | ||
); | ||
|
||
Deno.test("image title and no alt", () => { | ||
const markdown = `![](image.jpg "best title")`; | ||
const expected = `<p><img src="image.jpg" title="best title" /></p>\n`; | ||
|
||
const html = render(markdown); | ||
assertEquals(html, expected); | ||
}); | ||
|
||
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 html = render(markdown); | ||
assertEquals(html, expected); | ||
}); | ||
|
||
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 html = render(markdown); | ||
assertEquals(html, expected); | ||
}); | ||
|
||
Deno.test("expect console warning from invalid math", () => { | ||
const originalWarn = console.warn; | ||
const warnCalls: string[] = []; | ||
console.warn = (...args) => { | ||
warnCalls.push(args[0].message); | ||
}; | ||
|
||
const html = render("$$ +& $$", { allowMath: true }); | ||
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`; | ||
assertEquals(html, expected); | ||
assertStringIncludes( | ||
warnCalls[0], | ||
"KaTeX parse error: Expected 'EOF', got '&' at position 2: +&̲", | ||
); | ||
|
||
const html2 = render(" $&$", { allowMath: true }); | ||
const expected2 = `<p> $&$</p>\n`; | ||
assertEquals(html2, expected2); | ||
assertStringIncludes( | ||
warnCalls[1], | ||
"KaTeX parse error: Expected 'EOF', got '&' at position 1: &̲", | ||
); | ||
|
||
console.warn = originalWarn; | ||
}); |