import { describe, it, expect } from "vitest"; import { trimIndentation } from "../../../spec/support/utils.js"; import markdownService from "./markdown.js"; describe("markdown", () => { it("rewrites language of known language tags", () => { const conversionTable = { "nginx": "language-text-x-nginx-conf", "diff": "language-text-x-diff", "javascript": "language-application-javascript-env-backend", "css": "language-text-css", "mips": "language-text-x-asm-mips" }; for (const [ input, output ] of Object.entries(conversionTable)) { const result = markdownService.renderToHtml(trimIndentation`\ \`\`\`${input} Hi \`\`\` `, "title"); expect(result).toBe(trimIndentation`\
Hi
`);
}
});
it("rewrites language of unknown language tags", () => {
const result = markdownService.renderToHtml(trimIndentation`\
\`\`\`unknownlanguage
Hi
\`\`\`
`, "title");
expect(result).toBe(trimIndentation`\
Hi
`);
});
it("converts h1 heading", () => {
const result = markdownService.renderToHtml(trimIndentation`\
# Hello
## world
# another one
Hello, world
`, "title");
expect(result).toBe(`Hello, world
`); }); it("parses duplicate title with escape correctly", () => { const result = markdownService.renderToHtml(trimIndentation`\ # What's new Hi there `, "What's new") expect(result).toBe(`Hi there
`); }); it("trims unnecessary whitespace", () => { const input = `\ ## Heading 1 Title \`\`\` code block 1 second line 2 \`\`\` * Hello * world 1. Hello 2. World `; const expected = `\Title
code block 1
second line 2
Before
After
`; expect(markdownService.renderToHtml(input, "Title")).toStrictEqual(expected); }); it("imports images with same outcome as if inserted from CKEditor", () => { const input = ""; const expected = `Before
<application
...
android:testOnly="false">
...
</application>
After
`; expect(markdownService.renderToHtml(input, "Title")).toStrictEqual(expected); }); it("does not escape unneeded characters", () => { const input = `It's important to note that these examples are not natively supported by Trilium out of the box; instead, they demonstrate what you can build within Trilium.`; const expected = `It's important to note that these examples are not natively supported by Trilium out of the box; instead, they demonstrate what you can build within Trilium.
`; expect(markdownService.renderToHtml(input, "Title")).toStrictEqual(expected); }); it("preserves ", () => { const input = `Hello world.`; const expected = /*html*/`Hello world.
`; expect(markdownService.renderToHtml(input, "Title")).toStrictEqual(expected); }); it("converts non-breaking space character to ", () => { const input = `Hello\u00a0world.`; const expected = /*html*/`Hello world.
`; expect(markdownService.renderToHtml(input, "Title")).toStrictEqual(expected); }); it("supports normal links", () => { const input = `[Google](https://www.google.com)`; const expected = /*html*/``; expect(markdownService.renderToHtml(input, "Title")).toStrictEqual(expected); }); it("does not touch relative links", () => { const input = `[Canvas](../../Canvas.html)`; const expected = /*html*/``; expect(markdownService.renderToHtml(input, "Title")).toStrictEqual(expected); }); it("imports back to reference links", () => { const input = `Canvas`; const expected = /*html*/``; expect(markdownService.renderToHtml(input, "Title")).toStrictEqual(expected); }); it("preserves figures and images with sizes", () => { const scenarios = [ /*html*/`The equation is \\(e=mc^{2}\\).
`; expect(markdownService.renderToHtml(input, "Title")).toStrictEqual(expected); }); it("converts display math expressions into Mathtex format", () => { const input = `$$\sqrt{x^{2}+1}$$`; const expected = /*html*/`\\[\sqrt{x^{2}+1}\\]
`; expect(markdownService.renderToHtml(input, "Title")).toStrictEqual(expected); }); it("preserves escaped math expressions", () => { const scenarios = [ "\\$\\$\sqrt{x^{2}+1}\\$\\$", "The equation is \\$e=mc^{2}\\$." ]; for (const scenario of scenarios) { expect(markdownService.renderToHtml(scenario, "Title")).toStrictEqual(`${scenario}
`); } }); it("preserves table with column widths", () => { const html = /*html*/`1 | ![]() | Go to any location on openstreetmap.org and right click to bring up the context menu. Select the “Show address” item. |
2 | ![]() | The address will be visible in the top-left of the screen, in the place of the search bar. Select the coordinates and copy them into the clipboard. |
3 | ![]() | Simply paste the value inside the text box into the #geolocation attribute of a child note of the map and then it should be displayed on the map. |