tools: add Typst bold/italic parse-tree diagnostic script
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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()
|
||||
})()
|
||||
Reference in New Issue
Block a user