({
text,
isPending,
availableTerminalHeight,
terminalWidth,
})
| 28 | const LIST_ITEM_TEXT_FLEX_GROW = 1; |
| 29 | |
| 30 | const 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 = ''; |
nothing calls this directly
no test coverage detected