fix(share): footnotes not working

This commit is contained in:
Elian Doran 2025-01-07 14:43:12 +02:00
parent d6dedb1611
commit 5ffd8bc790
No known key found for this signature in database

View File

@ -70,10 +70,38 @@ function renderText(result: Result, note: SNote) {
for (const linkEl of document.querySelectorAll("a")) { for (const linkEl of document.querySelectorAll("a")) {
const href = linkEl.getAttribute("href"); const href = linkEl.getAttribute("href");
if (!href?.startsWith("#")) { // Preserve footnotes.
if (href?.startsWith("#fn")) {
continue; continue;
} }
if (href?.startsWith("#")) {
handleAttachmentLink(linkEl, href);
}
}
result.content = document.body.innerHTML;
if (result.content.includes(`<span class="math-tex">`)) {
result.header += `
<script src="../${assetPath}/node_modules/katex/dist/katex.min.js"></script>
<link rel="stylesheet" href="../${assetPath}/node_modules/katex/dist/katex.min.css">
<script src="../${assetPath}/node_modules/katex/dist/contrib/auto-render.min.js"></script>
<script src="../${assetPath}/node_modules/katex/dist/contrib/mhchem.min.js"></script>
<script>
document.addEventListener("DOMContentLoaded", function() {
renderMathInElement(document.getElementById('content'));
});
</script>`;
}
if (note.hasLabel("shareIndex")) {
renderIndex(result);
}
}
}
function handleAttachmentLink(linkEl: HTMLAnchorElement, href: string) {
const linkRegExp = /attachmentId=([a-zA-Z0-9_]+)/g; const linkRegExp = /attachmentId=([a-zA-Z0-9_]+)/g;
let attachmentMatch let attachmentMatch
if (attachmentMatch = linkRegExp.exec(href)) { if (attachmentMatch = linkRegExp.exec(href)) {
@ -108,27 +136,6 @@ function renderText(result: Result, note: SNote) {
linkEl.removeAttribute("href"); linkEl.removeAttribute("href");
} }
} }
}
result.content = document.body.innerHTML;
if (result.content.includes(`<span class="math-tex">`)) {
result.header += `
<script src="../${assetPath}/node_modules/katex/dist/katex.min.js"></script>
<link rel="stylesheet" href="../${assetPath}/node_modules/katex/dist/katex.min.css">
<script src="../${assetPath}/node_modules/katex/dist/contrib/auto-render.min.js"></script>
<script src="../${assetPath}/node_modules/katex/dist/contrib/mhchem.min.js"></script>
<script>
document.addEventListener("DOMContentLoaded", function() {
renderMathInElement(document.getElementById('content'));
});
</script>`;
}
if (note.hasLabel("shareIndex")) {
renderIndex(result);
}
}
} }
function renderCode(result: Result) { function renderCode(result: Result) {