Files
bip-kit/test/helpers.test.js
CatoandClaude Fable 5 a711d1834e feat: v0.2 — inline model, extended block vocabulary, react reference renderer (#18)
One vocabulary + one reference renderer so every fleet site reads long-form
at the same standard, while typography tokens stay per-site.

Parser (root export, still zero-dep; the v0.1 ten block types unchanged):
- Inline model: parseInline → text/strong/em/code/link/footnoteRef spans;
  every text-bearing block keeps `text` and gains additive `spans`.
- New blocks: h4, hr, figure (caption title), gallery (adjacent images
  merge), callout (GitHub > [!NOTE] syntax, nestable), pullquote (>> with
  — cite), mermaid, chart (tiny declarative spec; malformed specs THROW),
  math ($$), footnote defs, stats fence.
- Headings gain slugified, de-duplicated, umlaut-aware ids (kivvi's scheme).
- parseFrontmatter learns YAML arrays (inline + block lists), still dep-free.
- Helpers: extractToc, readingTime, slugify/createSlugger, parseChartSpec.

Renderer (new bip-kit/react subpath + bip-kit/styles.css):
- ArticleBody: async RSC that pre-awaits shiki/katex, then emits a fully
  synchronous tree (renderToString-safe). Server components for every block;
  client islands: Toc (scroll-spy, hidden under 3 headings), ReadingProgress,
  Lightbox, CopyButton. MermaidBlock on its own bip-kit/react/mermaid subpath
  so the mermaid peer never enters uninterested bundles (components override).
- shiki/katex are optional peers loaded via bundler-invisible dynamic import;
  honest degradation without them (mono <pre>, TeX source with data-math).
- styles.css: complete neutral theme — 70ch measure, real vertical rhythm,
  dark mode via vars only (data-theme wins over prefers-color-scheme),
  mobile-first, print-safe; every color/radius/font is a --bp-* custom
  property (theming contract documented in the README).

CI: ci.yml gains workflow_dispatch (re-arm strand — a GITHUB_TOKEN merge
cannot trigger workflows on its own; threadkit#28 pattern).

96 tests: v0.1 compat goldens (original shapes byte-identical after
stripping additive fields), goldens for every new syntax form and edge case,
renderToString smoke tests for every block type with and without the
optional peers (BIPKIT_DISABLE_PEERS seam), consumer-install pack test now
probing ./react, ./react/mermaid and ./styles.css.


Claude-Session: https://claude.ai/code/session_01WqKqMnHQHSmkGFfc5t7Rxn

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-09-05 16:03:53 +00:00

70 lines
2.7 KiB
JavaScript

import { test } from "node:test";
import assert from "node:assert/strict";
import {
parseContentBlocks,
extractToc,
readingTime,
slugify,
createSlugger,
} from "../dist/index.js";
// ── slugify ─────────────────────────────────────────────────────────────────
test("slugify lowercases, hyphenates, and transliterates umlauts", () => {
assert.equal(slugify("Hello World!"), "hello-world");
assert.equal(slugify("Über die Straße"), "ueber-die-strasse");
assert.equal(slugify(" --- "), "");
});
test("createSlugger de-duplicates repeated slugs", () => {
const slug = createSlugger();
assert.equal(slug("Setup"), "setup");
assert.equal(slug("Setup"), "setup-2");
assert.equal(slug("!!!"), "section");
});
// ── extractToc ──────────────────────────────────────────────────────────────
test("extractToc lists h2/h3/h4 with parser-assigned ids and levels", () => {
const blocks = parseContentBlocks("## One\n\ntext\n\n### One point one\n\n#### Deep\n\n## Two");
assert.deepEqual(extractToc(blocks), [
{ id: "one", text: "One", level: 2 },
{ id: "one-point-one", text: "One point one", level: 3 },
{ id: "deep", text: "Deep", level: 4 },
{ id: "two", text: "Two", level: 2 },
]);
});
test("extractToc derives ids for hand-built v0.1 blocks without them", () => {
const toc = extractToc([
{ type: "h2", text: "Alpha" },
{ type: "h2", text: "Alpha" },
{ type: "p", text: "not a heading" },
]);
assert.deepEqual(
toc.map((t) => t.id),
["alpha", "alpha-2"],
);
});
// ── readingTime ─────────────────────────────────────────────────────────────
test("readingTime counts words across block types and floors at one minute", () => {
const short = readingTime(parseContentBlocks("Just a few words."));
assert.equal(short.words, 4);
assert.equal(short.minutes, 1);
});
test("readingTime scales with content at 200 wpm", () => {
const para = Array.from({ length: 100 }, () => "word").join(" ");
const body = Array.from({ length: 6 }, () => para).join("\n\n"); // 600 words
const rt = readingTime(parseContentBlocks(body));
assert.equal(rt.words, 600);
assert.equal(rt.minutes, 3);
});
test("readingTime reaches inside callouts and footnotes", () => {
const rt = readingTime(parseContentBlocks("> [!NOTE]\n> five words are in here"));
assert.equal(rt.words, 5);
});