mirror of
https://github.com/multica-ai/multica.git
synced 2026-07-25 03:55:27 +02:00
* fix: escape special chars in image alt and file-card filename during Markdown serialization Filenames containing Markdown label characters ([, ], \, (, )) broke the  and !file[name](url) syntax, causing raw Markdown to render instead of the image/file card. - Add shared escapeMarkdownLabel utility - Apply escaping in file-card renderMarkdown - Add renderMarkdown to ImageExtension for alt text escaping - Add regression tests Closes #3616 Co-authored-by: multica-agent <github@multica.ai> * fix: address review — fix tokenizer regex, unescape labels, add regression tests - Remove unused tokenizeFn (TS6133) - Change file-card regex to (?:\\.|[^\]])* to handle escaped brackets - Unescape labels in tokenize() and preprocessFileCards() - Export ImageExtension for testability - Rewrite tests: 3 describe blocks covering ImageExtension.renderMarkdown, file-card tokenizer round-trip, and preprocessFileCards (6 tests total) - typecheck and vitest both pass Co-authored-by: multica-agent <github@multica.ai> --------- Co-authored-by: multica-agent <github@multica.ai>
27 lines
784 B
TypeScript
27 lines
784 B
TypeScript
import { describe, it, expect } from "vitest";
|
|
import { escapeMarkdownLabel } from "./escape-markdown-label";
|
|
|
|
describe("escapeMarkdownLabel", () => {
|
|
it("escapes [ and ]", () => {
|
|
expect(escapeMarkdownLabel("photo[1].png")).toBe("photo\\[1\\].png");
|
|
});
|
|
|
|
it("escapes backslash", () => {
|
|
expect(escapeMarkdownLabel("a\\b")).toBe("a\\\\b");
|
|
});
|
|
|
|
it("escapes ( and )", () => {
|
|
expect(escapeMarkdownLabel("file(1).txt")).toBe("file\\(1\\).txt");
|
|
});
|
|
|
|
it("escapes all special chars together", () => {
|
|
expect(escapeMarkdownLabel("6P4N\\`X[A~Z(S@XO}WE0FT_P.jpg")).toBe(
|
|
"6P4N\\\\`X\\[A~Z\\(S@XO}WE0FT_P.jpg",
|
|
);
|
|
});
|
|
|
|
it("leaves normal text unchanged", () => {
|
|
expect(escapeMarkdownLabel("hello world.png")).toBe("hello world.png");
|
|
});
|
|
});
|