add triplecate
This commit is contained in:
parent
cc75afe344
commit
0d3afdc58d
34 changed files with 357 additions and 295 deletions
|
|
@ -11,9 +11,12 @@ export default class inlineNotes extends Handler {
|
|||
|
||||
constructor(chunker, polisher, caller) {
|
||||
super(chunker, polisher, caller);
|
||||
this.input = cssPageWeaver.features.inlineNotes.parameters?.input || ".footnote-ref"; // ← CSS selector of the call element
|
||||
this.containerNotes = cssPageWeaver.features.inlineNotes.parameters?.containerNotes || "#footnotes"; // ← CSS selector of the container of the footnote
|
||||
this.newClass = cssPageWeaver.features.inlineNotes.parameters?.newClass || "inline-note"; // ← Class of the span create for the note
|
||||
const params = cssPageWeaver.features.inlineNotes.parameters;
|
||||
this.input = params?.input || ".footnote-ref"; // ← CSS selector of the call element
|
||||
this.containerNotes = params?.containerNotes || "#footnotes"; // ← CSS selector of the container of the footnote
|
||||
this.newClass = params?.newClass || "inline-note"; // ← Class of the span create for the note
|
||||
this.newNotesClass = params?.newNotesClass || "float-note";
|
||||
this.reset = params?.reset;
|
||||
}
|
||||
|
||||
beforeParsed(content) {
|
||||
|
|
@ -25,6 +28,10 @@ export default class inlineNotes extends Handler {
|
|||
type: this.newClass
|
||||
});
|
||||
|
||||
let notesClass = "." + this.newClass;
|
||||
resetCounter(content, this.reset, notesClass);
|
||||
createCallandMarker(content, notesClass, this.newNotesClass);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -84,7 +91,7 @@ function createNotes(content, input, type){
|
|||
back.remove();
|
||||
}
|
||||
|
||||
let inline_note = document.createElement('span');
|
||||
let inline_note = document.createElement('div');
|
||||
inline_note.className = type;
|
||||
let num = index + 1;
|
||||
inline_note.dataset.counterNote = num;
|
||||
|
|
@ -96,3 +103,105 @@ function createNotes(content, input, type){
|
|||
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// FUNCTIONS -----------------------------------------------------
|
||||
|
||||
|
||||
// RESET COUNTER
|
||||
|
||||
function resetCounter(content, reset, notesClass){
|
||||
|
||||
if(reset && reset != ""){
|
||||
const elements = content.querySelectorAll(reset + ", " + notesClass);
|
||||
let resetEligible = false;
|
||||
elements.forEach(element => {
|
||||
if (element.matches(reset)) {
|
||||
resetEligible = true;
|
||||
} else if (resetEligible && element.matches(notesClass)) {
|
||||
element.dataset.resetCounterFollowingNote = true;
|
||||
resetEligible = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// CALL & MARKER
|
||||
function createCallandMarker(content, notesClass, newNotesClass){
|
||||
|
||||
let notes = content.querySelectorAll(notesClass);
|
||||
let resetNum = 0;
|
||||
|
||||
notes.forEach(function (note, index) {
|
||||
|
||||
if (note.dataset.resetCounterFollowingNote === "true") {
|
||||
resetNum = index;
|
||||
}
|
||||
let num = index + 1 - resetNum;
|
||||
|
||||
note.classList.remove(...note.classList);
|
||||
note.classList.add(newNotesClass);
|
||||
note.dataset.counterNote = num;
|
||||
|
||||
// call
|
||||
let ref_note = document.createElement('span');
|
||||
ref_note.className = newNotesClass + "_call";
|
||||
ref_note.dataset.counterNote = num;
|
||||
ref_note.innerHTML = num;
|
||||
|
||||
// wrap preceding word + call in .wrapper__note-call
|
||||
let wrapper = document.createElement('span');
|
||||
wrapper.className = 'wrapper__note-call';
|
||||
|
||||
let prevSibling = note.previousSibling;
|
||||
if (prevSibling && prevSibling.nodeType === Node.TEXT_NODE) {
|
||||
let text = prevSibling.textContent;
|
||||
let m = text.match(/^([\s\S]*\s)(\S+\s*)$/);
|
||||
if (m) {
|
||||
let before = m[1];
|
||||
let extracted = m[2];
|
||||
|
||||
// Si le dernier mot extrait est uniquement », prendre aussi le mot d'avant
|
||||
if (/^»\s*$/.test(extracted)) {
|
||||
let m2 = before.trimEnd().match(/^([\s\S]*\s|)(\S+)$/);
|
||||
if (m2) {
|
||||
let spaceBetween = before.slice(m2[1].length + m2[2].length);
|
||||
before = m2[1];
|
||||
extracted = m2[2] + spaceBetween + extracted;
|
||||
}
|
||||
}
|
||||
|
||||
prevSibling.textContent = before;
|
||||
wrapper.appendChild(document.createTextNode(extracted));
|
||||
} else {
|
||||
prevSibling.textContent = '';
|
||||
wrapper.appendChild(document.createTextNode(text));
|
||||
}
|
||||
}
|
||||
|
||||
wrapper.appendChild(ref_note);
|
||||
note.before(wrapper);
|
||||
|
||||
// marker + content note wrapped in float-note_body
|
||||
let marker_note = document.createElement('span');
|
||||
marker_note.className = newNotesClass + "_marker";
|
||||
//marker_note.innerHTML = num + ". ";
|
||||
marker_note.innerHTML = num;
|
||||
|
||||
let noteBody = document.createElement('div');
|
||||
noteBody.className = 'float-note_body';
|
||||
while (note.firstChild) {
|
||||
noteBody.appendChild(note.firstChild);
|
||||
}
|
||||
note.appendChild(marker_note);
|
||||
note.appendChild(noteBody);
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue