2026-04-11 17:49:46 +02:00
|
|
|
|
|
|
|
|
class before extends Paged.Handler {
|
|
|
|
|
constructor(chunker, polisher, caller) {
|
|
|
|
|
super(chunker, polisher, caller);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
beforeParsed(content) {
|
|
|
|
|
paragraphId(content);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Paged.registerHandlers(before);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function paragraphId(content) {
|
|
|
|
|
content.querySelectorAll("p, li").forEach((paragraph, index) => {
|
|
|
|
|
let words = paragraph.textContent
|
|
|
|
|
.trim()
|
|
|
|
|
.split(/\s+/)
|
|
|
|
|
.map(word => word.replace(/[^\wÀ-ÿ]/g, "")) // Supprime la ponctuation
|
|
|
|
|
.filter(word => word.length > 0);
|
|
|
|
|
|
|
|
|
|
let id = words.slice(0, 10).map(word => word.charAt(0)).join("").toLowerCase();
|
|
|
|
|
id = "p-" + id;
|
|
|
|
|
|
|
|
|
|
if (!id) id = `para-${index}`; // Si le paragraphe est vide, on donne un id par défaut
|
|
|
|
|
paragraph.dataset.uniqueId = id;
|
|
|
|
|
});
|
|
|
|
|
|
2026-04-11 20:51:26 +02:00
|
|
|
}
|
|
|
|
|
|