change behaviour followingNotes (before next title or next ol)

This commit is contained in:
Julie Blanc 2026-04-09 22:15:00 +02:00
parent 824317476c
commit a8e3f5c31b

View file

@ -27,19 +27,38 @@ export default class followingNotes extends Handler {
createCallandMarker(content, this.notesClass, newNotesClass); createCallandMarker(content, this.notesClass, newNotesClass);
const containerMap = new Map();
let notes = content.querySelectorAll(this.notesClass); let notes = content.querySelectorAll(this.notesClass);
notes.forEach(function (note) { notes.forEach(function (note) {
let paragraph = note.closest("p"); let paragraph = note.closest("p");
if (!paragraph) return; if (!paragraph) return;
let container = paragraph.nextElementSibling; // Find next boundary: heading or ol[type="1"]
if (!container || !container.classList.contains("container-following-note")) { let boundary = null;
container = document.createElement("div"); let sibling = paragraph.nextElementSibling;
container.classList.add("container-following-note"); while (sibling) {
paragraph.after(container); if (sibling.matches('h1, h2, h3, h4, h5, h6, ol[type="1"]')) {
boundary = sibling;
break;
}
sibling = sibling.nextElementSibling;
} }
container.appendChild(note); const mapKey = boundary || paragraph.parentElement;
if (!containerMap.has(mapKey)) {
let container = document.createElement("div");
container.classList.add("container-following-note");
if (boundary) {
boundary.before(container);
} else {
paragraph.parentElement.appendChild(container);
}
containerMap.set(mapKey, container);
}
containerMap.get(mapKey).appendChild(note);
}); });