import { describe, it, expect } from "vitest"; import markdownExportService from "./md.js"; import { trimIndentation } from "../../../spec/support/utils.js"; describe("Markdown export", () => { it("trims language tag for code blocks", () => { const html = trimIndentation`\

A diff:

Hello
            -world
            +worldy
            
`; const expected = trimIndentation`\ A diff: \`\`\`diff Hello -world +worldy \`\`\``; expect(markdownExportService.toMarkdown(html)).toBe(expected); }); it("rewrites frontend script JavaScript code block", () => { const html = `
Hello
`; const expected = trimIndentation`\ \`\`\`javascript Hello \`\`\``; expect(markdownExportService.toMarkdown(html)).toBe(expected); }); it("rewrites backend script JavaScript code block", () => { const html = `
Hello
`; const expected = trimIndentation`\ \`\`\`javascript Hello \`\`\``; 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 = "helloHello world"; const expected = "~~hello~~Hello ~~world~~"; expect(markdownExportService.toMarkdown(html)).toBe(expected); }); it("exports headings properly", () => { const html = trimIndentation`\

Heading 1

Heading 2

Heading 3

Heading 4

Heading 5
Heading 6
`; const expected = trimIndentation`\ # Heading 1 ## Heading 2 ### Heading 3 #### Heading 4 ##### Heading 5 ###### Heading 6`; expect(markdownExportService.toMarkdown(html)).toBe(expected); }); it("rewrites image URL with spaces", () => { const html = ``; const expected = `![](Hello%20world%20%20.png)`; expect(markdownExportService.toMarkdown(html)).toBe(expected); }); });