fix(settings): render changelog entries as markdown
This commit is contained in:
3 files changed
+35
-6
No files matched your search
+19
-1
@@ -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("<script>alert(1)</script>");
|
||||
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 |");
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user