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

Function highlightLine

src/native-ts/color-diff/index.ts:504–538  ·  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 if (!hasRootNode(result.emitter)) {
525 if (!loggedEmitterShapeError) {
526 loggedEmitterShapeError = true
527 logError(
528 new Error(
529 `color-diff: hljs emitter shape mismatch (keys: ${Object.keys(result.emitter).join(',')}). Syntax highlighting disabled.`,
530 ),
531 )
532 }
533 return [[defaultStyle(theme), code]]
534 }
535 const blocks: Block[] = []
536 flattenHljs(result.emitter.rootNode, theme, undefined, blocks)
537 return blocks
538}
539
540// ---------------------------------------------------------------------------
541// 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