caption element before table is placed as first element of the table (allows markdown tables to have caption)

This commit is contained in:
Adam Teichert
2025-12-15 23:01:35 -07:00
parent a203dc6e46
commit e07d0a6e47
2 changed files with 53 additions and 3 deletions

View File

@@ -125,8 +125,21 @@ export function markdownToHTMLSafe({
}
export function markdownToHtmlNoImages(markdownString: string) {
const clean = DOMPurify.sanitize(
marked.parse(markdownString, { async: false, pedantic: false, gfm: true })
).replaceAll(/>[^<>]*<\/math>/g, "></math>");
const parsedHtml = marked.parse(markdownString, {
async: false,
pedantic: false,
gfm: true,
}) as string;
// Move caption inside table
const htmlWithCaptionInTable = parsedHtml.replace(
/(<caption[^>]*>[\s\S]*?<\/caption>)\s*(<table[^>]*>)/g,
"$2$1"
);
const clean = DOMPurify.sanitize(htmlWithCaptionInTable).replaceAll(
/>[^<>]*<\/math>/g,
"></math>"
);
return clean;
}