MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / nodeToPlainText

Function nodeToPlainText

cli/src/utils/markdown-renderer.tsx:358–462  ·  view source on GitHub ↗
(node: MarkdownNode)

Source from the content-addressed store, hash-verified

356}
357
358const nodeToPlainText = (node: MarkdownNode): string => {
359 switch (node.type) {
360 case 'root':
361 return getChildrenText((node as Root).children as MarkdownNode[])
362
363 case 'paragraph':
364 return getChildrenText((node as Paragraph).children as MarkdownNode[]) + '\n\n'
365
366 case 'text':
367 return (node as Text).value
368
369 case 'strong':
370 return getChildrenText((node as Strong).children as MarkdownNode[])
371
372 case 'emphasis':
373 return getChildrenText((node as Emphasis).children as MarkdownNode[])
374
375 case 'inlineCode':
376 return (node as InlineCode).value
377
378 case 'heading': {
379 const heading = node as Heading
380 const prefix = '#'.repeat(Math.max(1, Math.min(heading.depth, 6)))
381 const content = getChildrenText(heading.children as MarkdownNode[])
382 return `${prefix} ${content}\n\n`
383 }
384
385 case 'list': {
386 const list = node as List
387 return (
388 list.children
389 .map((item, idx) => {
390 const marker = list.ordered ? `${(list.start ?? 1) + idx}. ` : '- '
391 const text = getChildrenText((item as ListItem).children as MarkdownNode[]).trimEnd()
392 return marker + text
393 })
394 .join('\n') + '\n\n'
395 )
396 }
397
398 case 'listItem':
399 return getChildrenText((node as ListItem).children as MarkdownNode[])
400
401 case 'blockquote': {
402 const blockquote = node as Blockquote
403 const content = blockquote.children
404 .map((child) => nodeToPlainText(child).replace(/^/gm, '> '))
405 .join('')
406 return `${content}\n\n`
407 }
408
409 case 'code': {
410 const code = node as Code
411 const header = code.lang ? `\`\`\`${code.lang}\n` : '```\n'
412 return `${header}${code.value}\n\`\`\`\n\n`
413 }
414
415 case 'break':

Callers 2

renderTableFunction · 0.85
renderNodeFunction · 0.85

Calls 1

getChildrenTextFunction · 0.85

Tested by

no test coverage detected