change behaviour followingNotes (before next title or next ol)
This commit is contained in:
parent
824317476c
commit
a8e3f5c31b
1 changed files with 25 additions and 6 deletions
|
|
@ -27,19 +27,38 @@ export default class followingNotes extends Handler {
|
|||
createCallandMarker(content, this.notesClass, newNotesClass);
|
||||
|
||||
|
||||
const containerMap = new Map();
|
||||
|
||||
let notes = content.querySelectorAll(this.notesClass);
|
||||
notes.forEach(function (note) {
|
||||
let paragraph = note.closest("p");
|
||||
if (!paragraph) return;
|
||||
|
||||
let container = paragraph.nextElementSibling;
|
||||
if (!container || !container.classList.contains("container-following-note")) {
|
||||
container = document.createElement("div");
|
||||
container.classList.add("container-following-note");
|
||||
paragraph.after(container);
|
||||
// Find next boundary: heading or ol[type="1"]
|
||||
let boundary = null;
|
||||
let sibling = paragraph.nextElementSibling;
|
||||
while (sibling) {
|
||||
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);
|
||||
});
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue