44 lines
1.7 KiB
JavaScript
44 lines
1.7 KiB
JavaScript
/**
|
|
* Typst syntax highlighting diagnostics.
|
|
* Paste into browser dev tools console with a Typst file open.
|
|
*/
|
|
|
|
// ── Part 1: CSS token counts (no view needed) ────────────────────────────
|
|
// If all are 0, the language mode is not being applied at all.
|
|
console.log('=== Token CSS class counts ===')
|
|
;['heading','comment','keyword','string','number',
|
|
'variableName','function','emphasis','strong'].forEach(t => {
|
|
const n = document.querySelectorAll('.tok-' + t).length
|
|
console.log(` .tok-${t}: ${n}`)
|
|
})
|
|
|
|
// ── Part 2: Try to get the parse tree ────────────────────────────────────
|
|
// CodeMirror 6 stores DocView on .cm-content; DocView.view = EditorView
|
|
const content = document.querySelector('.cm-content')
|
|
const view = content?.cmView?.view
|
|
|
|
if (!view?.state) {
|
|
console.warn('Could not find EditorView — parse tree unavailable')
|
|
console.log('Keys on .cm-content:', Object.keys(content ?? {}).join(', '))
|
|
} else {
|
|
console.log('\n=== Parse tree (top 600 chars) ===')
|
|
console.log(view.state.tree.toString().slice(0, 600))
|
|
|
|
// First heading line
|
|
const doc = view.state.doc
|
|
for (let ln = 1; ln <= Math.min(doc.lines, 25); ln++) {
|
|
const line = doc.line(ln)
|
|
if (line.text.trimStart().startsWith('=')) {
|
|
console.log(`\n=== Nodes on heading line ${ln}: "${line.text}" ===`)
|
|
view.state.tree.iterate({
|
|
from: line.from, to: line.to,
|
|
enter(node) {
|
|
const t = doc.sliceString(node.from, node.to)
|
|
console.log(` ${node.name}: ${JSON.stringify(t.slice(0, 50))}`)
|
|
}
|
|
})
|
|
break
|
|
}
|
|
}
|
|
}
|