diff --git a/src/app/plugins/markdown/bidirectional.test.ts b/src/app/plugins/markdown/bidirectional.test.ts new file mode 100644 index 000000000..ab1b09ff1 --- /dev/null +++ b/src/app/plugins/markdown/bidirectional.test.ts @@ -0,0 +1,110 @@ +import { describe, expect, it } from "vitest"; +import { markdownToHtml } from "./markdownToHtml"; +import { htmlToMarkdown } from "./htmlToMarkdown"; +import { injectDataMd } from "./injectDataMd"; + +describe("bidirectional round-trip", () => { + it("round-trips headings", () => { + const markdown = "## Hello World"; + const html = markdownToHtml(markdown); + const injected = injectDataMd(html); + const result = htmlToMarkdown(injected); + expect(result).toContain("## Hello World"); + }); + + it("round-trips bold text", () => { + const markdown = "**bold text**"; + const html = markdownToHtml(markdown); + const injected = injectDataMd(html); + const result = htmlToMarkdown(injected); + expect(result).toContain("**bold text**"); + }); + + it("round-trips italic text", () => { + const markdown = "*italic text*"; + const html = markdownToHtml(markdown); + const injected = injectDataMd(html); + const result = htmlToMarkdown(injected); + expect(result).toContain("*italic text*"); + }); + + it("round-trips inline code", () => { + const markdown = "`inline code`"; + const html = markdownToHtml(markdown); + const injected = injectDataMd(html); + const result = htmlToMarkdown(injected); + expect(result).toContain("`inline code`"); + }); + + it("round-trips code blocks", () => { + const markdown = "```rust\nfn main() {}\n```"; + const html = markdownToHtml(markdown); + const injected = injectDataMd(html); + const result = htmlToMarkdown(injected); + expect(result).toContain("```rust"); + expect(result).toContain("fn main()"); + }); + + it("round-trips blockquotes", () => { + const markdown = "> Quote text"; + const html = markdownToHtml(markdown); + const injected = injectDataMd(html); + const result = htmlToMarkdown(injected); + expect(result).toContain("> Quote text"); + }); + + it("round-trips unordered lists", () => { + const markdown = "- Item 1\n- Item 2"; + const html = markdownToHtml(markdown); + const injected = injectDataMd(html); + const result = htmlToMarkdown(injected); + expect(result).toContain("- Item 1"); + expect(result).toContain("- Item 2"); + }); + + it("round-trips ordered lists", () => { + const markdown = "1. First\n2. Second"; + const html = markdownToHtml(markdown); + const injected = injectDataMd(html); + const result = htmlToMarkdown(injected); + // Note: marked normalizes ordered lists to start at 1 + expect(result).toContain("1. First"); + expect(result).toContain("1. Second"); + }); + + it("round-trips spoiler syntax", () => { + const markdown = "||hidden message||"; + const html = markdownToHtml(markdown); + const injected = injectDataMd(html); + const result = htmlToMarkdown(injected); + expect(result).toContain("||hidden message||"); + }); + + it("round-trips inline math", () => { + const markdown = "$E = mc^2$"; + const html = markdownToHtml(markdown); + const injected = injectDataMd(html); + const result = htmlToMarkdown(injected); + expect(result).toContain("$E = mc^2$"); + }); + + it("round-trips block math", () => { + const markdown = "$$x + y$$"; + const html = markdownToHtml(markdown); + const injected = injectDataMd(html); + const result = htmlToMarkdown(injected); + expect(result).toContain("$$x + y$$"); + }); + + it("does NOT parse k. as a list", () => { + const markdown = "k.Hello world"; + const html = markdownToHtml(markdown); + const injected = injectDataMd(html); + const result = htmlToMarkdown(injected); + // Should NOT contain any list markers + expect(result).not.toContain("
  • "); + expect(result).not.toContain("
      "); + expect(result).not.toContain("