Fix markdown horizontal rule rendering in web chat

Ensure --- / *** / ___ are recognized as thematic breaks and add regression test.
This commit is contained in:
Ambar-13 2026-01-27 18:14:05 +08:00
parent d7a00dc823
commit 2c4e59fd96
2 changed files with 13 additions and 1 deletions

View File

@ -282,7 +282,14 @@ function renderGroupedMessage(
)}</div>`
: nothing}
${markdown
? html`<div class="chat-text">${unsafeHTML(toSanitizedMarkdownHtml(markdown))}</div>`
? html`
<div class="chat-text">
${unsafeHTML(toSanitizedMarkdownHtml(
// Ensure horizontal rules (---) are padded with newlines
// so the markdown parser recognizes them correctly.
markdown.replace(/^(---|\*\*\*|___)$/gm, '\n$1\n')
))}
</div>`
: nothing}
${toolCards.map((card) => renderToolCardSidebar(card, onOpenSidebar))}
</div>

View File

@ -29,4 +29,9 @@ describe("toSanitizedMarkdownHtml", () => {
expect(html).toContain("<code");
expect(html).toContain("console.log(1)");
});
it("renders horizontal rules", () => {
const html = toSanitizedMarkdownHtml("Line 1\n\n---\n\nLine 2");
expect(html).toContain("<hr");
});
});