Something went wrong. Try again.
about things notes.zzstoatzz.io
notes
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778import { describe, expect, test } from "bun:test";import { analyzeMarkdown } from "./markdown.mjs";
describe("analyzeMarkdown", () => { test("extracts a linked H1 and falls back to the file path", () => { expect(analyzeMarkdown("# [A linked title](https://example.com)", "fallback.md").title).toBe( "A linked title", ); expect(analyzeMarkdown("## No H1", "path/to/NOTE.MD").title).toBe("path/to/NOTE"); });
test("removes formatting without changing ordinary punctuation", () => { const markdown = [ "# Plain **text**", "", "foo_bar_baz, `inline_code`, and [a link](https://example.com/a_(b)).", "", "> quoted *words*", ].join("\n");
expect(analyzeMarkdown(markdown, "fallback.md").textContent).toBe( [ "Plain text", "", "foo_bar_baz, inline_code, and a link.", "", "quoted words", ].join("\n"), ); });
test("preserves fenced code literally", () => { const markdown = [ "~~~js", "const pipe = left | right;", 'const markdownLooking = "# **still code**";', "~~~", ].join("\n");
expect(analyzeMarkdown(markdown, "code.md").textContent).toBe( ['const pipe = left | right;', 'const markdownLooking = "# **still code**";'].join("\n"), ); });
test("understands GFM tables, task lists, and strikethrough", () => { const markdown = [ "| name | state |", "| --- | --- |", "| parser | ~~fragile~~ solid |", "", "- [x] shipped", ].join("\n"); const text = analyzeMarkdown(markdown, "gfm.md").textContent;
expect(text).toContain("name"); expect(text).toContain("state"); expect(text).toContain("parser"); expect(text).toContain("fragile solid"); expect(text).toContain("shipped"); expect(text).not.toContain("|"); expect(text).not.toContain("[x]"); expect(text).not.toContain("~~"); });
test("drops YAML and TOML front matter with either line ending", () => { for (const markdown of [ "---\ntitle: metadata\n---\n\n# Visible", "---\r\ntitle: metadata\r\n---\r\n\r\n# Visible", "+++\ntitle = 'metadata'\n+++\n\n# Visible", ]) { expect(analyzeMarkdown(markdown, "fallback.md")).toEqual({ title: "Visible", textContent: "Visible", }); } });});