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() +})()