fix(settings): render changelog entries as markdown

This commit is contained in:
t8y2 committed 2026-09-02 13:17:26 +08:00
1 parent ad98bef167
commit 069b84daf9
3 files changed
+35 -6

No files matched your search

+19 -1
View File
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
import { aiMarkdownLinkUrlFromClick, formatAiInlineMarkdown, handleAiMarkdownLinkClick, normalizeAiMarkdownLink } from "@/lib/ai/aiMarkdown";
import { aiMarkdownLinkUrlFromClick, formatAiInlineMarkdown, formatAiInlineMarkdownFragment, handleAiMarkdownLinkClick, normalizeAiMarkdownLink } from "@/lib/ai/aiMarkdown";
describe("formatAiInlineMarkdown", () => {
it("renders http links for external browser handling", () => {
@@ -26,6 +26,24 @@ describe("formatAiInlineMarkdown", () => {
});
});
describe("formatAiInlineMarkdownFragment", () => {
it("renders single-line content without a block paragraph wrapper", () => {
const html = formatAiInlineMarkdownFragment("Title — see [PR #1](https://example.com/pull/1) and `code`.");
expect(html).not.toContain("<p>");
expect(html).toContain('href="https://example.com/pull/1"');
expect(html).toContain("<code");
expect(html).toContain("Title — see");
});
it("escapes raw html like the block renderer", () => {
const html = formatAiInlineMarkdownFragment("<script>alert(1)</script>");
expect(html).toContain("&lt;script&gt;alert(1)&lt;/script&gt;");
expect(html).not.toContain("<script>");
});
});
describe("markdown table overflow wrapping", () => {
it("wraps tables in scroll container", () => {
const html = formatAiInlineMarkdown("| a | b |\n| --- | --- |\n| 1 | 2 |\n| 3 | 4 |");
+8
View File
@@ -56,6 +56,14 @@ export function formatAiInlineMarkdown(text: string): string {
}
}
export function formatAiInlineMarkdownFragment(text: string): string {
try {
return markedInstance.parseInline(text) as string;
} catch {
return escapeHtml(text);
}
}
export function normalizeAiMarkdownLink(href: string): string | null {
try {
const url = new URL(href);