import { describe, expect, it } from "vitest"; import { diffLines } from "../src/diff.ts"; import { html, raw } from "../src/html.ts"; import { renderMarkdown } from "../src/markdown.ts"; const md = (s: string) => renderMarkdown(s, { noteHref: (n) => `/go?name=${encodeURIComponent(n)}`, imageSrc: (f) => `/attachments/${f}` }); describe("diff", () => { it("marks added and removed lines and folds the rest", () => { const before = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"].join("\n"); const after = ["a", "b", "c", "d", "e", "F", "g", "h", "i", "j"].join("\n"); const d = diffLines(before, after, 1); expect(d).toEqual([ { kind: "skip", count: 4 }, { kind: "same", text: "e" }, { kind: "remove", text: "f" }, { kind: "add", text: "F" }, { kind: "same", text: "g" }, { kind: "skip", count: 3 }, ]); }); it("shows a new note as all added", () => { expect(diffLines("", "x\ny")).toEqual([ { kind: "add", text: "x" }, { kind: "add", text: "y" }, ]); }); }); describe("html", () => { it("escapes values but not nested html", () => { expect(html`

${""}${html`${"&"}`}${raw("


")}

`.toString()).toBe("

<b>&


"); }); }); describe("draft previews", () => { it("never lets a draft run script", () => { const out = md('\n\n[x](javascript:alert(1)) '); expect(out).not.toMatch(/ { const out = md("See [[Mistborn|the book]] and ![[cover.png]]."); expect(out).toContain('"); expect(out).toContain('