footnoter.js
1#!/usr/bin/env bun
2
3const filePath = Bun.argv[2]
4const file = Bun.file(filePath)
5let textContent = await file.text()
6let textGroups = textContent.split("<hr />").map(g => g.trim())
7
8textGroups = textGroups.map((g) => {
9 let ret = g
10 let footnote
11 let i = 1
12 let notes = []
13 const footnotesRe = /\s?\[(?<footnote>[^\]]*)\]/
14 while (ret.match(footnotesRe) !== null) {
15 footnote = ret.match(footnotesRe)
16 const content = footnote.groups.footnote
17 ret = ret.replace(footnotesRe, `<small><sup><a href="#foot-${i}" name="sup-${i}">${i}</a></sup></small>`)
18 notes.push(`<p><small><a href="#sup-${i}" name="foot-${i}">[${i}]</a> ${content.replace(' \ ', '<br />')}</small></p>`)
19 i++
20 }
21 ret += "<br /><br />"+notes.join("\n\n")
22 return ret
23})
24const final = textGroups.join("\n\n<hr />\n\n");
25file.write(final);