mirror of
https://github.com/bitbaum/bip-kit.git
synced 2026-12-04 04:37:03 +01:00
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>
58 lines
2.5 KiB
JavaScript
58 lines
2.5 KiB
JavaScript
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { renderToString } from "react-dom/server";
|
|
import { parseContentBlocks } from "../dist/index.js";
|
|
import { ArticleBody, CodeBlock, MathBlock } from "../dist/react/index.js";
|
|
|
|
/**
|
|
* Degradation paths WITHOUT the optional peers. shiki and katex ARE installed
|
|
* as devDependencies here, so the missing-peer path is forced through the
|
|
* documented test seam: BIPKIT_DISABLE_PEERS (checked per load, not at
|
|
* import time — setting it here affects exactly this process).
|
|
*/
|
|
process.env.BIPKIT_DISABLE_PEERS = "all";
|
|
|
|
test("code degrades to an honest mono <pre>, still with copy button + filename", async () => {
|
|
const blocks = parseContentBlocks("```ts src/x.ts\nconst a: number = 1;\n```");
|
|
const html = renderToString(await ArticleBody({ blocks }));
|
|
assert.doesNotMatch(html, /bp-codeblock-highlighted/);
|
|
assert.doesNotMatch(html, /--shiki/);
|
|
assert.match(html, /<pre class="bp-pre">/);
|
|
assert.match(html, /language-ts/);
|
|
assert.match(html, /class="bp-copy"/);
|
|
assert.match(html, /src\/x\.ts/);
|
|
});
|
|
|
|
test("math degrades to styled source with a data attribute — no crash", async () => {
|
|
const blocks = parseContentBlocks("$$e = mc^2$$");
|
|
const html = renderToString(await ArticleBody({ blocks }));
|
|
assert.doesNotMatch(html, /katex/);
|
|
assert.match(html, /bp-math--fallback/);
|
|
assert.match(html, /data-math="display"/);
|
|
assert.match(html, /e = mc\^2/);
|
|
});
|
|
|
|
test("standalone CodeBlock and MathBlock degrade the same way", async () => {
|
|
const code = renderToString(await CodeBlock({ block: { lang: "js", text: "1" } }));
|
|
assert.match(code, /<pre class="bp-pre">/);
|
|
const math = renderToString(await MathBlock({ block: { tex: "x^2", display: true } }));
|
|
assert.match(math, /bp-math--fallback/);
|
|
});
|
|
|
|
test("mermaid without an override renders its source fallback (peer never loads in SSR)", async () => {
|
|
const blocks = parseContentBlocks("```mermaid\ngraph TD; A-->B\n```");
|
|
const html = renderToString(await ArticleBody({ blocks }));
|
|
assert.match(html, /data-mermaid/);
|
|
assert.match(html, /graph TD/);
|
|
});
|
|
|
|
test("a full document still renders end-to-end with zero peers", async () => {
|
|
const blocks = parseContentBlocks(
|
|
"## T\n\ntext[^1]\n\n```js\n1\n```\n\n$$x$$\n\n> [!NOTE]\n> n\n\n[^1]: def",
|
|
);
|
|
const html = renderToString(await ArticleBody({ blocks }));
|
|
assert.match(html, /bp-article/);
|
|
assert.match(html, /bp-callout--note/);
|
|
assert.match(html, /bp-footnotes/);
|
|
});
|