Skip to content

Commit 4e5a0dd

Browse files
fix: 修复代码不能在终端高亮的问题 (#126)
* fix: 修复代码不能在终端高亮的问题 highlight.js v11 result = hljs().highlight(); 已经不存在result.emitter,使用result._emitter替代 * chore: update
2 parents f49c7d7 + c16fc62 commit 4e5a0dd

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

packages/color-diff-napi/src/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -528,19 +528,20 @@ function highlightLine(
528528
// hljs throws on unknown language despite ignoreIllegals
529529
return [[defaultStyle(theme), code]]
530530
}
531-
if (!hasRootNode(result.emitter)) {
531+
const emitter = result._emitter || {};
532+
if (!hasRootNode(emitter)) {
532533
if (!loggedEmitterShapeError) {
533534
loggedEmitterShapeError = true
534535
logError(
535536
new Error(
536-
`color-diff: hljs emitter shape mismatch (keys: ${Object.keys(result.emitter).join(',')}). Syntax highlighting disabled.`,
537+
`color-diff: hljs emitter shape mismatch (keys: ${Object.keys(emitter).join(',')}). Syntax highlighting disabled.`,
537538
),
538539
)
539540
}
540541
return [[defaultStyle(theme), code]]
541542
}
542543
const blocks: Block[] = []
543-
flattenHljs(result.emitter.rootNode, theme, undefined, blocks)
544+
flattenHljs(emitter.rootNode, theme, undefined, blocks)
544545
return blocks
545546
}
546547

0 commit comments

Comments
 (0)