1
0
mirror of https://github.com/one-among-us/data.git synced 2024-11-23 11:37:37 +08:00
one-among-us-data/scripts/feature.ts

41 lines
1.3 KiB
TypeScript
Raw Normal View History

2024-05-17 20:28:56 +08:00
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
`<li id="footnote-${id}">${text}<a href="#footnote-ref-${id}">${backSVG}</a></li>` : // Footnote reference
`<sup><a href="#footnote-${id}" id="footnote-ref-${id}">${id}</a></sup>`
)
// Wrap the footnote definitions in an ordered list
.replace(/(<li id="footnote.*<\/li>)/gs, "<ol>\n$1\n</ol>")
);
}
function handleDeleteLine(md: string): string {
if (!md.includes("~~")) return md;
return md.replace(/~~(.*?)~~/g, (match, text) => "<del>" + text + "</del>");
}
function handleNoteIcon(md: string): string {
if (!md.includes("[!")) return md;
return md.replace(/\[\!(\w+)\](?::\s*(.*))?/g, (match, icon, _) => Icon[icon as string]);
}
export function handleFeatures(markdown: string): string {
// Handle Footnote
let md = handleFootnote(markdown)
// Handle Delete Line: ~~something~~ to <del>something</del>
md = handleDeleteLine(md)
// Handle Icon
md = handleNoteIcon(md)
return md
}