Skip to content

Commit ef75275

Browse files
committed
Footnote handling, package updates
1 parent e21092d commit ef75275

4 files changed

Lines changed: 2869 additions & 297 deletions

File tree

notes/courses/LING-UA-1/index.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
[
22
{
33
"slug": "01-intro",
4-
"title": "What is Language",
4+
"title": "01 - What is Language",
55
"date": "2025-05-19"
66
},
77
{
88
"slug": "02-03-phonetics",
9-
"title": "Phonetics",
9+
"title": "02/03 - Phonetics",
1010
"date": "2025-05-20/21"
1111
},
1212
{
1313
"slug": "04-05-phonology",
14-
"title": "Phonology",
14+
"title": "04/05 - Phonology",
1515
"date": "2025-05-22/27"
1616
},
1717
{
1818
"slug": "06-07-morphology",
19-
"title": "Morphology",
19+
"title": "06/07 - Morphology",
2020
"date": "2025-05-28/29"
2121
}
2222
]

notes/js/note.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,21 @@ fetch(`/notes/courses/${course}/${noteSlug}.md`)
4949
const { meta, body } = parseFrontMatter(md);
5050
document.title = meta.title || noteSlug;
5151

52+
const footnotes = [];
53+
54+
const bodyWithoutDefs = body.replace(
55+
/^\s*\[([^\]]+)\]:\s*(.+)$/gm,
56+
(_, num, text) => {
57+
footnotes.push({ num, text: text.trim() });
58+
return '';
59+
}
60+
)
61+
62+
const bodyWithRefs = bodyWithoutDefs.replace(
63+
/\[\^(d+)\]/g,
64+
(_, num) => `<sup id="fnref${num}"><a href="#fn${num}">${num}</a></sup>`
65+
);
66+
5267
const back = document.getElementById("back-to-course");
5368
back.href = `course.html?id=${encodeURIComponent(course)}`;
5469

@@ -59,7 +74,7 @@ fetch(`/notes/courses/${course}/${noteSlug}.md`)
5974
headingData.length = 0;
6075
for (let k in slugCounts) delete slugCounts[k];
6176

62-
const dirty = marked.parse(body);
77+
const dirty = marked.parse(bodyWithRefs);
6378
const sanitize = window.DOMPurify?.sanitize || (s => s);
6479
const contentDiv = document.createElement("div");
6580
contentDiv.innerHTML = sanitize(dirty);
@@ -108,6 +123,24 @@ fetch(`/notes/courses/${course}/${noteSlug}.md`)
108123
container.insertBefore(tocNav, contentDiv);
109124
}
110125

126+
if (footnotes.length) {
127+
const fnSec = document.createElement("section");
128+
fnSec.className = "footnotes";
129+
const hr = document.createElement("hr");
130+
fnSec.appendChild(hr);
131+
132+
const ol = document.createElement("ol");
133+
footnotes.forEach(({ num, text }) => {
134+
const li = document.createElement("li");
135+
li.id = `fn${num}`;
136+
const fnHtml = sanitize(marked.parseInline(text));
137+
li.innerHTML = fnHtml;
138+
ol.appendChild(li);
139+
});
140+
fnSec.appendChild(ol);
141+
container.appendChild(fnSec);
142+
}
143+
111144
contentDiv.querySelectorAll('table').forEach(table => {
112145
const wrapper = document.createElement('div');
113146
wrapper.className = 'table-wrapper';

0 commit comments

Comments
 (0)