import { describe, it, expect } from "vitest"; import markdownExportService from "./markdown.js"; import { trimIndentation } from "../../../spec/support/utils.js"; describe("Markdown export", () => { it("exports correct language tag for known languages", () => { const conversionTable = { "language-text-x-nginx-conf": "nginx", "language-text-x-diff": "diff", "language-application-javascript-env-frontend": "javascript", "language-application-javascript-env-backend": "javascript", "language-text-x-asm-mips": "mips" }; for (const [ input, output ] of Object.entries(conversionTable)) { const html = trimIndentation`\
A diff:
Hello
-world
+worldy
`;
const expected = trimIndentation`\
A diff:
\`\`\`${output}
Hello
-world
+worldy
\`\`\``;
expect(markdownExportService.toMarkdown(html)).toBe(expected);
}
});
it("removes auto tag for code blocks", () => {
const html = trimIndentation`\
Hello
-world
+worldy
`;
const expected = trimIndentation`\
\`\`\`
Hello
-world
+worldy
\`\`\``;
expect(markdownExportService.toMarkdown(html)).toBe(expected);
});
it("supports code block with no language tag", () => {
const html = trimIndentation`\
Hello
`;
const expected = trimIndentation`\
\`\`\`
Hello
\`\`\``;
expect(markdownExportService.toMarkdown(html)).toBe(expected);
});
it("exports strikethrough text correctly", () => {
const html = "Before
After
`; const space = " "; // editor config trimming space. const expected = trimIndentation`\ Before > [!NOTE] > This is a note. > [!TIP] > This is a tip. > [!IMPORTANT] > This is a very important information. >${space} > | | | > | --- | --- | > | 1 | 2 | > | 3 | 4 | > [!CAUTION] > This is a caution. > [!WARNING] > ## Title goes here >${space} > This is a warning. After`; expect(markdownExportService.toMarkdown(html)).toBe(expected); }); it("exports code in tables properly", () => { const html = trimIndentation`\Row 1 |
Allows displaying the value of one or more attributes in the calendar like this:
It can also be used with relations, case in which it will display the title of the target note:
|
Row 1 | Allows displaying the value of one or more attributes in the calendar like this:
It can also be used with relations, case in which it will display the title of the target note:
|