mirror of
https://github.com/multica-ai/multica.git
synced 2026-07-24 11:10:25 +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>
9 lines
339 B
TypeScript
9 lines
339 B
TypeScript
/**
|
|
* Escape characters that break Markdown link/image label syntax: [ ] \ ( )
|
|
* Used by image and file-card renderMarkdown to prevent raw filenames from
|
|
* corrupting the `` / `!file[name](url)` output.
|
|
*/
|
|
export function escapeMarkdownLabel(text: string): string {
|
|
return text.replace(/[[\]\\()]/g, (ch) => `\\${ch}`);
|
|
}
|