50 lines
1.6 KiB
JavaScript
50 lines
1.6 KiB
JavaScript
/*
|
|
Adds a custom css property that switches footnote style
|
|
between endnodes (default for Pandoc) and footnotes
|
|
modified from: https://pagedjs.org/plugins/endnotes-to-footnotes/
|
|
|
|
*/
|
|
|
|
|
|
|
|
const endNoteCalloutsQuery = ".footnote-ref";
|
|
|
|
// the hook
|
|
class endToFootNotes extends Paged.Handler {
|
|
constructor(chunker, polisher, caller) {
|
|
super(chunker, polisher, caller);
|
|
this.notestyle = 'endnotes';
|
|
}
|
|
|
|
onDeclaration(declaration, dItem, dList, rule) {
|
|
if (declaration.property == "--paged-note-style") {
|
|
if (declaration.value.value.includes("footnote")) {
|
|
console.log('FOOTNOTES!');
|
|
// console.log(declaration.property, declaration, rule);
|
|
this.notestyle = 'footnotes'
|
|
}
|
|
}
|
|
}
|
|
|
|
beforeParsed(content) {
|
|
if ('footnotes' !== this.notestyle) {
|
|
return;
|
|
}
|
|
console.log("parsef");
|
|
let callouts = content.querySelectorAll(endNoteCalloutsQuery);
|
|
callouts.forEach((callout) => {
|
|
console.log(callout.hash)
|
|
// console.log(callout.href)
|
|
// console.log(`#${callout.href.callout.href.hash}`)
|
|
let note = content.querySelector(callout.hash);
|
|
console.log(note);
|
|
if (!note) { return console.warn(`there is no note with the id of ${callout.hash}`) }
|
|
let noteContent = `<span class="pagedjs-end-to-footnote">${note.innerHTML}</span>`;
|
|
callout.insertAdjacentHTML("afterend", noteContent);
|
|
callout.remove();
|
|
note.remove();
|
|
});
|
|
}
|
|
}
|
|
Paged.registerHandlers(endToFootNotes);
|