MCPcopy Index your code
hub / github.com/codeaashu/claude-code / formatToken

Function formatToken

src/utils/markdown.ts:49–280  ·  view source on GitHub ↗
(
  token: Token,
  theme: ThemeName,
  listDepth = 0,
  orderedListNumber: number | null = null,
  parent: Token | null = null,
  highlight: CliHighlight | null = null,
)

Source from the content-addressed store, hash-verified

47}
48
49export function formatToken(
50 token: Token,
51 theme: ThemeName,
52 listDepth = 0,
53 orderedListNumber: number | null = null,
54 parent: Token | null = null,
55 highlight: CliHighlight | null = null,
56): string {
57 switch (token.type) {
58 case 'blockquote': {
59 const inner = (token.tokens ?? [])
60 .map(_ => formatToken(_, theme, 0, null, null, highlight))
61 .join('')
62 // Prefix each line with a dim vertical bar. Keep text italic but at
63 // normal brightness — chalk.dim is nearly invisible on dark themes.
64 const bar = chalk.dim(BLOCKQUOTE_BAR)
65 return inner
66 .split(EOL)
67 .map(line =>
68 stripAnsi(line).trim() ? `${bar} ${chalk.italic(line)}` : line,
69 )
70 .join(EOL)
71 }
72 case 'code': {
73 if (!highlight) {
74 return token.text + EOL
75 }
76 let language = 'plaintext'
77 if (token.lang) {
78 if (highlight.supportsLanguage(token.lang)) {
79 language = token.lang
80 } else {
81 logForDebugging(
82 `Language not supported while highlighting code, falling back to plaintext: ${token.lang}`,
83 )
84 }
85 }
86 return highlight.highlight(token.text, { language }) + EOL
87 }
88 case 'codespan': {
89 // inline code
90 return color('permission', theme)(token.text)
91 }
92 case 'em':
93 return chalk.italic(
94 (token.tokens ?? [])
95 .map(_ => formatToken(_, theme, 0, null, parent, highlight))
96 .join(''),
97 )
98 case 'strong':
99 return chalk.bold(
100 (token.tokens ?? [])
101 .map(_ => formatToken(_, theme, 0, null, parent, highlight))
102 .join(''),
103 )
104 case 'heading':
105 switch (token.depth) {
106 case 1: // h1

Callers 4

MarkdownBodyFunction · 0.85
formatCellFunction · 0.85
applyMarkdownFunction · 0.85
getDisplayTextFunction · 0.85

Calls 10

stripAnsiFunction · 0.85
logForDebuggingFunction · 0.85
colorFunction · 0.85
createHyperlinkFunction · 0.85
getListNumberFunction · 0.85
linkifyIssueReferencesFunction · 0.85
getDisplayTextFunction · 0.85
padAlignedFunction · 0.85
maxMethod · 0.80
forEachMethod · 0.80

Tested by

no test coverage detected