GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(web): recognize closed chat code fences with CR-only line endings… · Ryoku-dev/hyakki@82a82ee

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/web/src/components/chat
    • MarkdownCodeBlock.logic.test.ts
    • MarkdownCodeBlock.logic.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/web/src/components/chat/MarkdownCodeBlock.logic.test.ts‎

Copy file name to clipboard
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { describe, expect, it } from "vite-plus/test";
2+
3+
import { markdownTree } from "../../markdown/wordsHast";
4+
import { isClosedCodeFence } from "./MarkdownCodeBlock.logic";
5+
6+
describe("isClosedCodeFence", () => {
7+
it.each(["\n", "\r\n", "\r"])("tells closed from unclosed fences with %j line endings", (eol) => {
8+
for (const closed of [false, true]) {
9+
const source = ["```sh", "echo hi", ...(closed ? ["```"] : [])].join(eol);
10+
const [pre] = markdownTree(source).children;
11+
const code = pre?.type === "element" ? pre.children[0] : undefined;
12+
const content = code?.type === "element" ? code.children[0] : undefined;
13+
if (pre?.type !== "element" || content?.type !== "text") {
14+
throw new Error("Expected a parsed code block");
15+
}
16+
expect(isClosedCodeFence(pre, source, content.value)).toBe(closed);
17+
}
18+
});
19+
});
Collapse file

‎apps/web/src/components/chat/MarkdownCodeBlock.logic.ts‎

Copy file name to clipboardExpand all lines: apps/web/src/components/chat/MarkdownCodeBlock.logic.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export function isClosedCodeFence(node: Element | undefined, text: string, code:
5252
const opening = /^(?:`{3,}|~{3,})/.exec(source)?.[0];
5353
// One class for the blockquote prefix: nested quantifiers here backtrack
5454
// exponentially on code lines that start with many `> ` markers.
55-
const closing = /(?:^|\n)[ \t>]*(`{3,}|~{3,})[ \t\r]*$/.exec(source)?.[1];
55+
const closing = /(?:^|[\r\n])[ \t>]*(`{3,}|~{3,})[ \t\r]*$/.exec(source)?.[1];
5656
return (
5757
opening !== undefined &&
5858
closing !== undefined &&

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.