From 904fc10d89300a3efa5a826a20adfce6f69eb03f Mon Sep 17 00:00:00 2001 From: Mohamed Boudra Date: Thu, 15 Oct 2026 20:24:56 +0200 Subject: [PATCH] fix(markdown): preserve adjacency around inline HTML --- packages/app/src/components/markdown/html.ts | 9 +-------- packages/app/src/components/markdown/renderer.test.ts | 10 +++++++--- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/packages/app/src/components/markdown/html.ts b/packages/app/src/components/markdown/html.ts index 5babb682c2..467430fb72 100644 --- a/packages/app/src/components/markdown/html.ts +++ b/packages/app/src/components/markdown/html.ts @@ -69,8 +69,7 @@ export function normalizeMarkdownHtml(source: string): string { if (EMPHASIS[name]) return EMPHASIS[name]; const boundary = layoutBoundary(name, source, raw, offset, closing); if (boundary !== null) return boundary; - if (name === "a") - return markdownAnchor(raw, closing, links) + inlineBoundary(source, raw, offset, closing); + if (name === "a") return markdownAnchor(raw, closing, links); if (name === "img" && !closing) { const { src, alt = "" } = attributes(raw); return src ? `![${alt.replace(/[[\]\\]/g, "\\$&")}](<${markdownUrl(src)}>)` : alt; @@ -126,11 +125,6 @@ function markdownAnchor(raw: string, closing: boolean, links: (string | undefine return href === undefined ? "" : "["; } -function inlineBoundary(source: string, raw: string, offset: number, closing: boolean): string { - if (!closing) return ""; - return /^(?:<[A-Za-z]|[A-Za-z0-9])/.test(source.slice(offset + raw.length)) ? " " : ""; -} - function blockBoundary(source: string, raw: string, offset: number, closing: boolean): string { if (closing) { const following = source.slice(offset + raw.length); @@ -160,6 +154,5 @@ function layoutBoundary( if (BLOCK_TAGS.has(name)) return blockBoundary(source, raw, offset, closing); if ((name === "td" || name === "th") && closing) return /^ { "**Review details**\n\nBody **stays**.", ], ["BeforeAfter", "BeforeAfter"], + ["file.ts", "file.ts"], + ['GitHub', "[Git]()Hub"], + ["GitHub", "GitHub"], + ["Git Hub", "Git Hub"], ["
Keep the content
", "Keep the content"], [ 'Review', @@ -297,14 +301,14 @@ it("uses the first repeated image reference definition", () => { ); }); -it("keeps Greptile header links and block text separated", () => { +it("preserves authored adjacency in the Greptile header", () => { const source = '

RetriggerView in GreptileConfidence Score: 2/5

'; const rendered = prepareMarkdownSource(source, undefined, { supportsSvg: false }).render(); expect(rendered).toContain( - "[Retrigger]() [View in Greptile]", + "[Retrigger]()[View in Greptile]", ); - expect(rendered).toContain(") Confidence Score: 2/5"); + expect(rendered).toContain(")Confidence Score: 2/5"); }); it("keeps paragraph, heading and table-row boundaries when stripping HTML", () => {