import { describe, expect, it } from "vitest"; import { htmlToMarkdown, renderNoteHtml, stripNote } from "./markdown"; // The sanitizer pipeline is the notes feature's XSS defense: markdown-it // with html disabled, then DOMPurify with a restrictive allow-list. These // tests pin the security-relevant behavior — loosening any of them should // require a deliberate decision, never an accident. describe("renderNoteHtml", () => { it("renders basic markdown to html", () => { const out = renderNoteHtml("**bold** and _ital_"); expect(out).toContain("bold"); expect(out).toContain("ital"); }); it("returns empty string for empty source", () => { expect(renderNoteHtml("")).toBe(""); }); it("strips raw script tags (parser-level html disabled)", () => { const out = renderNoteHtml("hello"); expect(out).not.toContain("safe")).toBe("safe"); }); it("returns empty string for empty source", () => { expect(stripNote("")).toBe(""); }); }); describe("htmlToMarkdown", () => { it("converts emphasis", () => { expect(htmlToMarkdown("b")).toBe("**b**"); }); it("converts atx headings", () => { expect(htmlToMarkdown("
a
b
| A | B |
|---|---|
| 1 | 2 |
| x | y |