Skip to content

Commit d29c479

Browse files
committed
Title parsing.
1 parent 26589d9 commit d29c479

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

js/mathjax.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
window.MathJax = {
22
tex: {
3-
packages: { '[+]': ['noerrors', 'ams'] },
3+
packages: { '[+]': ['noerrors', 'ams', 'tipa'] },
44
macros: {
55
qed: "\\square",
66
ran: "\\text{ran}",

notes/js/note.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ marked.setOptions({
4040
const headingData = [];
4141
const renderer = new marked.Renderer();
4242

43-
renderer.heading = (text, level) => {
44-
const source = text;
43+
renderer.heading = (text, level, raw) => {
44+
const source = typeof raw === 'string' ? raw : text;
4545
const slug = slugify(source);
46-
headingData.push({ text: source, level, slug });
46+
headingData.push({ text, level, slug });
4747
return `<h${level} id="${slug}">${text}</h${level}>`;
4848
};
4949

@@ -79,11 +79,19 @@ fetch(`/notes/courses/${course}/${noteSlug}.md`)
7979
headingData.forEach(({ text, level, slug }) => {
8080
const li = document.createElement("li");
8181
li.style.marginLeft = `${(level - 1) * 16}px`;
82-
li.innerHTML = `<a href="#${slug}">${text}</a>`;
82+
83+
const a = document.createElement("a");
84+
a.href = `#${slug}`;
85+
a.textContent = text;
86+
li.append(a);
87+
li.addEventListener("click", (e) => {
88+
e.preventDefault();
89+
document.getElementById(slug).scrollIntoView({ behavior: "smooth" });
90+
});
8391
ul.append(li);
8492
});
8593

86-
tocNav.append(ul);
94+
tocNav.appendChild(ul);
8795
container.prepend(tocNav);
8896
}
8997

0 commit comments

Comments
 (0)