Files
bip-kit/test/inline.test.js
T
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

95 lines
3.0 KiB
JavaScript

import { test } from "node:test";
import assert from "node:assert/strict";
import { parseInline, inlineToText } from "../dist/index.js";
test("plain text is a single text span", () => {
assert.deepEqual(parseInline("just words"), [{ t: "text", text: "just words" }]);
});
test("**strong** and *em* and _em_ parse to nested spans", () => {
assert.deepEqual(parseInline("a **b** c"), [
{ t: "text", text: "a " },
{ t: "strong", children: [{ t: "text", text: "b" }] },
{ t: "text", text: " c" },
]);
assert.deepEqual(parseInline("*x*"), [{ t: "em", children: [{ t: "text", text: "x" }] }]);
assert.deepEqual(parseInline("_x_"), [{ t: "em", children: [{ t: "text", text: "x" }] }]);
});
test("em nests inside strong", () => {
assert.deepEqual(parseInline("**a *b* c**"), [
{
t: "strong",
children: [
{ t: "text", text: "a " },
{ t: "em", children: [{ t: "text", text: "b" }] },
{ t: "text", text: " c" },
],
},
]);
});
test("inline code containing ** stays raw", () => {
assert.deepEqual(parseInline("run `a ** b` now"), [
{ t: "text", text: "run " },
{ t: "code", text: "a ** b" },
{ t: "text", text: " now" },
]);
});
test("code inside strong keeps its literal content", () => {
assert.deepEqual(parseInline("**use `x`**"), [
{
t: "strong",
children: [
{ t: "text", text: "use " },
{ t: "code", text: "x" },
],
},
]);
});
test("links carry href and parsed children", () => {
assert.deepEqual(parseInline("see [the **docs**](https://example.com/a)"), [
{ t: "text", text: "see " },
{
t: "link",
href: "https://example.com/a",
children: [
{ t: "text", text: "the " },
{ t: "strong", children: [{ t: "text", text: "docs" }] },
],
},
]);
});
test("footnote references parse as footnoteRef, not link", () => {
assert.deepEqual(parseInline("fact[^1] more"), [
{ t: "text", text: "fact" },
{ t: "footnoteRef", id: "1" },
{ t: "text", text: " more" },
]);
});
test("unterminated markers stay literal text", () => {
assert.deepEqual(parseInline("a ** b"), [{ t: "text", text: "a ** b" }]);
assert.deepEqual(parseInline("a `b"), [{ t: "text", text: "a `b" }]);
assert.deepEqual(parseInline("[dangling](nope"), [{ t: "text", text: "[dangling](nope" }]);
});
test("intraword underscores and asterisks are not emphasis", () => {
assert.deepEqual(parseInline("snake_case_name"), [{ t: "text", text: "snake_case_name" }]);
assert.deepEqual(parseInline("2*3*4 = 24"), [{ t: "text", text: "2*3*4 = 24" }]);
});
test("javascript: hrefs survive parsing as data (renderer refuses them)", () => {
// The parser is a faithful reader; the RENDERER is the guard (safeHref).
const [link] = parseInline("[x](javascript:alert1)");
assert.equal(link.t, "link");
assert.equal(link.href, "javascript:alert1");
});
test("inlineToText flattens a span tree back to readable text", () => {
assert.equal(inlineToText(parseInline("a **b** `c` [d](e)[^1]")), "a b c d");
});