change font-sans for blockquote + add counters.js

This commit is contained in:
Julie Blanc 2026-01-20 23:02:35 +01:00
parent abbd549428
commit 32e02d956a
15 changed files with 161 additions and 192 deletions

94
js/counters.js Normal file
View file

@ -0,0 +1,94 @@
import { Handler } from '/csspageweaver/lib/paged.esm.js';
export default class counters extends Handler {
constructor(chunker, polisher, caller) {
super(chunker, polisher, caller);
}
// Convertir en upper-alpha (A, B, C...)
toUpperAlpha(num) {
return String.fromCharCode(64 + num);
}
// Convertir en lower-alpha (a, b, c...)
toLowerAlpha(num) {
return String.fromCharCode(96 + num);
}
// Convertir en upper-roman (I, II, III...)
toUpperRoman(num) {
const romanNumerals = [
['M', 1000], ['CM', 900], ['D', 500], ['CD', 400],
['C', 100], ['XC', 90], ['L', 50], ['XL', 40],
['X', 10], ['IX', 9], ['V', 5], ['IV', 4], ['I', 1]
];
let result = '';
for (const [letter, value] of romanNumerals) {
while (num >= value) {
result += letter;
num -= value;
}
}
return result;
}
beforeParsed(content) {
const sectionContent = content.querySelector('#section__content');
if (!sectionContent) return;
// Compteurs
let h1Count = 0;
let h2Count = 0;
let h3Count = 0;
let h4Count = 0;
let h5Count = 0;
let h6Count = 0;
// Parcourir tous les éléments dans l'ordre du document
const allElements = sectionContent.querySelectorAll('h1, h2, h3, h4, h5, h6');
allElements.forEach(el => {
const tagName = el.tagName.toLowerCase();
switch (tagName) {
case 'h1':
h1Count++;
h2Count = 0; // reset h2
el.setAttribute('data-counter', this.toUpperAlpha(h1Count));
break;
case 'h2':
h2Count++;
h3Count = 0; // reset h3
el.setAttribute('data-counter', this.toUpperRoman(h2Count));
break;
case 'h3':
h3Count++;
h4Count = 0; // reset h4
el.setAttribute('data-counter', h3Count.toString());
break;
case 'h4':
h4Count++;
h5Count = 0; // reset h5
el.setAttribute('data-counter', this.toLowerAlpha(h4Count));
break;
case 'h5':
h5Count++;
h6Count = 0; // reset h6
const letter = this.toLowerAlpha(h5Count);
el.setAttribute('data-counter', letter + letter);
break;
case 'h6':
h6Count++;
el.setAttribute('data-counter', '(' + h6Count + ')');
break;
}
});
}
}

View file

@ -1,21 +0,0 @@
import { Handler } from '/csspageweaver/lib/paged.esm.js';
export default class myCustomHandler1 extends Handler {
constructor(chunker, polisher, caller) {
super(chunker, polisher, caller);
}
beforeParsed(content){
// let h2 = content.querySelectorAll('h2');
// h2.forEach( h2 => {
// h2.insertAdjacentHTML("afterbegin", '🍄');
// });
}
afterParsed(parsed) {
console.info("%c [CSS Page Weaver] Example custom handler 1 with afterParsed hook (see js/custom-handler-example-1.js", 'color: green;');
}
}

View file

@ -1,16 +0,0 @@
import { Handler } from '/csspageweaver/lib/paged.esm.js';
export default class myCustomHandler2 extends Handler {
constructor(chunker, polisher, caller) {
super(chunker, polisher, caller);
}
afterPageLayout(pageElement, page, breakToken) {
if(pageElement.id == "page-1"){
console.info("%c [CSS Page Weaver] Example custom handler 2 with afterPageLayout hook (see js/custom-handler-example-2.js", 'color: green;')
}
}
}