MCPcopy Create free account
hub / github.com/Noumena-Network/code / buildMarkdownRenderBlocks

Function buildMarkdownRenderBlocks

src/components/Markdown.tsx:119–168  ·  view source on GitHub ↗
(tokens: Token[], theme: string, highlight: CliHighlight | null)

Source from the content-addressed store, hash-verified

117}
118
119function buildMarkdownRenderBlocks(tokens: Token[], theme: string, highlight: CliHighlight | null): MarkdownRenderBlock[] {
120 const buildStartMs = nowMs();
121 const blocks: MarkdownRenderBlock[] = [];
122 let nonTableContent = "";
123 const flushNonTableContent = function flushNonTableContent() {
124 if (nonTableContent) {
125 blocks.push({
126 type: 'ansi',
127 content: nonTableContent.trim()
128 });
129 nonTableContent = "";
130 }
131 };
132 for (const token of tokens) {
133 if (token.type === "table") {
134 flushNonTableContent();
135 blocks.push({
136 type: 'table',
137 token: token as Tokens.Table
138 });
139 } else if (token.type === "code") {
140 flushNonTableContent();
141 let cachedFallbackAnsi: string | null = null;
142 blocks.push({
143 type: 'code',
144 code: token.text,
145 language: token.lang ?? null,
146 getFallbackAnsi: () => {
147 if (cachedFallbackAnsi !== null) {
148 return cachedFallbackAnsi;
149 }
150 const codeFenceFormatStartMs = nowMs();
151 cachedFallbackAnsi = formatToken(token, theme, 0, null, null, highlight);
152 recordMarkdownCodeFenceFormat({
153 codeLength: token.text.length,
154 language: token.lang ?? null,
155 durationMs: nowMs() - codeFenceFormatStartMs
156 });
157 return cachedFallbackAnsi;
158 }
159 });
160 } else {
161 nonTableContent = nonTableContent + formatToken(token, theme, 0, null, null, highlight);
162 nonTableContent;
163 }
164 }
165 flushNonTableContent();
166 recordMarkdownRenderBuild(nowMs() - buildStartMs);
167 return blocks;
168}
169
170export function getCachedMarkdownRenderBlocks(content: string, theme: string, highlight: CliHighlight | null): MarkdownRenderBlock[] {
171 configureMarked();

Callers 1

Calls 5

flushNonTableContentFunction · 0.85
formatTokenFunction · 0.85
nowMsFunction · 0.70

Tested by

no test coverage detected