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

Function renderNode

cli/src/utils/markdown-renderer.tsx:854–990  ·  view source on GitHub ↗
(
  node: MarkdownNode,
  state: RenderState,
  parentType: MarkdownNode['type'],
  nextSibling?: MarkdownNode,
)

Source from the content-addressed store, hash-verified

852}
853
854const renderNode = (
855 node: MarkdownNode,
856 state: RenderState,
857 parentType: MarkdownNode['type'],
858 nextSibling?: MarkdownNode,
859): ReactNode[] => {
860 switch (node.type) {
861 case 'root':
862 return renderNodes(
863 (node as Root).children as MarkdownNode[],
864 state,
865 node.type,
866 )
867
868 case 'paragraph': {
869 const children = renderNodes(
870 (node as Paragraph).children as MarkdownNode[],
871 state,
872 node.type,
873 )
874 const nodes = [...children]
875 if (parentType === 'listItem') {
876 nodes.push('\n')
877 } else if (parentType === 'blockquote') {
878 nodes.push('\n')
879 } else {
880 const isTightFollowup =
881 parentType === 'root' &&
882 nextSibling &&
883 (nextSibling.type === 'blockquote' || nextSibling.type === 'list')
884 nodes.push(isTightFollowup ? '\n' : '\n\n')
885 }
886 return nodes
887 }
888
889 case 'text':
890 return [(node as Text).value]
891
892 case 'strong': {
893 const children = renderNodes(
894 (node as Strong).children as MarkdownNode[],
895 state,
896 node.type,
897 )
898 return [
899 <span key={state.nextKey()} attributes={TextAttributes.BOLD}>
900 {wrapSegmentsInFragments(children, state.nextKey())}
901 </span>,
902 ]
903 }
904
905 case 'emphasis': {
906 const children = renderNodes(
907 (node as Emphasis).children as MarkdownNode[],
908 state,
909 node.type,
910 )
911 return [

Callers 2

renderNodesFunction · 0.85
renderMarkdownFunction · 0.85

Calls 10

renderNodesFunction · 0.85
wrapSegmentsInFragmentsFunction · 0.85
renderInlineCodeFunction · 0.85
renderHeadingFunction · 0.85
renderListFunction · 0.85
renderBlockquoteFunction · 0.85
renderCodeBlockFunction · 0.85
renderLinkFunction · 0.85
renderTableFunction · 0.85
nodeToPlainTextFunction · 0.85

Tested by

no test coverage detected