MCPcopy Create free account
hub / github.com/anus-dev/ANUS / MarkdownDisplayInternal

Function MarkdownDisplayInternal

packages/cli/src/ui/utils/MarkdownDisplay.tsx:30–284  ·  view source on GitHub ↗
({
  text,
  isPending,
  availableTerminalHeight,
  terminalWidth,
})

Source from the content-addressed store, hash-verified

28const LIST_ITEM_TEXT_FLEX_GROW = 1;
29
30const MarkdownDisplayInternal: React.FC<MarkdownDisplayProps> = ({
31 text,
32 isPending,
33 availableTerminalHeight,
34 terminalWidth,
35}) => {
36 if (!text) return <></>;
37
38 const lines = text.split('\n');
39 const headerRegex = /^ *(#{1,4}) +(.*)/;
40 const codeFenceRegex = /^ *(`{3,}|~{3,}) *(\w*?) *$/;
41 const ulItemRegex = /^([ \t]*)([-*+]) +(.*)/;
42 const olItemRegex = /^([ \t]*)(\d+)\. +(.*)/;
43 const hrRegex = /^ *([-*_] *){3,} *$/;
44 const tableRowRegex = /^\s*\|(.+)\|\s*$/;
45 const tableSeparatorRegex = /^\s*\|?\s*(:?-+:?)\s*(\|\s*(:?-+:?)\s*)+\|?\s*$/;
46
47 const contentBlocks: React.ReactNode[] = [];
48 let inCodeBlock = false;
49 let lastLineEmpty = true;
50 let codeBlockContent: string[] = [];
51 let codeBlockLang: string | null = null;
52 let codeBlockFence = '';
53 let inTable = false;
54 let tableRows: string[][] = [];
55 let tableHeaders: string[] = [];
56
57 function addContentBlock(block: React.ReactNode) {
58 if (block) {
59 contentBlocks.push(block);
60 lastLineEmpty = false;
61 }
62 }
63
64 lines.forEach((line, index) => {
65 const key = `line-${index}`;
66
67 if (inCodeBlock) {
68 const fenceMatch = line.match(codeFenceRegex);
69 if (
70 fenceMatch &&
71 fenceMatch[1].startsWith(codeBlockFence[0]) &&
72 fenceMatch[1].length >= codeBlockFence.length
73 ) {
74 addContentBlock(
75 <RenderCodeBlock
76 key={key}
77 content={codeBlockContent}
78 lang={codeBlockLang}
79 isPending={isPending}
80 availableTerminalHeight={availableTerminalHeight}
81 terminalWidth={terminalWidth}
82 />,
83 );
84 inCodeBlock = false;
85 codeBlockContent = [];
86 codeBlockLang = null;
87 codeBlockFence = '';

Callers

nothing calls this directly

Calls 1

addContentBlockFunction · 0.85

Tested by

no test coverage detected