1
0
mirror of https://github.com/one-among-us/data.git synced 2024-11-23 03:27:38 +08:00

[PR] Merge pull request #195 from LS-KR/main

[O] Handle footnote
This commit is contained in:
Elihuso Quigley 2024-02-28 19:50:02 -08:00 committed by GitHub
commit ef97ae8bca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -120,6 +120,9 @@ function buildPeoplePages() {
// Read markdown page and remove markdown meta
let markdown = metadataParser(fs.readFileSync(path.join(srcPath, `page${lang}.md`), "utf-8")).content.replaceAll("<!--", "{/* ").replaceAll("-->", " */}");
// Handle Footnote
markdown = handleFootnote(markdown)
// Autocorrect markdown
markdown = autocorrect.formatFor(markdown, 'markdown')
@ -133,6 +136,21 @@ function buildPeoplePages() {
}
}
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}">↩</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>')
}
// Copy `people/${dirname}/photos` to `dist/people/${dirname}/`.
function copyPeopleAssets() {
const PEOPLE_ASSETS = ["photos", "backup", "page.md"];