fix: 修复代码不能在终端高亮的问题

highlight.js v11 result = hljs().highlight(); 已经不存在result.emitter,使用result._emitter替代
This commit is contained in:
sobird
2026-04-05 01:37:14 +08:00
parent f49c7d7e8c
commit d3a607e4e5

View File

@@ -528,19 +528,20 @@ function highlightLine(
// hljs throws on unknown language despite ignoreIllegals
return [[defaultStyle(theme), code]]
}
if (!hasRootNode(result.emitter)) {
const emitter = result._emitter;
if (!hasRootNode(emitter)) {
if (!loggedEmitterShapeError) {
loggedEmitterShapeError = true
logError(
new Error(
`color-diff: hljs emitter shape mismatch (keys: ${Object.keys(result.emitter).join(',')}). Syntax highlighting disabled.`,
`color-diff: hljs emitter shape mismatch (keys: ${Object.keys(emitter).join(',')}). Syntax highlighting disabled.`,
),
)
}
return [[defaultStyle(theme), code]]
}
const blocks: Block[] = []
flattenHljs(result.emitter.rootNode, theme, undefined, blocks)
flattenHljs(emitter.rootNode, theme, undefined, blocks)
return blocks
}