diff --git a/.gitattributes b/.gitattributes index 0fbf43567..a2d57bd2e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -64,3 +64,7 @@ lib/diagram-render/dist/*.json text eol=lf # Byte-for-byte golden CSS for make-pdf --style plain; CRLF on a Windows # checkout would break the exact comparison. make-pdf/test/fixtures/print-css-plain/*.css text eol=lf + +# /design-html splices the vendored Pretext bundle in at the scaffold's PRETEXT_BUNDLE +# line with awk, which would not match a CRLF line on a Windows checkout. +design-html/vendor/pretext-embed.html text eol=lf diff --git a/changelog.d/fix-design-html-pretext-embed.md b/changelog.d/fix-design-html-pretext-embed.md new file mode 100644 index 000000000..f76833c02 --- /dev/null +++ b/changelog.d/fix-design-html-pretext-embed.md @@ -0,0 +1 @@ +**Pages built by `/design-html` from the bundled Pretext copy now run instead of crashing on their first text-layout call.** The skill told the agent to paste `vendor/pretext.js` into the page's own `` +- If `VENDOR` found: pasted into a module script, its renamed exports leave + `prepare` etc. undefined. Copy `pretext-embed.html` beside it into the page, + splice the bundle in at `PRETEXT_BUNDLE` with + `awk -v f="" '$(1)=="PRETEXT_BUNDLE"{while((getline l0)print l;next}1' finalized.html >t&&mv t finalized.html` + and put page code at `// page code`. +- If `VENDOR_MISSING`: a module script keeps the patterns' imports, from `'https://esm.sh/@chenglou/pretext'`. Add a comment: `` For **framework output**, add to the project's dependencies instead: diff --git a/design-html/SKILL.md.tmpl b/design-html/SKILL.md.tmpl index f38a84a80..63ea3b20c 100644 --- a/design-html/SKILL.md.tmpl +++ b/design-html/SKILL.md.tmpl @@ -242,11 +242,12 @@ _ROOT=$(git rev-parse --show-toplevel 2>/dev/null) [ -n "$_PRETEXT_VENDOR" ] && echo "VENDOR: $_PRETEXT_VENDOR" || echo "VENDOR_MISSING" ``` -- If `VENDOR` found: inline the file in a `` +- If `VENDOR` found: pasted into a module script, its renamed exports leave + `prepare` etc. undefined. Copy `pretext-embed.html` beside it into the page, + splice the bundle in at `PRETEXT_BUNDLE` with + `awk -v f="" '$(1)=="PRETEXT_BUNDLE"{while((getline l0)print l;next}1' finalized.html >t&&mv t finalized.html` + and put page code at `// page code`. +- If `VENDOR_MISSING`: a module script keeps the patterns' imports, from `'https://esm.sh/@chenglou/pretext'`. Add a comment: `` For **framework output**, add to the project's dependencies instead: diff --git a/design-html/sections/pretext-patterns.md b/design-html/sections/pretext-patterns.md index 059379350..4ecf69589 100644 --- a/design-html/sections/pretext-patterns.md +++ b/design-html/sections/pretext-patterns.md @@ -8,7 +8,7 @@ Pretext API usage patterns. Follow them exactly. **Pattern 1: Basic height computation (Simple layout, Card/grid)** ```js import { prepare, layout } from '@chenglou/pretext' -// Vanilla HTML: omit the import; this code follows the inlined bundle in the same + diff --git a/test/design-html-pretext-embed.test.ts b/test/design-html-pretext-embed.test.ts new file mode 100644 index 000000000..cf07fe2b2 --- /dev/null +++ b/test/design-html-pretext-embed.test.ts @@ -0,0 +1,151 @@ +/** + * /design-html's Pretext embedding recipe, run as written. "### Pretext Source + * Embedding" in the generated design-html/SKILL.md tells the agent to copy + * design-html/vendor/pretext-embed.html into the page, splice the vendored + * bundle in at its PRETEXT_BUNDLE line with a documented awk command, and put + * page code at its "// page code" line. The scaffold keeps the bundle in an + * inert '); + expect(SCAFFOLD).toContain("new Blob([document.getElementById('pretext-src').text], { type: 'text/javascript' })"); + expect(SCAFFOLD).toContain('URL.revokeObjectURL(pretextURL)'); + expect(SCAFFOLD.indexOf(PAGE_CODE_LINE)).toBeGreaterThan(SCAFFOLD.indexOf('await import(pretextURL)')); + expect(SCAFFOLD.lastIndexOf('')).toBeGreaterThan(SCAFFOLD.indexOf(PAGE_CODE_LINE)); + for (const name of NAMES) { + expect(BUNDLE, name).toMatch(new RegExp(`\\w+ as ${name}\\b`)); + expect(SCAFFOLD, name).toMatch(new RegExp(`[{,] ${name}[ ,]`)); + } + }); + + test('the vendored bundle can sit in a raw-text