MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / formatToken

Function formatToken

source code/utils/markdown.ts:51–282  ·  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

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

Callers 4

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

Calls 8

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

Tested by

no test coverage detected