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 `);
+ expect(built).not.toContain('PRETEXT_BUNDLE');
+ const pages: Record = {
+ '/finalized.html': built,
+ '/old.html': htmlDocument(``),
+ };
+ server = Bun.serve({
+ hostname: '127.0.0.1', port: 0,
+ fetch: (req) => {
+ const html = pages[new URL(req.url).pathname];
+ return html ? new Response(html, { headers: { 'content-type': 'text/html; charset=utf-8' } }) : new Response('not found', { status: 404 });
+ },
+ });
+ browser = await chromium.launch({ headless: true, executablePath: CHROMIUM, timeout: 90_000 });
+ for (const url of [`file://${finalized}`, `http://127.0.0.1:${server.port}/finalized.html`]) {
+ const { errors, raw } = await load(browser, url);
+ expect(errors, url).toEqual([]);
+ expect(raw, `${url}: the page code never finished`).not.toBe('');
+ const result = JSON.parse(raw);
+ expect(result.lineCount, url).toBeGreaterThan(1);
+ expect(result.height, url).toBe(result.lineCount * LINE_HEIGHT);
+ expect(result.walked, url).toBe(result.lineCount);
+ expect(result.lines, url).toBe(result.lineCount);
+ expect(typeof result.firstLine === 'string' && result.firstLine.length > 0, url).toBe(true);
+ }
+ const old = await load(browser, `http://127.0.0.1:${server.port}/old.html`);
+ expect(old.raw).toBe('');
+ expect(old.errors).toContain('ReferenceError: prepareWithSegments is not defined');
+ } finally {
+ await browser?.close();
+ server?.stop(true);
+ fs.rmSync(dir, { recursive: true, force: true });
+ }
+ }, 120_000);
+});
diff --git a/test/design-lint.test.ts b/test/design-lint.test.ts
index cbe35994c..114fc7399 100644
--- a/test/design-lint.test.ts
+++ b/test/design-lint.test.ts
@@ -314,6 +314,8 @@ describe('design-lint: the copy tier', () => {
expect(copy(CLEAN)).toEqual([]);
const pretext = fs.readFileSync(path.join(ROOT, 'design-html', 'vendor', 'pretext.js'), 'utf-8');
expect(copy(CLEAN.replace('