MCPcopy Create free account
hub / github.com/IIIIQIIII/claude-code / highlightLine

Function highlightLine

src/native-ts/color-diff/index.ts:504–540  ·  view source on GitHub ↗
(
  state: { lang: string | null; stack: unknown },
  line: string,
  theme: Theme,
)

Source from the content-addressed store, hash-verified

502let loggedEmitterShapeError = false
503
504function highlightLine(
505 state: { lang: string | null; stack: unknown },
506 line: string,
507 theme: Theme,
508): Block[] {
509 // syntect-parity: feed a trailing \n so line comments terminate, then strip
510 const code = line + '\n'
511 if (!state.lang) {
512 return [[defaultStyle(theme), code]]
513 }
514 let result
515 try {
516 result = hljs().highlight(code, {
517 language: state.lang,
518 ignoreIllegals: true,
519 })
520 } catch {
521 // hljs throws on unknown language despite ignoreIllegals
522 return [[defaultStyle(theme), code]]
523 }
524 // highlight.js ≥11 renamed `emitter` to `_emitter` (private).
525 const emitter = (result as any).emitter ?? (result as any)._emitter
526 if (!hasRootNode(emitter)) {
527 if (!loggedEmitterShapeError) {
528 loggedEmitterShapeError = true
529 logError(
530 new Error(
531 `color-diff: hljs emitter shape mismatch (keys: ${Object.keys(emitter ?? {}).join(',')}). Syntax highlighting disabled.`,
532 ),
533 )
534 }
535 return [[defaultStyle(theme), code]]
536 }
537 const blocks: Block[] = []
538 flattenHljs(emitter.rootNode, theme, undefined, blocks)
539 return blocks
540}
541
542// ---------------------------------------------------------------------------
543// Word diff

Callers 2

renderMethod · 0.85
renderMethod · 0.85

Calls 6

hljsFunction · 0.85
hasRootNodeFunction · 0.85
flattenHljsFunction · 0.85
keysMethod · 0.80
defaultStyleFunction · 0.70
logErrorFunction · 0.50

Tested by

no test coverage detected