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

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

highlight.js v11 result = hljs().highlight(); 已经不存在result.emitter,使用result._emitter替代

* chore: update
This commit is contained in:
claude-code-best
2026-04-05 15:50:23 +08:00
committed by GitHub

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
}