Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/web/src/components/chat/markdownStreamBlocks.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ describe("splitMarkdownBlocks", () => {
"| a | b |\n| - | - |\n| 1 | 2 |\n\nAfter the table.",
"para\n\n indented code\n\nnext",
"Setext\n===\n\nnext\n---\n\n- [ ] task\n- [x] done",
"- a\n\n ```\n x\n\n```\n\nb",
"- a\n\n ```\n x\n\ny\n\n ```\n\nb",
])("renders each block as the whole text renders it, at every streamed prefix: %j", (text) => {
for (let end = 0; end <= text.length; end++) {
const source = text.slice(0, end);
Expand Down
4 changes: 4 additions & 0 deletions apps/web/src/components/chat/markdownStreamBlocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ export function splitMarkdownBlocks(text: string): string[] | null {
let blockStart = 0;
let lineStart = 0;
let fence: string | null = null;
let fenceIndent = 0;
let afterBlankLine = false;
for (const line of text.split("\n")) {
const opener = FENCE_PATTERN.exec(line)?.[1];
if (fence !== null) {
// A line left of an indented fence may end the list item holding it, which isn't tracked.
if (/\S/.test(line.slice(0, fenceIndent))) break;
if (
opener &&
opener[0] === fence[0] &&
Expand All @@ -35,6 +38,7 @@ export function splitMarkdownBlocks(text: string): string[] | null {
}
afterBlankLine = false;
fence = opener ?? null;
if (opener) fenceIndent = line.indexOf(opener);
}
lineStart += line.length + 1;
}
Expand Down
Loading