import { Icon, backSVG } from "./icon.js"; import { BannerData } from "./data.js"; function handleFootnote(md: string) { if (!md.includes("[^")) return md; // Replace footnote references with HTML superscript tags return ( md.replace(/\[\^(\d+)\](?::\s*(.*))?/g, (match, id, text) => text ? // Footnote definition `
  • ${text}${backSVG}
  • ` : // Footnote reference `${id}` ) // Wrap the footnote definitions in an ordered list .replace(/(
  • \n$1\n") ); } function handleDeleteLine(md: string): string { if (!md.includes("~~")) return md; return md.replace(/~~(.*?)~~/g, (match, text) => "" + text + ""); } function handleNoteIcon(md: string): string { if (!md.includes("[!")) return md; return md.replace(/\[\!(\w+)\](?::\s*(.*))?/g, (match, icon, _) => Icon[icon as string]); } function handleBanner(md: string): string { if (!md.includes('[[')) return md; return md.replace(/\[\[(.*?)\]\]/g, (match, raw) => { const data = JSON.parse(raw) as BannerData if (data.type != 'banner') return match return `

    ${data.title}

    ${data.text}

    ` }) } export function handleFeatures(markdown: string): string { // Handle Footnote let md = handleFootnote(markdown) // Handle Delete Line: ~~something~~ to something md = handleDeleteLine(md) // Handle Icon md = handleNoteIcon(md) // Handle Banner md = handleBanner(md) return md }