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); }); });