mirror of
https://github.com/coder/coder.git
synced 2026-10-16 14:48:56 +08:00
fix(site/src/pages/AgentsPage/components/ChatConversation): keep balanced parentheses in preview link destinations
A link or image destination such as `https://example.com/a_(b)` ended at its first `)`, so the preview title kept the rest of the URL and the closing parenthesis. Allow one level of balanced parentheses inside the destination.
This commit is contained in:
@@ -58,6 +58,17 @@ describe("getThinkingDisclosureDisplay", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it.each([
|
||||
"See [docs](https://example.com/a_(b)) next",
|
||||
"See .png) next",
|
||||
])("keeps balanced parentheses in link destinations: %j", (text) => {
|
||||
expect(getThinkingDisclosureDisplay(text)).toEqual({
|
||||
title: "See docs next",
|
||||
ariaLabel: "Thinking: See docs next",
|
||||
body: text,
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps text that Markdown renders literally in the preview title", () => {
|
||||
const text =
|
||||
"Check `Promise<User>`, `*args*`, 0 < n and n > 0 in user_id_field and APP__DB__URL";
|
||||
|
||||
@@ -55,8 +55,8 @@ const cleanHeadingText = (text: string): string => {
|
||||
return code === undefined ? match : setAside(getCodeSpanText(code));
|
||||
},
|
||||
)
|
||||
.replace(/!\[([^\]]*)\]\([^)]*\)/g, "$1")
|
||||
.replace(/\[([^\]]+)\]\([^)]*\)/g, "$1")
|
||||
.replace(/!\[([^\]]*)\]\((?:[^()]|\([^()]*\))*\)/g, "$1")
|
||||
.replace(/\[([^\]]+)\]\((?:[^()]|\([^()]*\))*\)/g, "$1")
|
||||
.replace(/\*\*([^*\s](?:[^*]*[^*\s])?)\*\*/g, "$1")
|
||||
.replace(/\b__([^_]+)__\b/g, "$1")
|
||||
.replace(/\*([^*\s](?:[^*]*[^*\s])?)\*/g, "$1")
|
||||
|
||||
Reference in New Issue
Block a user