Skip to content

Commit 4b20037

Browse files
committed
fix(web): ignore a split CRLF when checking for a closed Mermaid fence
1 parent 37a959f commit 4b20037

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

‎apps/web/src/components/ChatMarkdown.test.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ describe("ChatMarkdown Mermaid streaming", () => {
192192
["> ```mermaid\n> flowchart LR\n> A --> B\n> ```", "\n> ```"],
193193
["- Diagram\n\n ```mermaid\n flowchart LR\n A --> B\n ```", "\n ```"],
194194
["```mermaid\r\nflowchart LR\r\nA --> B\r\n\t```", "\r\n```"],
195+
["```mermaid\r\nflowchart LR\r\nA --> B\r\n\t```\r", "\n```"],
195196
])("reveals a finished fence before the message finishes: %s", async (open, closing) => {
196197
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
197198
let renderer: ReactTestRenderer | undefined;

‎apps/web/src/components/ChatMarkdown.tsx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,8 +496,9 @@ function isClosedCodeFence(
496496
opening[0] === closing[0] &&
497497
closing.length >= opening.length &&
498498
// A real closer is excluded from the parsed code. Invalid, overindented
499-
// markers remain in it, so the source must have an extra fence line.
500-
source.split(/\r\n|\r|\n/).length > code.split(/\r\n|\r|\n/).length
499+
// markers remain in it, so the source must have an extra fence line. A
500+
// stream cut inside a CRLF leaves a lone CR that is not a line of its own.
501+
source.replace(/\r$/, "").split(/\r\n|\r|\n/).length > code.split(/\r\n|\r|\n/).length
501502
);
502503
}
503504

0 commit comments

Comments
 (0)