From 8c9a610f0dc1676de7221c8aadfd50aebd0eafad Mon Sep 17 00:00:00 2001 From: claude Date: Mon, 8 Jun 2026 22:02:14 +0000 Subject: [PATCH] tools: add Typst bold/italic parse-tree diagnostic script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Paste typst-bold-italic-diag.js into the browser console while a Typst document containing *bold* and _italic_ is open to determine whether Strong/Emphasis nodes are being produced by the grammar (grammar issue) or whether the nodes exist but bold/italic is not visually rendered (font issue — Source Code Pro only loads Regular 400). Co-Authored-By: Claude Sonnet 4.6 --- typst-bold-italic-diag.js | 52 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 typst-bold-italic-diag.js diff --git a/typst-bold-italic-diag.js b/typst-bold-italic-diag.js new file mode 100644 index 0000000000..cfcc68e34a --- /dev/null +++ b/typst-bold-italic-diag.js @@ -0,0 +1,52 @@ +// Typst bold/italic parse-tree diagnostic +// Open a Typst document that contains *bold* and _italic_ text, +// then paste this whole block into the browser console. + +(function () { + const strong = [...document.querySelectorAll('.tok-strong')] + const emphasis = [...document.querySelectorAll('.tok-emphasis')] + + console.group('=== Typst bold/italic diagnostic ===') + + console.log('tok-strong count :', strong.length) + console.log('tok-emphasis count:', emphasis.length) + + if (strong.length) { + console.log('tok-strong text :', strong.map(s => JSON.stringify(s.textContent))) + } + if (emphasis.length) { + console.log('tok-emphasis text :', emphasis.map(s => JSON.stringify(s.textContent))) + } + + // Interpret results + if (strong.length === 0 && emphasis.length === 0) { + console.warn( + 'RESULT: Grammar is NOT producing Strong/Emphasis nodes.', + 'This is a LALR state-merge bug — needs a grammar fix.' + ) + } else { + const strongText = strong.map(s => s.textContent).join('') + const emphText = emphasis.map(s => s.textContent).join('') + const hasMidStrong = strong.length > 2 // more than just the two * delimiters + const hasMidEmph = emphasis.length > 2 + + if (hasMidStrong || hasMidEmph) { + console.info( + 'RESULT: Grammar IS producing Strong/Emphasis nodes (content inside delimiters is styled).', + 'Bold/italic not visible? Issue is the loaded font — Source Code Pro only has Regular (400).', + 'Fix: switch editor font to DM Mono (which has actual Italic + Medium faces).', + 'Or: load Source Code Pro Bold/Italic font files.' + ) + } else { + console.warn( + 'RESULT: Partial — only the delimiters (* or _) are styled, not the text between them.', + 'StrongText/EmphText nodes are missing. Needs a grammar fix.' + ) + } + + console.log('all strong text joined :', JSON.stringify(strongText)) + console.log('all emphasis text joined:', JSON.stringify(emphText)) + } + + console.groupEnd() +})()