(
content: string,
options: MarkdownRenderOptions = {},
)
| 1057 | } |
| 1058 | |
| 1059 | export function renderStreamingMarkdown( |
| 1060 | content: string, |
| 1061 | options: MarkdownRenderOptions = {}, |
| 1062 | ): ReactNode { |
| 1063 | if (!hasMarkdown(content)) { |
| 1064 | return content |
| 1065 | } |
| 1066 | |
| 1067 | if (!hasIncompleteCodeFence(content)) { |
| 1068 | return renderMarkdown(content, options) |
| 1069 | } |
| 1070 | |
| 1071 | const lastFenceIndex = content.lastIndexOf('```') |
| 1072 | if (lastFenceIndex === -1) { |
| 1073 | return renderMarkdown(content, options) |
| 1074 | } |
| 1075 | |
| 1076 | const completeSection = content.slice(0, lastFenceIndex) |
| 1077 | const pendingSection = content.slice(lastFenceIndex) |
| 1078 | |
| 1079 | const segments: ReactNode[] = [] |
| 1080 | |
| 1081 | if (completeSection.length > 0) { |
| 1082 | segments.push(renderMarkdown(completeSection, options)) |
| 1083 | } |
| 1084 | |
| 1085 | if (pendingSection.length > 0) { |
| 1086 | segments.push(pendingSection) |
| 1087 | } |
| 1088 | |
| 1089 | return mergeStreamingSegments(segments) |
| 1090 | } |
no test coverage detected