From f9e4af73ff01d67ef3a2ef36dd58b9a4f3153e4a Mon Sep 17 00:00:00 2001 From: Stefan Bauer Date: Sun, 15 Nov 2026 14:19:59 +0100 Subject: [PATCH 1/5] fix(markdown): one code-block rule for every markdown A code block in a placed component's content, and an indented code block anywhere, were written by markdown-it's default rules: a plain
 without
tabindex, so one that scrolled sideways failed axe's
scrollable-region-focusable. Every markdown-it instance is now made by
createMarkdown, which writes every fence and indented block as the docs
already wrote fences: highlighted, focusable, with the copy button. A test
fails on an instance made anywhere else.
---
 docs/guide/authoring.md                      |  7 ++--
 packages/dev-server/src/code-blocks.ts       | 27 ++++++++++++
 packages/dev-server/src/markdown.ts          | 30 ++++++-------
 packages/dev-server/src/placed-tags.ts       |  5 ++-
 packages/dev-server/src/storefront/placed.ts |  4 +-
 packages/dev-server/src/storefront/teaser.ts |  5 ++-
 packages/dev-server/test/code-blocks.spec.ts | 28 +++++++++++++
 storefront-bench/e2e/build-browser.spec.ts   | 44 +++++++++++++++++---
 8 files changed, 119 insertions(+), 31 deletions(-)
 create mode 100644 packages/dev-server/src/code-blocks.ts
 create mode 100644 packages/dev-server/test/code-blocks.spec.ts

diff --git a/docs/guide/authoring.md b/docs/guide/authoring.md
index e0bb09e..e61567c 100644
--- a/docs/guide/authoring.md
+++ b/docs/guide/authoring.md
@@ -147,9 +147,10 @@ line or on the first line inside it:
 | ` ```src-data atoms/button~secondary ` | Its data; for a variant, merged with the base |
 | ` ```src-html atoms/button ` | Its rendered HTML |
 
-Any other language is syntax-highlighted. Every code block is focusable (`tabindex="0"`), in the docs and on
-storefront pages alike, so a block that scrolls sideways can be scrolled from the keyboard; style it with
-`overflow-x: auto` rather than wrapping its lines.
+Any other language is syntax-highlighted. Every code block is written the same way wherever its markdown is (a
+component's docs, a storefront page, the content of a component placed on a page), a fence and an indented block
+alike: highlighted, with a copy button, and focusable (`tabindex="0"`), so a block that scrolls sideways can be
+scrolled from the keyboard. Style it with `overflow-x: auto` rather than wrapping its lines.
 
 Link to another component with a `pattern:` link, which becomes an in-app link: `[the button](pattern:atoms/button)`
 or `[secondary](pattern:atoms/button~secondary)`. A link to a component that doesn't exist is marked as
diff --git a/packages/dev-server/src/code-blocks.ts b/packages/dev-server/src/code-blocks.ts
new file mode 100644
index 0000000..5ef5bbe
--- /dev/null
+++ b/packages/dev-server/src/code-blocks.ts
@@ -0,0 +1,27 @@
+// The one code-block rule for every markdown Pattern Dump renders: the workbench's docs, a storefront page's body, and
+// the content of a component placed on a page. Every markdown-it instance is made here (createMarkdown), so each one
+// writes a code block the same way, a fence and an indented block alike: highlighted when its language is one the
+// highlighter knows, plain otherwise, always focusable (tabindex="0", so a block that scrolls sideways is reached by
+// keyboard), with the copy button over it. A caller with fences of its own (markdown.ts: pattern, src-*) replaces the
+// fence rule and falls back to codeBlock for every other fence.
+//
+// guard: test/code-blocks.spec.ts fails on a markdown-it instance made anywhere else.
+
+import MarkdownIt from "markdown-it";
+import { highlight, wrapWithCopyButton } from "@pattern-dump/renderer";
+
+/** A code block: highlighted (or a plain, focusable 
), with the copy button carrying the raw code. */
+export function codeBlock(code: string, lang: string): string {
+  return wrapWithCopyButton(highlight(code, lang), code);
+}
+
+/** The language a fence names: its info string's first word ("bash" of "bash title=x"), or "". */
+export const fenceLanguage = (info: string): string => info.trim().split(/\s+/)[0] ?? "";
+
+/** A markdown-it instance with the code-block rule installed. */
+export function createMarkdown(options: ConstructorParameters[0]): MarkdownIt {
+  const md = new MarkdownIt(options);
+  md.renderer.rules["fence"] = (tokens, idx) => `${codeBlock(tokens[idx]!.content, fenceLanguage(tokens[idx]!.info))}\n`;
+  md.renderer.rules["code_block"] = (tokens, idx) => `${codeBlock(tokens[idx]!.content, "")}\n`;
+  return md;
+}
diff --git a/packages/dev-server/src/markdown.ts b/packages/dev-server/src/markdown.ts
index cff9c5a..976ad02 100644
--- a/packages/dev-server/src/markdown.ts
+++ b/packages/dev-server/src/markdown.ts
@@ -22,9 +22,10 @@
 
 import { readFile } from "node:fs/promises";
 import { basename } from "node:path";
-import MarkdownIt from "markdown-it";
+import type MarkdownIt from "markdown-it";
 import type { DiscoveryMap, ImageLookup } from "@pattern-dump/contracts";
-import { highlight, imageTag, wrapWithCopyButton, deepMerge, readExampleHeight, type ProseSlot } from "@pattern-dump/renderer";
+import { imageTag, deepMerge, readExampleHeight, type ProseSlot } from "@pattern-dump/renderer";
+import { codeBlock, createMarkdown, fenceLanguage } from "./code-blocks.js";
 import { escapeAttr, escapeHtml } from "./http-utils.js";
 import { usePlacedTags, type PlacedBlock } from "./placed-tags.js";
 import { placeBlock, type PlacementDeps } from "./storefront/placed.js";
@@ -86,7 +87,7 @@ const INLINE: DocEmbed = { embed: "inline" };
 
 /** The docs parser: one configuration, with or without placed components. */
 function createDocMarkdown(placing: boolean): MarkdownIt {
-  const md = new MarkdownIt({ html: false, linkify: false });
+  const md = createMarkdown({ html: false, linkify: false });
 
   // Positive allowlist: block javascript:, data:, vbscript:, etc.
   // html: false already escapes raw HTML in source; this covers link/image hrefs.
@@ -100,7 +101,7 @@ function createDocMarkdown(placing: boolean): MarkdownIt {
   // never mutates shared state during render, safe for parallel builds.
   md.renderer.rules["fence"] = (tokens, idx, _opts, env) => {
     const map = (env as { resolvedFences?: Map }).resolvedFences;
-    return map?.get(idx) ?? _mdPlainPre(tokens[idx]?.content ?? "");
+    return map?.get(idx) ?? `${codeBlock(tokens[idx]?.content ?? "", fenceLanguage(tokens[idx]?.info ?? ""))}\n`;
   };
 
   // A storefront page's image, written with its variants (proseImages), else as markdown writes it.
@@ -121,10 +122,6 @@ function createDocMarkdown(placing: boolean): MarkdownIt {
 const _md = createDocMarkdown(false);
 const _mdPlaced = createDocMarkdown(true);
 
-/** Focusable, as every code block is (renderer highlight.ts): a block that scrolls sideways is reached by keyboard. */
-function _mdPlainPre(code: string): string {
-  return `
${escapeHtml(code)}
`; -} /** @@ -374,7 +371,7 @@ async function _resolveFence( if (lang === "src-template" || lang.startsWith("src-template ")) { const spec = lang.startsWith("src-template ") ? lang.slice("src-template ".length).trim() : code.split("\n")[0]?.trim() ?? ""; - if (!spec) { out.set(idx, _mdPlainPre("")); return; } + if (!spec) { out.set(idx, codeBlock("", "")); return; } const { compId } = _parsePatternSpec(spec); // variant ignored — all variants share the base template const entry = discoveryMap.get(compId); if (!entry?.hbsPath) { @@ -383,7 +380,7 @@ async function _resolveFence( } try { const src = await readFile(entry.hbsPath, "utf-8"); - out.set(idx, wrapWithCopyButton(highlight(src, "handlebars"), src)); + out.set(idx, codeBlock(src, "handlebars")); } catch (e) { console.warn(`[dev-server] src-template read error [${spec}]:`, e); out.set(idx, `

[src-template: ${escapeHtml(spec)} — read error]

`); @@ -393,7 +390,7 @@ async function _resolveFence( if (lang === "src-data" || lang.startsWith("src-data ")) { const spec = lang.startsWith("src-data ") ? lang.slice("src-data ".length).trim() : code.split("\n")[0]?.trim() ?? ""; - if (!spec) { out.set(idx, _mdPlainPre("")); return; } + if (!spec) { out.set(idx, codeBlock("", "")); return; } const { compId, variant } = _parsePatternSpec(spec); const lookupId = variant ? `${compId}~${variant}` : compId; try { @@ -410,7 +407,7 @@ async function _resolveFence( const variantData: Record = variantJsonPath ? JSON.parse(await readFile(variantJsonPath, "utf-8")) : {}; const merged = deepMerge(structuredClone(baseData), variantData); const src = JSON.stringify(merged, null, 2); - out.set(idx, wrapWithCopyButton(highlight(src, "json"), src)); + out.set(idx, codeBlock(src, "json")); } else { // Base component: no parent to merge from — show its own data file as-is. const jsonPath = discoveryMap.get(compId)?.jsonPath; @@ -419,7 +416,7 @@ async function _resolveFence( return; } const src = await readFile(jsonPath, "utf-8"); - out.set(idx, wrapWithCopyButton(highlight(src, "json"), src)); + out.set(idx, codeBlock(src, "json")); } } catch (e) { console.warn(`[dev-server] src-data read error [${spec}]:`, e); @@ -430,11 +427,11 @@ async function _resolveFence( if (lang === "src-html" || lang.startsWith("src-html ")) { const spec = lang.startsWith("src-html ") ? lang.slice("src-html ".length).trim() : code.split("\n")[0]?.trim() ?? ""; - if (!spec) { out.set(idx, _mdPlainPre("")); return; } + if (!spec) { out.set(idx, codeBlock("", "")); return; } const { compId, variant } = _parsePatternSpec(spec); try { const html = await renderComponent(compId, variant); - out.set(idx, wrapWithCopyButton(highlight(html, "html"), html)); + out.set(idx, codeBlock(html, "html")); } catch (e) { if (!_isRendererNotFound(e)) console.warn(`[dev-server] src-html render error [${spec}]:`, e); out.set(idx, `

[src-html: ${escapeHtml(spec)} — render error]

`); @@ -442,6 +439,5 @@ async function _resolveFence( return; } - const highlighted = highlight(code, lang); - out.set(idx, wrapWithCopyButton(highlighted, code)); + out.set(idx, codeBlock(code, lang)); } diff --git a/packages/dev-server/src/placed-tags.ts b/packages/dev-server/src/placed-tags.ts index 5c531cb..95501b5 100644 --- a/packages/dev-server/src/placed-tags.ts +++ b/packages/dev-server/src/placed-tags.ts @@ -18,9 +18,10 @@ // the tag's indent. Attribute values are plain text, never HTML; how content becomes HTML is the checker's // (block markdown, with HTML escaped, only for a `text/markdown` property). -import MarkdownIt from "markdown-it"; +import type MarkdownIt from "markdown-it"; import type StateBlock from "markdown-it/lib/rules_block/state_block.mjs"; import { suggest } from "@pattern-dump/config"; +import { createMarkdown } from "./code-blocks.js"; import type { ObjectSchema, Placed, PlacedEntry, PlacedProblem, Pos } from "./storefront/declared-values.js"; /** One `pd-` tag as written: its name, attributes, child tags and content text, each with a position. */ @@ -131,7 +132,7 @@ export function usePlacedTags(md: MarkdownIt): MarkdownIt { /** Every claimed block of a markdown body, in order (for a caller that needs no rendering). */ export function readPlacedBlocks(body: string, lineOffset = 0): PlacedBlock[] { - const md = usePlacedTags(new MarkdownIt({ html: false, linkify: false })); + const md = usePlacedTags(createMarkdown({ html: false, linkify: false })); return md.parse(body, { pdLineOffset: lineOffset }).filter(t => t.type === "pd_component").map(t => t.meta as PlacedBlock); } diff --git a/packages/dev-server/src/storefront/placed.ts b/packages/dev-server/src/storefront/placed.ts index a0b345e..049491f 100644 --- a/packages/dev-server/src/storefront/placed.ts +++ b/packages/dev-server/src/storefront/placed.ts @@ -13,7 +13,7 @@ import { readFile } from "node:fs/promises"; import { basename } from "node:path"; -import MarkdownIt from "markdown-it"; +import { createMarkdown } from "../code-blocks.js"; import type { DiscoveryMap, Render } from "@pattern-dump/contracts"; import { checkSchemaExtensions, isHelperNameProblem, unescapedOutputs } from "@pattern-dump/renderer"; import type { CompositionRegistry } from "../composition.js"; @@ -22,7 +22,7 @@ import { checkPlaced, type ObjectSchema, type PlacedProblem, type PropertySchema import { includeTree } from "./sample-data.js"; /** Content markdown: block markdown, HTML escaped (html: false), markdown-it's link check. */ -const contentMd = new MarkdownIt({ html: false, linkify: false }); +const contentMd = createMarkdown({ html: false, linkify: false }); export interface PlacementDeps { discoveryMap: DiscoveryMap; diff --git a/packages/dev-server/src/storefront/teaser.ts b/packages/dev-server/src/storefront/teaser.ts index ed6b967..f264b41 100644 --- a/packages/dev-server/src/storefront/teaser.ts +++ b/packages/dev-server/src/storefront/teaser.ts @@ -7,10 +7,11 @@ // of the body's text: an edit is a new key, so a changed first paragraph is never answered from the cache. import { createHash } from "node:crypto"; -import MarkdownIt from "markdown-it"; +import type MarkdownIt from "markdown-it"; +import { createMarkdown } from "../code-blocks.js"; // html on, so a pd- tag is an html token to skip, not text. -const md = new MarkdownIt({ html: true, linkify: false }); +const md = createMarkdown({ html: true, linkify: false }); type Token = ReturnType[number]; diff --git a/packages/dev-server/test/code-blocks.spec.ts b/packages/dev-server/test/code-blocks.spec.ts new file mode 100644 index 0000000..9223a74 --- /dev/null +++ b/packages/dev-server/test/code-blocks.spec.ts @@ -0,0 +1,28 @@ +// Every markdown Pattern Dump renders writes a code block the one way (src/code-blocks.ts): a fence and an indented +// block, in the docs, on a page and in a placed component's content, are focusable and carry the copy button. The +// guard: no markdown-it instance is made outside code-blocks.ts, so no path can miss the rule again. +import { describe, expect, it } from "vitest"; +import { readdirSync, readFileSync } from "node:fs"; +import { join, relative } from "node:path"; +import { fileURLToPath } from "node:url"; +import { createMarkdown } from "../src/code-blocks.js"; + +const src = fileURLToPath(new URL("../src/", import.meta.url)); +const files = (dir: string): string[] => readdirSync(dir, { withFileTypes: true }) + .flatMap(e => e.isDirectory() ? files(join(dir, e.name)) : e.name.endsWith(".ts") ? [join(dir, e.name)] : []); + +describe("the code-block rule", () => { + it("writes a fence and an indented block alike: focusable, with the copy button and the raw code", () => { + const html = createMarkdown({ html: false }).render("```bash\nnpm i \n```\n\nAnd:\n\n npm i \n"); + const blocks = html.match(/
]*>.*?<\/pre><\/div>/gs) ?? []; + expect(blocks).toHaveLength(2); + for (const b of blocks) expect(b).toMatch(/
]*tabindex="0"/);
+    expect(blocks[0]).toContain(`data-raw="npm i \n"`);
+    expect(blocks[1]).toContain(`data-raw="npm i \n"`);
+  });
+
+  it("is every markdown-it instance's: none is made outside code-blocks.ts", () => {
+    const makers = files(src).filter(f => !f.endsWith("code-blocks.ts") && /new MarkdownIt\(|markdownit\(/.test(readFileSync(f, "utf-8")));
+    expect(makers.map(f => relative(src, f))).toEqual([]);
+  });
+});
diff --git a/storefront-bench/e2e/build-browser.spec.ts b/storefront-bench/e2e/build-browser.spec.ts
index 239d7d2..fd47f09 100644
--- a/storefront-bench/e2e/build-browser.spec.ts
+++ b/storefront-bench/e2e/build-browser.spec.ts
@@ -73,7 +73,7 @@ test("a code block wider than its column scrolls, takes keyboard focus, and pass
   const line = `npm install ${Array.from({ length: 12 }, (_, i) => `@acme/package-number-${i}`).join(" ")}`;
   const root = await project("code", {
     "src/styles/layouts/page.scss": ".page pre {\n  overflow-x: auto;\n}\n",
-    "pages/index.md": `---\ntitle: Home\n---\n\nInstall it:\n\n\`\`\`bash\n${line}\n\`\`\`\n\nAnd plain:\n\n\`\`\`\n${line}\n\`\`\`\n`,
+    "pages/index.md": `---\ntitle: Home\n---\n\nInstall it:\n\n\`\`\`bash\n${line}\n\`\`\`\n\nAnd plain:\n\n\`\`\`\n${line}\n\`\`\`\n\nAnd indented:\n\n    ${line}\n`,
   });
   const report = await buildStaticSite(config, root, { outDir: join(root, ".out", "wb"), pdVersion: "0.0.0-test", browser: true, loadPlaywright });
   expect(report.accessibility).toMatchObject({ browser: true, warnings: [] });
@@ -88,19 +88,53 @@ test("a code block wider than its column scrolls, takes keyboard focus, and pass
   const page = await context.newPage();
   await page.goto("http://site.test/");
   const blocks = page.locator("main pre");
-  await expect(blocks).toHaveCount(2);
-  for (let i = 0; i < 2; i++) {
+  await expect(blocks).toHaveCount(3);
+  for (let i = 0; i < 3; i++) {
     const box = await blocks.nth(i).evaluate(el => ({ overflow: getComputedStyle(el).overflowX, scroll: el.scrollWidth, client: el.clientWidth }));
     expect(box.overflow).toBe("auto");
     expect(box.scroll).toBeGreaterThan(box.client);
   }
   // The Tab order, from the top: each block's copy button, then the block itself.
   const reached: string[] = [];
-  for (let i = 0; i < 4; i++) {
+  for (let i = 0; i < 6; i++) {
     await page.keyboard.press("Tab");
     reached.push(await page.evaluate(() => document.activeElement?.tagName ?? ""));
   }
-  expect(reached).toEqual(["BUTTON", "PRE", "BUTTON", "PRE"]);
+  expect(reached).toEqual(["BUTTON", "PRE", "BUTTON", "PRE", "BUTTON", "PRE"]);
+  await context.close();
+});
+
+test("a code block in a placed component's content scrolls, takes keyboard focus, and passes at 390 px", async ({ browser }) => {
+  const line = `npm install ${Array.from({ length: 12 }, (_, i) => `@acme/package-number-${i}`).join(" ")}`;
+  const root = await project("placed-code", {
+    "src/styles/layouts/page.scss": ".page pre {\n  overflow-x: auto;\n}\n",
+    "src/patterns/components/note/note.hbs": `\n`,
+    "src/patterns/components/note/note.schema.json": JSON.stringify({ type: "object", required: ["text"], "x-pd-content": "text",
+      properties: { text: { type: "string", contentMediaType: "text/markdown" } } }),
+    "src/patterns/components/note/note.json": JSON.stringify({ text: "

A note.

" }), + // A fence and an indented code block, both in the placed note's content. + "pages/index.md": `---\ntitle: Home\n---\n\n\nInstall it:\n\n\`\`\`bash\n${line}\n\`\`\`\n\nOr:\n\n ${line}\n\n`, + }); + const report = await buildStaticSite(config, root, { outDir: join(root, ".out", "wb"), pdVersion: "0.0.0-test", browser: true, loadPlaywright }); + expect(report.accessibility).toMatchObject({ browser: true, warnings: [] }); + const site = join(root, ".out", "site"); + const context = await browser.newContext({ viewport: { width: 390, height: 844 } }); + await context.route("http://site.test/**", async route => { + const path = new URL(route.request().url()).pathname; + const file = join(site, path.endsWith("/") ? `${path}index.html` : path); + await (existsSync(file) ? route.fulfill({ path: file }) : route.fulfill({ status: 404, body: "" })); + }); + const page = await context.newPage(); + await page.goto("http://site.test/"); + const blocks = page.locator("aside.note pre"); + await expect(blocks).toHaveCount(2); + for (let i = 0; i < 2; i++) { + const box = await blocks.nth(i).evaluate(el => ({ overflow: getComputedStyle(el).overflowX, scroll: el.scrollWidth, client: el.clientWidth })); + expect(box.overflow).toBe("auto"); + expect(box.scroll).toBeGreaterThan(box.client); + await blocks.nth(i).focus(); + await expect(blocks.nth(i)).toBeFocused(); + } await context.close(); }); From 370ecd2f8a203469afb9aa22b01c14e4bdf63002 Mon Sep 17 00:00:00 2001 From: Stefan Bauer Date: Sun, 15 Nov 2026 14:27:34 +0100 Subject: [PATCH 2/5] feat(storefront): a code block's copy button works on a storefront page On a storefront page the copy button did nothing: only the workbench's shell handled it. The page now carries a small script that shows each button where the browser can write to the clipboard and copies the block's code. The button is written hidden, so with scripting off there is no button to tab to. --- docs/guide/authoring.md | 4 +- packages/dev-server/src/code-blocks.ts | 16 ++++++-- packages/dev-server/src/markdown.ts | 22 +++++------ packages/dev-server/src/storefront/page.ts | 16 +++++++- packages/dev-server/src/storefront/placed.ts | 3 +- .../dev-server/test/storefront-doc.spec.ts | 9 ++++- packages/renderer/src/highlight.ts | 7 ++-- storefront-bench/e2e/build-browser.spec.ts | 11 +++--- storefront-bench/e2e/copy.spec.ts | 37 +++++++++++++++++++ storefront-bench/e2e/playwright.config.ts | 4 +- storefront-bench/pages/guides/setup.md | 6 +++ 11 files changed, 105 insertions(+), 30 deletions(-) create mode 100644 storefront-bench/e2e/copy.spec.ts diff --git a/docs/guide/authoring.md b/docs/guide/authoring.md index e61567c..363b132 100644 --- a/docs/guide/authoring.md +++ b/docs/guide/authoring.md @@ -150,7 +150,9 @@ line or on the first line inside it: Any other language is syntax-highlighted. Every code block is written the same way wherever its markdown is (a component's docs, a storefront page, the content of a component placed on a page), a fence and an indented block alike: highlighted, with a copy button, and focusable (`tabindex="0"`), so a block that scrolls sideways can be -scrolled from the keyboard. Style it with `overflow-x: auto` rather than wrapping its lines. +scrolled from the keyboard. Style it with `overflow-x: auto` rather than wrapping its lines. On a storefront page the +copy button is shown by a small script of the page's own, and only where the browser can copy: with scripting off +there is no button. Link to another component with a `pattern:` link, which becomes an in-app link: `[the button](pattern:atoms/button)` or `[secondary](pattern:atoms/button~secondary)`. A link to a component that doesn't exist is marked as diff --git a/packages/dev-server/src/code-blocks.ts b/packages/dev-server/src/code-blocks.ts index 5ef5bbe..0d5a334 100644 --- a/packages/dev-server/src/code-blocks.ts +++ b/packages/dev-server/src/code-blocks.ts @@ -10,18 +10,26 @@ import MarkdownIt from "markdown-it"; import { highlight, wrapWithCopyButton } from "@pattern-dump/renderer"; +/** Where a code block is written. On a storefront page its copy button starts hidden, and the page's script + * (page.ts copyScript) shows it: without scripting there is no button, so no focus stop that does nothing. The + * workbench's shell has its own handler. */ +export interface CodeBlockPlace { storefront?: boolean } + /** A code block: highlighted (or a plain, focusable
), with the copy button carrying the raw code. */
-export function codeBlock(code: string, lang: string): string {
-  return wrapWithCopyButton(highlight(code, lang), code);
+export function codeBlock(code: string, lang: string, place: CodeBlockPlace = {}): string {
+  return wrapWithCopyButton(highlight(code, lang), code, { hidden: place.storefront === true });
 }
 
 /** The language a fence names: its info string's first word ("bash" of "bash title=x"), or "". */
 export const fenceLanguage = (info: string): string => info.trim().split(/\s+/)[0] ?? "";
 
+/** Where a render's code blocks go: markdown-it's env, `{ pdCodeBlocks: { storefront: true } }`. */
+export const placeOf = (env: unknown): CodeBlockPlace => (env as { pdCodeBlocks?: CodeBlockPlace } | undefined)?.pdCodeBlocks ?? {};
+
 /** A markdown-it instance with the code-block rule installed. */
 export function createMarkdown(options: ConstructorParameters[0]): MarkdownIt {
   const md = new MarkdownIt(options);
-  md.renderer.rules["fence"] = (tokens, idx) => `${codeBlock(tokens[idx]!.content, fenceLanguage(tokens[idx]!.info))}\n`;
-  md.renderer.rules["code_block"] = (tokens, idx) => `${codeBlock(tokens[idx]!.content, "")}\n`;
+  md.renderer.rules["fence"] = (tokens, idx, _o, env) => `${codeBlock(tokens[idx]!.content, fenceLanguage(tokens[idx]!.info), placeOf(env))}\n`;
+  md.renderer.rules["code_block"] = (tokens, idx, _o, env) => `${codeBlock(tokens[idx]!.content, "", placeOf(env))}\n`;
   return md;
 }
diff --git a/packages/dev-server/src/markdown.ts b/packages/dev-server/src/markdown.ts
index 976ad02..6ea9bd8 100644
--- a/packages/dev-server/src/markdown.ts
+++ b/packages/dev-server/src/markdown.ts
@@ -25,7 +25,7 @@ import { basename } from "node:path";
 import type MarkdownIt from "markdown-it";
 import type { DiscoveryMap, ImageLookup } from "@pattern-dump/contracts";
 import { imageTag, deepMerge, readExampleHeight, type ProseSlot } from "@pattern-dump/renderer";
-import { codeBlock, createMarkdown, fenceLanguage } from "./code-blocks.js";
+import { codeBlock, createMarkdown, fenceLanguage, placeOf } from "./code-blocks.js";
 import { escapeAttr, escapeHtml } from "./http-utils.js";
 import { usePlacedTags, type PlacedBlock } from "./placed-tags.js";
 import { placeBlock, type PlacementDeps } from "./storefront/placed.js";
@@ -101,7 +101,7 @@ function createDocMarkdown(placing: boolean): MarkdownIt {
   // never mutates shared state during render, safe for parallel builds.
   md.renderer.rules["fence"] = (tokens, idx, _opts, env) => {
     const map = (env as { resolvedFences?: Map }).resolvedFences;
-    return map?.get(idx) ?? `${codeBlock(tokens[idx]?.content ?? "", fenceLanguage(tokens[idx]?.info ?? ""))}\n`;
+    return map?.get(idx) ?? `${codeBlock(tokens[idx]?.content ?? "", fenceLanguage(tokens[idx]?.info ?? ""), placeOf(env))}\n`;
   };
 
   // A storefront page's image, written with its variants (proseImages), else as markdown writes it.
@@ -230,7 +230,7 @@ export async function renderDoc(
     }
   }
 
-  return md.renderer.render(tokens, md.options, { resolvedFences, resolvedPlaced });
+  return md.renderer.render(tokens, md.options, { resolvedFences, resolvedPlaced, pdCodeBlocks: { storefront: embed.embed === "frame" } });
 }
 
 /** Checks a storefront page's images and resolves the markup of those from the assets (ProseImages). */
@@ -371,7 +371,7 @@ async function _resolveFence(
 
   if (lang === "src-template" || lang.startsWith("src-template ")) {
     const spec = lang.startsWith("src-template ") ? lang.slice("src-template ".length).trim() : code.split("\n")[0]?.trim() ?? "";
-    if (!spec) { out.set(idx, codeBlock("", "")); return; }
+    if (!spec) { out.set(idx, codeBlock("", "", { storefront: embed.embed === "frame" })); return; }
     const { compId } = _parsePatternSpec(spec);  // variant ignored — all variants share the base template
     const entry = discoveryMap.get(compId);
     if (!entry?.hbsPath) {
@@ -380,7 +380,7 @@ async function _resolveFence(
     }
     try {
       const src = await readFile(entry.hbsPath, "utf-8");
-      out.set(idx, codeBlock(src, "handlebars"));
+      out.set(idx, codeBlock(src, "handlebars", { storefront: embed.embed === "frame" }));
     } catch (e) {
       console.warn(`[dev-server] src-template read error [${spec}]:`, e);
       out.set(idx, `

[src-template: ${escapeHtml(spec)} — read error]

`); @@ -390,7 +390,7 @@ async function _resolveFence( if (lang === "src-data" || lang.startsWith("src-data ")) { const spec = lang.startsWith("src-data ") ? lang.slice("src-data ".length).trim() : code.split("\n")[0]?.trim() ?? ""; - if (!spec) { out.set(idx, codeBlock("", "")); return; } + if (!spec) { out.set(idx, codeBlock("", "", { storefront: embed.embed === "frame" })); return; } const { compId, variant } = _parsePatternSpec(spec); const lookupId = variant ? `${compId}~${variant}` : compId; try { @@ -407,7 +407,7 @@ async function _resolveFence( const variantData: Record = variantJsonPath ? JSON.parse(await readFile(variantJsonPath, "utf-8")) : {}; const merged = deepMerge(structuredClone(baseData), variantData); const src = JSON.stringify(merged, null, 2); - out.set(idx, codeBlock(src, "json")); + out.set(idx, codeBlock(src, "json", { storefront: embed.embed === "frame" })); } else { // Base component: no parent to merge from — show its own data file as-is. const jsonPath = discoveryMap.get(compId)?.jsonPath; @@ -416,7 +416,7 @@ async function _resolveFence( return; } const src = await readFile(jsonPath, "utf-8"); - out.set(idx, codeBlock(src, "json")); + out.set(idx, codeBlock(src, "json", { storefront: embed.embed === "frame" })); } } catch (e) { console.warn(`[dev-server] src-data read error [${spec}]:`, e); @@ -427,11 +427,11 @@ async function _resolveFence( if (lang === "src-html" || lang.startsWith("src-html ")) { const spec = lang.startsWith("src-html ") ? lang.slice("src-html ".length).trim() : code.split("\n")[0]?.trim() ?? ""; - if (!spec) { out.set(idx, codeBlock("", "")); return; } + if (!spec) { out.set(idx, codeBlock("", "", { storefront: embed.embed === "frame" })); return; } const { compId, variant } = _parsePatternSpec(spec); try { const html = await renderComponent(compId, variant); - out.set(idx, codeBlock(html, "html")); + out.set(idx, codeBlock(html, "html", { storefront: embed.embed === "frame" })); } catch (e) { if (!_isRendererNotFound(e)) console.warn(`[dev-server] src-html render error [${spec}]:`, e); out.set(idx, `

[src-html: ${escapeHtml(spec)} — render error]

`); @@ -439,5 +439,5 @@ async function _resolveFence( return; } - out.set(idx, codeBlock(code, lang)); + out.set(idx, codeBlock(code, lang, { storefront: embed.embed === "frame" })); } diff --git a/packages/dev-server/src/storefront/page.ts b/packages/dev-server/src/storefront/page.ts index a8e830f..eaa966b 100644 --- a/packages/dev-server/src/storefront/page.ts +++ b/packages/dev-server/src/storefront/page.ts @@ -107,6 +107,20 @@ export function fitterScript(): string { + `})();`; } +/** The copy buttons' script, on a page that has a code block (code-blocks.ts writes each button hidden): it shows a + * button only where the browser can write to the clipboard, and copies the block's code (its data-raw), saying + * "Copied" for a moment. Without scripting, or without a clipboard, there is no button: no focus stop that does + * nothing. The block itself stays focusable. */ +export function copyScript(): string { + return ``; +} + /** * `pd dev` only: reload when this page or the nav changes, or a component or stylesheet does; list a * build problem (a reload that failed, a restart that is needed) in a notice on the page, which the next @@ -595,5 +609,5 @@ export async function assemblePage(route: string, model: PageModel, a: PageAssem // One main landmark and one

(page-basics.ts): errors in pd build, warnings here. notes.push(...checkPageBasics(html).map(p => `warning: ${page!.path}: ${p}`)); } - return { status: isNotFound ? 404 : 200, html: document(head, `${html}\n${fitterScript()}`, a.live, a.lang, a.basePath ?? "/"), problems: [], notes }; + return { status: isNotFound ? 404 : 200, html: document(head, `${html}\n${fitterScript()}${html.includes(`class="copy-btn"`) ? `\n${copyScript()}` : ""}`, a.live, a.lang, a.basePath ?? "/"), problems: [], notes }; } diff --git a/packages/dev-server/src/storefront/placed.ts b/packages/dev-server/src/storefront/placed.ts index 049491f..1e8064a 100644 --- a/packages/dev-server/src/storefront/placed.ts +++ b/packages/dev-server/src/storefront/placed.ts @@ -170,7 +170,8 @@ export async function placeBlock(block: PlacedBlock, deps: PlacementDeps): Promi const checked = await checkPlaced(id, values, `<${block.root.name}>`, { schemaOf: deps.schemaOf, label: kebab, - markdown: text => contentMd.render(text), + // Placed content is a storefront page's: its code blocks' copy buttons start hidden (code-blocks.ts). + markdown: text => contentMd.render(text, { pdCodeBlocks: { storefront: true } }), }); problems.push(...checked.problems, ...await unsafeOutputs(id, block.root.at, deps), ...await sampleDataProblems(id, block.root.at, deps)); if (problems.length) return { problems }; diff --git a/packages/dev-server/test/storefront-doc.spec.ts b/packages/dev-server/test/storefront-doc.spec.ts index c4c3837..c97ee97 100644 --- a/packages/dev-server/test/storefront-doc.spec.ts +++ b/packages/dev-server/test/storefront-doc.spec.ts @@ -185,9 +185,14 @@ describe("renderDoc frame mode — the same safety rules", () => { expect(html).not.toContain(`href="javascript:`); }); - it("renders the other fences exactly as the workbench does", async () => { + it("renders the other fences as the workbench does, but for the copy button, which starts hidden (the page's script shows it)", async () => { const md = "```src-template components/callout\n```\n\n```src-data components/callout~warning\n```\n\n```ts\nconst a = 1;\n```\n"; - expect(await renderDoc(md, renderComponent, map, frame())).toBe(await renderDoc(md, renderComponent, map)); + const page = await renderDoc(md, renderComponent, map, frame()); + const button = `${highlightedHtml}

`; + return `
${highlightedHtml}
`; } // ---- Internal ---- diff --git a/storefront-bench/e2e/build-browser.spec.ts b/storefront-bench/e2e/build-browser.spec.ts index fd47f09..727d21b 100644 --- a/storefront-bench/e2e/build-browser.spec.ts +++ b/storefront-bench/e2e/build-browser.spec.ts @@ -80,13 +80,13 @@ test("a code block wider than its column scrolls, takes keyboard focus, and pass // The built page, served from its files, at the narrow viewport: each block scrolls sideways and is reached by Tab. const site = join(root, ".out", "site"); const context = await browser.newContext({ viewport: { width: 390, height: 844 } }); - await context.route("http://site.test/**", async route => { + await context.route("http://site.localhost/**", async route => { const path = new URL(route.request().url()).pathname; const file = join(site, path.endsWith("/") ? `${path}index.html` : path); await (existsSync(file) ? route.fulfill({ path: file }) : route.fulfill({ status: 404, body: "" })); }); const page = await context.newPage(); - await page.goto("http://site.test/"); + await page.goto("http://site.localhost/"); const blocks = page.locator("main pre"); await expect(blocks).toHaveCount(3); for (let i = 0; i < 3; i++) { @@ -94,7 +94,8 @@ test("a code block wider than its column scrolls, takes keyboard focus, and pass expect(box.overflow).toBe("auto"); expect(box.scroll).toBeGreaterThan(box.client); } - // The Tab order, from the top: each block's copy button, then the block itself. + // The Tab order, from the top: each block's copy button (shown by the page's script, the origin being a secure + // context with a clipboard, as an https site is), then the block itself. const reached: string[] = []; for (let i = 0; i < 6; i++) { await page.keyboard.press("Tab"); @@ -119,13 +120,13 @@ test("a code block in a placed component's content scrolls, takes keyboard focus expect(report.accessibility).toMatchObject({ browser: true, warnings: [] }); const site = join(root, ".out", "site"); const context = await browser.newContext({ viewport: { width: 390, height: 844 } }); - await context.route("http://site.test/**", async route => { + await context.route("http://site.localhost/**", async route => { const path = new URL(route.request().url()).pathname; const file = join(site, path.endsWith("/") ? `${path}index.html` : path); await (existsSync(file) ? route.fulfill({ path: file }) : route.fulfill({ status: 404, body: "" })); }); const page = await context.newPage(); - await page.goto("http://site.test/"); + await page.goto("http://site.localhost/"); const blocks = page.locator("aside.note pre"); await expect(blocks).toHaveCount(2); for (let i = 0; i < 2; i++) { diff --git a/storefront-bench/e2e/copy.spec.ts b/storefront-bench/e2e/copy.spec.ts new file mode 100644 index 0000000..9844a13 --- /dev/null +++ b/storefront-bench/e2e/copy.spec.ts @@ -0,0 +1,37 @@ +// A code block's copy button on a storefront page: the page's own script shows it and copies the block's code, from +// pd dev and from the built site. With scripting off there is no button to reach, so no focus stop that does nothing. +import { expect, test } from "./fixtures.js"; + +const CODE = "npm run dev --workspace storefront-bench\n"; + +test.describe("a code block's copy button", () => { + test.use({ permissions: ["clipboard-read", "clipboard-write"] }); + + test("is shown, is in the Tab order, and copies the block's code", async ({ page }) => { + await page.goto("/guides/setup/"); + const block = page.locator("main .shiki-container").filter({ hasText: "npm run dev" }); + const button = block.locator("button.copy-btn"); + await expect(button).toBeVisible(); + await button.focus(); + await expect(button).toBeFocused(); + await page.keyboard.press("Enter"); + await expect(button).toHaveText("Copied"); + expect(await page.evaluate(() => navigator.clipboard.readText())).toBe(CODE); + await expect(button).toHaveText("Copy"); + }); +}); + +test.describe("with JavaScript off", () => { + test.use({ javaScriptEnabled: false }); + + test("the block has no button, and the block itself still takes focus", async ({ page }) => { + await page.goto("/guides/setup/"); + const block = page.locator("main .shiki-container").filter({ hasText: "npm run dev" }); + await expect(block.locator("button.copy-btn")).toBeHidden(); + // Tab from the block's previous focusable element lands on the block, not on a button. + await block.locator("pre").focus(); + await expect(block.locator("pre")).toBeFocused(); + await page.keyboard.press("Shift+Tab"); + expect(await page.evaluate(() => document.activeElement?.matches("button.copy-btn") ?? false)).toBe(false); + }); +}); diff --git a/storefront-bench/e2e/playwright.config.ts b/storefront-bench/e2e/playwright.config.ts index 4c4efbc..c340762 100644 --- a/storefront-bench/e2e/playwright.config.ts +++ b/storefront-bench/e2e/playwright.config.ts @@ -32,10 +32,10 @@ export default defineConfig({ use: { trace: "on-first-retry", video: "retain-on-failure" }, projects: [ // pd dev, on the storefront host. dom-parity also reads the static root. - { name: "storefront", testMatch: /\b(pages|js-off|workbench-links|hmr|live-handshake|add-page|new-files|workbench|dom-parity|placed|config-reload|derived-page|headings|position|dates|navigations|seo|not-found|redirects|example-height|example-height-check|asset-stamps|image-slots|prose-images|build-browser|collections|collections-reload|base-path|scripts)\.spec\.ts$/, + { name: "storefront", testMatch: /\b(pages|js-off|workbench-links|hmr|live-handshake|add-page|new-files|workbench|dom-parity|placed|config-reload|derived-page|headings|position|dates|navigations|seo|not-found|redirects|example-height|example-height-check|asset-stamps|image-slots|prose-images|build-browser|collections|collections-reload|base-path|scripts|copy)\.spec\.ts$/, use: { ...devices["Desktop Chrome"], baseURL: `http://live.localhost:${DEV_PORT}` } }, // The built storefront root, from a static host. - { name: "storefront-static", testMatch: /\b(pages|js-off|workbench-links|static|placed|headings|position|dates|navigations|seo|not-found|redirects|example-height|example-height-check|asset-stamps|image-slots|prose-images|collections|scripts)\.spec\.ts$/, + { name: "storefront-static", testMatch: /\b(pages|js-off|workbench-links|static|placed|headings|position|dates|navigations|seo|not-found|redirects|example-height|example-height-check|asset-stamps|image-slots|prose-images|collections|scripts|copy)\.spec\.ts$/, use: { ...devices["Desktop Chrome"], baseURL: `http://127.0.0.1:${STATIC_PORT}` } }, ], webServer: [{ diff --git a/storefront-bench/pages/guides/setup.md b/storefront-bench/pages/guides/setup.md index a97fa6c..5ff3514 100644 --- a/storefront-bench/pages/guides/setup.md +++ b/storefront-bench/pages/guides/setup.md @@ -24,3 +24,9 @@ example looks. Every layout fills the main region of the base partial, which has the id `main`. This heading would have the same anchor, so it gets `main-1`. + +To start the bench's own server: + +```bash +npm run dev --workspace storefront-bench +``` From e707125683584c4f7efc161417e8c20e2da4f2d6 Mon Sep 17 00:00:00 2001 From: Stefan Bauer Date: Sun, 15 Nov 2026 14:29:12 +0100 Subject: [PATCH 3/5] feat(workbench): a folder's tab names the folder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A folder route's browser tab reads "Atoms · Acme DS", as a component route's reads "Button · Acme DS", so folder tabs and history entries can be told apart too. Home and an unknown route keep the brand alone. --- apps/dev-ui/e2e/document-title.spec.ts | 10 ++++++---- apps/dev-ui/e2e/static/static-build.spec.ts | 4 ++-- apps/dev-ui/src/app/router.ts | 15 +++++++++------ apps/dev-ui/src/core/title.spec.ts | 3 ++- apps/dev-ui/src/core/title.ts | 10 +++++----- docs/guide/configuration.md | 2 +- 6 files changed, 25 insertions(+), 19 deletions(-) diff --git a/apps/dev-ui/e2e/document-title.spec.ts b/apps/dev-ui/e2e/document-title.spec.ts index 5b6c188..8f2dfca 100644 --- a/apps/dev-ui/e2e/document-title.spec.ts +++ b/apps/dev-ui/e2e/document-title.spec.ts @@ -1,5 +1,5 @@ -// The browser tab names the workbench: shell.brand.title (test-bench sets "Test bench"), with the component in front -// on a component route, so tabs and history entries can be told apart. The served page has the brand before any +// The browser tab names the workbench: shell.brand.title (test-bench sets "Test bench"), with the component or folder +// in front on its route, so tabs and history entries can be told apart. The served page has the brand before any // script runs; the shell keeps the title in step with every navigation, Back included. import { test, expect } from "@playwright/test"; @@ -9,10 +9,12 @@ test("the served page's title is the brand", async ({ request }) => { expect(html).toContain("Test bench"); }); -test("a component route puts the component in front; a folder, and Back to it, the brand alone", async ({ page }) => { +test("a component or folder route puts its title in front, Back restores it, and an unknown route is the brand alone", async ({ page }) => { + await page.goto("/no-such-route"); + await expect(page).toHaveTitle("Test bench"); await page.goto("/atoms"); await expect(page.locator("#category-overview")).toBeVisible(); - await expect(page).toHaveTitle("Test bench"); + await expect(page).toHaveTitle("Atoms · Test bench"); await page.goto("/atoms/button"); await page.waitForSelector("#preview-frame[srcdoc]"); await expect(page).toHaveTitle("Button · Test bench"); diff --git a/apps/dev-ui/e2e/static/static-build.spec.ts b/apps/dev-ui/e2e/static/static-build.spec.ts index ce55eac..f63f6d6 100644 --- a/apps/dev-ui/e2e/static/static-build.spec.ts +++ b/apps/dev-ui/e2e/static/static-build.spec.ts @@ -48,14 +48,14 @@ test.describe("static build — built without the audit (--no-audit)", () => { }); test.describe("static build — the browser tab", () => { - test("names the brand in every shell page, and the component in front on a component route", async ({ page, request }) => { + test("names the brand in every shell page, and the component or folder in front on its route", async ({ page, request }) => { expect(await (await request.get("atoms/button")).text()).toContain("Test bench"); await page.goto("atoms/button"); await page.waitForSelector("#preview-frame[srcdoc]"); await expect(page).toHaveTitle("Button · Test bench"); await page.goto("atoms"); await expect(page.locator("#category-overview")).toBeVisible(); - await expect(page).toHaveTitle("Test bench"); + await expect(page).toHaveTitle("Atoms · Test bench"); }); }); diff --git a/apps/dev-ui/src/app/router.ts b/apps/dev-ui/src/app/router.ts index dd4149f..fe1e392 100644 --- a/apps/dev-ui/src/app/router.ts +++ b/apps/dev-ui/src/app/router.ts @@ -18,7 +18,7 @@ import { documentTitle } from "../core/title.js"; import { navigate, navigateOverview, navigateUnknown, navigateVariants, swapVariant } from "./navigation.js"; -function resolvePathKind(path: string): "component" | "group" | null { +function findTreeNode(path: string): TreeNode | null { function findNode(nodes: TreeNode[]): TreeNode | null { for (const n of nodes) { if (n.path === path) return n; @@ -29,8 +29,11 @@ function resolvePathKind(path: string): "component" | "group" | null { } return null; } - const node = findNode(session.tree.roots); - return node ? node.kind : null; + return findNode(session.tree.roots); +} + +function resolvePathKind(path: string): "component" | "group" | null { + return findTreeNode(path)?.kind ?? null; } // Read the current URL and route to the matching view. All navigation paths — @@ -59,11 +62,11 @@ export async function routeFromCurrentLocation(): Promise { } // Variant is now in the URL hash (#ghost), not ?v= query param. const variant = window.location.hash.slice(1) || undefined; - // The tab names the component on a component route (its gallery too), and only the workbench elsewhere. + // The tab names the component or folder the route shows (a component's gallery too), and only the workbench on + // home and on a route the tree doesn't know. const shown = path.endsWith("/variants") && resolvePathKind(path.slice(0, -"/variants".length)) === "component" ? path.slice(0, -"/variants".length) : path; - document.title = documentTitle(session.brandTitle, - resolvePathKind(shown) === "component" ? session.componentRegistry.get(shown)?.title : undefined); + document.title = documentTitle(session.brandTitle, path ? findTreeNode(shown)?.title : undefined); if (!path) return; if (path.endsWith("/variants")) { diff --git a/apps/dev-ui/src/core/title.spec.ts b/apps/dev-ui/src/core/title.spec.ts index 81b9e1f..21f3bcf 100644 --- a/apps/dev-ui/src/core/title.spec.ts +++ b/apps/dev-ui/src/core/title.spec.ts @@ -7,9 +7,10 @@ describe("the browser tab's title", () => { expect(brandTitle(undefined)).toBe("Pattern Dump"); }); - it("puts the component in front on a component route, and is the brand alone elsewhere", () => { + it("puts the component or folder in front on its route, and is the brand alone elsewhere", () => { expect(documentTitle("Acme DS", "Button")).toBe("Button · Acme DS"); expect(documentTitle(brandTitle(undefined), "Button")).toBe("Button · Pattern Dump"); + expect(documentTitle("Acme DS", "Atoms")).toBe("Atoms · Acme DS"); expect(documentTitle("Acme DS")).toBe("Acme DS"); }); }); diff --git a/apps/dev-ui/src/core/title.ts b/apps/dev-ui/src/core/title.ts index 7735264..308e5eb 100644 --- a/apps/dev-ui/src/core/title.ts +++ b/apps/dev-ui/src/core/title.ts @@ -1,13 +1,13 @@ // The browser tab's title: the workbench's name (shell.brand.title, else "Pattern Dump"; the served page starts with -// it), with the component's title in front on a component route, so tabs and history entries can be told apart. -// Every other route (home, a folder, an unknown path) is the name alone. +// it), with the title of the component or folder in front on its route, so tabs and history entries can be told +// apart. Home and an unknown path are the name alone. /** The name the tab shows without a component: the config's shell.brand.title, else the default. */ export function brandTitle(title: string | undefined): string { return title ?? "Pattern Dump"; } -/** " · " on a component route, else the brand. */ -export function documentTitle(brand: string, component?: string): string { - return component ? `${component} · ${brand}` : brand; +/** " · " on its route, else the brand. */ +export function documentTitle(brand: string, shown?: string): string { + return shown ? `${shown} · ${brand}` : brand; } diff --git a/docs/guide/configuration.md b/docs/guide/configuration.md index 1ec5489..94729ba 100644 --- a/docs/guide/configuration.md +++ b/docs/guide/configuration.md @@ -141,7 +141,7 @@ How the storefront's images are encoded as WebP variants ([Storefront: Images](s | Option | Type | Description | |---|---|---| | `overviews` | boolean | Folder gallery pages. Default `true`; a folder's `index.md` can turn off its own with `overview: false` | -| `shell.brand.title` | string | Title at the top of the Nav Rail, and the browser tab's title (with the component in front on a component route: "Button · My Design System"), in `pd dev` and in a `pd build` snapshot. Default: "Pattern Dump" | +| `shell.brand.title` | string | Title at the top of the Nav Rail, and the browser tab's title (with the component or folder in front on its route: "Button · My Design System", "Atoms · My Design System"), in `pd dev` and in a `pd build` snapshot. Default: "Pattern Dump" | | `shell.brand.logo` | string or `{ light, dark }` | Image shown instead of the title; `{ light, dark }` switches with the colour scheme | | `shell.brand.logoAlt` | string | Alternative text for the logo | | `shell.brand.href` | string | Makes the brand a link | From 0c9782a0f45cf3ffad99c451b6c544a9533e6379 Mon Sep 17 00:00:00 2001 From: Stefan Bauer Date: Sun, 15 Nov 2026 14:40:58 +0100 Subject: [PATCH 4/5] fix: no em dash in what Pattern Dump writes or prints MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Separators in labels and report lines are a middle dot ("Button · ghost", "Diagnostics audit · ", a docs error marker "[pattern: x · no such component]"), clause dashes in messages a colon or a period ("unknown key "x": did you mean ..."), and placeholders words in parentheses ("(no theme)", "(no size)"). The same in pd audit's headline, the terminal and console lines, pd --help, pd init's notes and the files it writes. Tests asserting the strings change with them. --- apps/dev-ui/e2e/theme-picker.spec.ts | 4 ++-- apps/dev-ui/src/app/bootstrap.ts | 2 +- apps/dev-ui/src/app/galleries.ts | 2 +- apps/dev-ui/src/app/hmr.ts | 10 +++++----- apps/dev-ui/src/app/shell.html | 2 +- apps/dev-ui/src/core/protocol.ts | 2 +- apps/dev-ui/src/dock/diagnostics.ts | 2 +- apps/dev-ui/src/rail/theme.ts | 6 +++--- apps/dev-ui/src/stage/viewport.ts | 4 ++-- packages/a11y/src/classifier.ts | 6 +++--- packages/a11y/src/classify-pages.ts | 2 +- .../a11y/src/page-rule-tiers.generated.json | 2 +- packages/a11y/src/rule-tiers.generated.json | 2 +- packages/cli/src/args.ts | 4 ++-- packages/cli/src/init/plan.spec.ts | 6 +++--- packages/cli/src/init/plan.ts | 14 ++++++------- packages/cli/src/init/run.spec.ts | 2 +- packages/cli/src/init/run.ts | 6 +++--- .../cli/templates/base/pattern-dump.config.ts | 2 +- .../templates/base/src/scripts/globals.d.ts | 2 +- .../base/src/styles/base/document.scss | 2 +- packages/cli/templates/base/tsconfig.json | 2 +- .../src/patterns/atoms/button/button.md | 4 ++-- .../molecules/search-field/search-field.md | 2 +- .../src/patterns/pages/example/example.md | 2 +- .../examples/src/scripts/search-field.ts | 2 +- packages/config/src/validate.spec.ts | 18 ++++++++--------- packages/config/src/validate.ts | 12 +++++------ packages/contracts/src/dev-protocol.ts | 2 +- packages/core/src/index.ts | 6 +++--- packages/core/src/load-config.spec.ts | 4 ++-- packages/dev-server/src/audit-format.ts | 10 +++++----- packages/dev-server/src/flattening.ts | 10 +++++----- packages/dev-server/src/frontmatter.ts | 10 +++++----- packages/dev-server/src/index.ts | 2 +- packages/dev-server/src/markdown.ts | 20 +++++++++---------- packages/dev-server/src/packages.ts | 2 +- packages/dev-server/src/placed-tags.ts | 4 ++-- packages/dev-server/src/ports.ts | 2 +- packages/dev-server/src/static-build.ts | 12 +++++------ .../dev-server/src/storefront/collections.ts | 2 +- .../src/storefront/declared-values.ts | 6 +++--- .../src/storefront/frontmatter-contract.ts | 6 +++--- .../dev-server/src/storefront/navigations.ts | 6 +++--- packages/dev-server/src/storefront/pages.ts | 2 +- packages/dev-server/src/surfacing.ts | 6 +++--- packages/dev-server/src/watch.ts | 8 ++++---- .../test/declared-values-placed.spec.ts | 6 +++--- .../dev-server/test/diagnostics-graph.spec.ts | 12 +++++------ packages/dev-server/test/docs.spec.ts | 6 +++--- .../test/frontmatter-strict.spec.ts | 16 +++++++-------- packages/dev-server/test/placed-tags.spec.ts | 4 ++-- .../dev-server/test/startup-addresses.spec.ts | 2 +- .../dev-server/test/storefront-build.spec.ts | 4 ++-- .../test/storefront-collections.spec.ts | 4 ++-- .../dev-server/test/storefront-doc.spec.ts | 8 ++++---- .../test/storefront-frontmatter.spec.ts | 12 +++++------ .../test/storefront-navigations.spec.ts | 6 +++--- .../dev-server/test/storefront-page.spec.ts | 2 +- .../dev-server/test/storefront-pages.spec.ts | 2 +- .../dev-server/test/storefront-placed.spec.ts | 6 +++--- .../dev-server/test/storefront-site.spec.ts | 6 +++--- 62 files changed, 171 insertions(+), 171 deletions(-) diff --git a/apps/dev-ui/e2e/theme-picker.spec.ts b/apps/dev-ui/e2e/theme-picker.spec.ts index 3f53ef7..27b057d 100644 --- a/apps/dev-ui/e2e/theme-picker.spec.ts +++ b/apps/dev-ui/e2e/theme-picker.spec.ts @@ -16,7 +16,7 @@ // but not clickable, so the user-facing affordance is the chip