diff --git a/public/csspageweaver/plugins/footnotesFix/.gitignore b/public/csspageweaver/plugins/footnotesFix/.gitignore deleted file mode 100644 index 496ee2c..0000000 --- a/public/csspageweaver/plugins/footnotesFix/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.DS_Store \ No newline at end of file diff --git a/public/csspageweaver/plugins/footnotesFix/README.md b/public/csspageweaver/plugins/footnotesFix/README.md deleted file mode 100644 index b6d9540..0000000 --- a/public/csspageweaver/plugins/footnotesFix/README.md +++ /dev/null @@ -1,95 +0,0 @@ -# Plugin to fix footnotes reset issue - -This plugin fix the issue of footnote reset. - -You can use the current method to declare footnotes: - -```CSS -@page { - @footnote { - float: bottom; - } - } - -.pagedjs_footnote { - float: footnote; -} -``` - -This style is also added to the default stylesheet `footnotes.css` of this plugin. You can delete it if you have already declared footnotes in your own stylesheet (don't forget to remove it from the `config.json` as well). - - -## How to use the plugin - -Add this folder to `csspageweaver/plugins/`. - -Call the plugin in `csspageweaver/manifest.json`: - -```json - "plugins": [ - "footnotesFix", - // other plugins ... - ], -``` - -## Configuration - -In `manifest.json`, you can modify/add some parameters: - -```json - "plugins":{ - "footnotesFix" - }, - "pluginsParameters":{ - "footnotesFix": { - "selector": ".footnote", - "reset": ".chapter" - } - }, -``` - -All the parameters are optional. - -- `selector` → CSS selector for the note element (must be inline in the HTML), by default is `.footnote` -- `reset` → CSS selector where you want reset note counter. If you want to reset on the page: `page` - - -## Notes in HTML - -In your HTML, the note must be a `` inserted in the text, like this: - -```HTML -Donec tincidunt, odio vel vestibulum sollicitudin, nibh dolor tempor sapien, ac laoreet -sem felis ut purus. Vestibulum neque ex, ullamcorper sit -amet diam sed, pharetra laoreet sem. Morbi cursus bibendum consectetur. Nullam vel -lacus congue nibh pulvinar maximus sit amet eu risus. Curabitur semper odio mauris, nec -imperdiet velit pharetra non. Aenean accumsan nulla ac ex iaculis interdum. -``` - -You can use the [inline_notes` plugin](https://gitlab.com/csspageweaver/plugins/inline_notes) to create these span elements from listed notes, which are more common in conversion tools like Pandoc. - -The inline_notes plugin should be called before the footnotes plugin in the `manifest.json`: - - -```json - "plugins": [ - "inline_notes", - "footnotes_fix", - // other plugins ... - ], -``` - -## Styling call & footer - -It's possible to change the styles of call notes and marker notes directly in your stylesheet like in the following code: - -```CSS -::footnote-call{ - font-weight: bold; -} - -::footnote-marker{ - font-weight: bold; -} -``` - diff --git a/public/csspageweaver/plugins/footnotesFix/config.json b/public/csspageweaver/plugins/footnotesFix/config.json deleted file mode 100644 index b25395b..0000000 --- a/public/csspageweaver/plugins/footnotesFix/config.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "Footnotes", - "description": "Fix footnote reset", - "author": ["Julie Blanc"], - "licence": "MIT", - "version": "1.0", - "hook": "footnotes.js", - "stylesheet": "footnotes.css" -} \ No newline at end of file diff --git a/public/csspageweaver/plugins/footnotesFix/footnotes.css b/public/csspageweaver/plugins/footnotesFix/footnotes.css deleted file mode 100644 index c3a94e4..0000000 --- a/public/csspageweaver/plugins/footnotesFix/footnotes.css +++ /dev/null @@ -1,9 +0,0 @@ -@page { - @footnote { - float: bottom; - } -} - -.footnote { - float: footnote; -} \ No newline at end of file diff --git a/public/csspageweaver/plugins/footnotesFix/footnotes.js b/public/csspageweaver/plugins/footnotesFix/footnotes.js deleted file mode 100644 index 6842b49..0000000 --- a/public/csspageweaver/plugins/footnotesFix/footnotes.js +++ /dev/null @@ -1,85 +0,0 @@ -/** - * @name Footnotes - * @file Reset the way footnote are counted - * @author Julie Blanc - * @see { @link https://gitlab.com/csspageweaver/plugins/footnotesFix/ } - */ - -import { Handler } from '/csspageweaver/lib/paged.esm.js'; - -export default class footnotes extends Handler { - - constructor(chunker, polisher, caller) { - super(chunker, polisher, caller); - this.parameters = cssPageWeaver.features.footnotesFix.parameters; - this.reset = this.parameters?.reset ; - this.counter = 0; - this.selector = this.parameters?.selector || ".footnote"; - } - - beforeParsed(content) { - - - let notes = content.querySelectorAll(this.selector); - notes.forEach(function (note, index) { - note.classList.add("pagedjs_footnote"); - }); - - - - if(this.reset){ - let elems = content.querySelectorAll(this.reset); - elems.forEach(function (elem, index) { - var span = document.createElement('span'); - span.classList.add("reset-fix-footnote"); - span.style.position = "absolute"; - elem.insertBefore(span, elem.firstChild); - }); - }else{ - console.log("[footnotesFix] no reset") - } - - } - - - afterPageLayout(pageElement, page, breakToken){ - - if(this.reset){ - - // reset on pages - if(this.reset === "page"){ - this.counter = 0; - } - - // reset on specific element - let newchapter = pageElement.querySelector('.reset-fix-footnote'); - if(newchapter){ - this.counter = 0; - } - - let footnotes = pageElement.querySelectorAll(".pagedjs_footnote_content [data-note]"); - - let callnotes = pageElement.querySelectorAll('a.pagedjs_footnote'); - callnotes.forEach((call, index) => { - - this.counter = this.counter + 1; // increment - let num = this.counter - 1; - - // update data-counter for call - call.setAttribute('data-counter-footnote-increment', num); - call.style.counterReset = "footnote " + num; - - // update data-counter for marker - let footnote = footnotes[index]; - let dataCounter = num + 1; - footnote.setAttribute('data-counter-note', dataCounter); - footnote.style.counterReset = "footnote-marker " + num; - - - }); - } - } - - - -} \ No newline at end of file diff --git a/public/csspageweaver/plugins/inlineNotes/.gitignore b/public/csspageweaver/plugins/inlineNotes/.gitignore deleted file mode 100644 index 496ee2c..0000000 --- a/public/csspageweaver/plugins/inlineNotes/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.DS_Store \ No newline at end of file diff --git a/public/csspageweaver/plugins/inlineNotes/README.md b/public/csspageweaver/plugins/inlineNotes/README.md deleted file mode 100644 index a838722..0000000 --- a/public/csspageweaver/plugins/inlineNotes/README.md +++ /dev/null @@ -1,77 +0,0 @@ ---- -name: InlineNotes -tags: recommended, stable -description: This script moves listed notes to inline elements at the place of the call. - ---- - -# Inline notes - -To move notes in the correct place in the page, Paged.js needs to have the note element in the flow. But in convert tools like Pandoc, it’s common to have the notes elements presented in a list with link elements in the flow pointing to the correponding note. - -This script moves listed notes to inline elements at the place of the call. - - - -## How to use - -Add this folder in `csspageweaver/plugins/`. - -Call the plugin in `csspageweaver/manifest.json`: - -```json - "plugins": [ - "inlineNotes", - // other plugins ... - ], -``` - -## Config.json - -In `manifest.json`, you can modify/add some parameters: - -``` - "pluginsParameters": { - // parameters of other plugins ... - "inlineNotes": { - "input": ".footnote-ref", - "containerNotes": ".footnotes" - } - }, -``` - -- `input` → CSS selector of the original call element (by default: `.footnote-ref`) -- `containerNotes` → CSS selector of the original container of the footnote list, this container is deleted after moving notes (by default: `#footnotes`) -- `` → Class of the new span created for the note - - -## Exemple - -Before : - -```HTML -

Gutenberg in 1439 was the first European to use movable type. -Among his many contributions to printing are: the invention of -a process for mass-producing movable type; the use of oil-based -ink for printing books; 1 adjustable molds; mechanical movable type; and the use of a wooden printing press similar to the agricultural screw presses of the period.

- - -``` - - -After (wiht the plugin): - -```HTML -

Gutenberg in 1439 was the first European to use movable type. -Among his many contributions to printing are: the invention of -a process for mass-producing movable type; the use of oil-based -ink for printing books; Soap, Sex, and Cigarettes: A Cultural History of American Advertising By Juliann Sivulka, page 5 -adjustable molds; mechanical movable type; and the use -of a wooden printing press similar to the agricultural -screw presses of the period.

-``` diff --git a/public/csspageweaver/plugins/inlineNotes/config.json b/public/csspageweaver/plugins/inlineNotes/config.json deleted file mode 100644 index 25ed0cd..0000000 --- a/public/csspageweaver/plugins/inlineNotes/config.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "Inline notes", - "description": "This script moves listed notes to inline elements at the place of the call", - "author": ["Julie Blanc"], - "license": "MIT License", - "version": "1.0", - "hook": "inlineNotes.js" -} \ No newline at end of file diff --git a/public/csspageweaver/plugins/inlineNotes/inlineNotes.js b/public/csspageweaver/plugins/inlineNotes/inlineNotes.js deleted file mode 100644 index 955476c..0000000 --- a/public/csspageweaver/plugins/inlineNotes/inlineNotes.js +++ /dev/null @@ -1,140 +0,0 @@ -/** - * @name Inline Notes - * @author Julien Bidoret - * @author Julie Blanc - * @see { @link https://gitlab.com/csspageweaver/plugins/inlineNotes } - */ - -import { Handler } from '/csspageweaver/lib/paged.esm.js'; - -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 - } - - beforeParsed(content) { - - // ---- HUGO SPECIFIC // Correction des ids et href 'fn:' en 'fn-' ---- - // 1. Tous les éléments avec un id commençant par "fn:" - content.querySelectorAll('[id^="fn:"]').forEach(el => { - el.id = el.id.replace(/:/g, '-'); - }); - - // 2. Tous les éléments avec un id commençant par "fnref:" - content.querySelectorAll('[id^="fnref:"]').forEach(el => { - el.id = el.id.replace(/:/g, '-'); - }); - - // 3. Tous les éléments avec un href commençant par "#fn:" - content.querySelectorAll('[href^="#fn:"]').forEach(el => { - el.href = el.href.replace(/:/g, '-'); - }); - - // 4. Tous les éléments avec un href commençant par "#fnref:" - content.querySelectorAll('[href^="#fnref:"]').forEach(el => { - el.href = el.href.replace(/:/g, '-'); - }); - - // 5. (optionnel) Tous les 'for' dans labels, si jamais (pas typique) - content.querySelectorAll('[for^="fn:"]').forEach(el => { - el.htmlFor = el.htmlFor.replace(/:/g, '-'); - }); - - - - inlineNotesHandler({ - content: content, - input: this.input, - containerNotes: this.containerNotes, - type: this.newClass - }); - - } -} - - - -function inlineNotesHandler(params){ - - let content = params.content; - let input = params.input; - let type = params.type; - let container = params.containerNotes; - - createNotes(content, input, type, container); - - // let noteContainer = content.querySelector(params.containerNotes); - // if(noteContainer){ - // noteContainer.remove(); - // } - -} - - -function getBlocks(element){ - return element.querySelectorAll('div,p,blockquote,section,article,h1,h2,h3,h4,h5,h6,figure'); -} - -// get only inline-level tags -function unwrapBlockChildren(element) { - let blocks = getBlocks(element); - - blocks.forEach(block => { - block.insertAdjacentHTML("beforebegin", block.innerHTML); - block.remove(); - }); - let remainingblocks = getBlocks(element); - if(remainingblocks.length) unwrapBlockChildren(element); - return element; -} - - -function createNotes(content, input, type, container){ - - let containers = content.querySelectorAll(container); - - containers.forEach(function (container, index) { - let section = container.parentNode; - - let calls = section.querySelectorAll(input); - calls.forEach( (call, index) => { - - let href = call.getAttribute('href'); - let hashIndex = href.indexOf('#'); - let selector = href.slice(hashIndex); - - let note = section.querySelector(selector); - if (!note) { - console.warn('Note non trouvée pour', selector); - return; - } - - let back = note.querySelector(".footnote-back"); - if(back){ - back.remove(); - } - - - - let inline_note = document.createElement('span'); - inline_note.className = type; - let num = index + 1; - inline_note.dataset.counterNote = num; - inline_note.dataset.chapter = section.id; - - inline_note.innerHTML = unwrapBlockChildren(note).innerHTML; - call.after(inline_note); - - call.parentElement.removeChild(call); - - - }) - - container.remove(); - }); - -} diff --git a/static/csspageweaver/plugins/footnotesFix/.gitignore b/static/csspageweaver/plugins/footnotesFix/.gitignore deleted file mode 100644 index 496ee2c..0000000 --- a/static/csspageweaver/plugins/footnotesFix/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.DS_Store \ No newline at end of file diff --git a/static/csspageweaver/plugins/footnotesFix/README.md b/static/csspageweaver/plugins/footnotesFix/README.md deleted file mode 100644 index b6d9540..0000000 --- a/static/csspageweaver/plugins/footnotesFix/README.md +++ /dev/null @@ -1,95 +0,0 @@ -# Plugin to fix footnotes reset issue - -This plugin fix the issue of footnote reset. - -You can use the current method to declare footnotes: - -```CSS -@page { - @footnote { - float: bottom; - } - } - -.pagedjs_footnote { - float: footnote; -} -``` - -This style is also added to the default stylesheet `footnotes.css` of this plugin. You can delete it if you have already declared footnotes in your own stylesheet (don't forget to remove it from the `config.json` as well). - - -## How to use the plugin - -Add this folder to `csspageweaver/plugins/`. - -Call the plugin in `csspageweaver/manifest.json`: - -```json - "plugins": [ - "footnotesFix", - // other plugins ... - ], -``` - -## Configuration - -In `manifest.json`, you can modify/add some parameters: - -```json - "plugins":{ - "footnotesFix" - }, - "pluginsParameters":{ - "footnotesFix": { - "selector": ".footnote", - "reset": ".chapter" - } - }, -``` - -All the parameters are optional. - -- `selector` → CSS selector for the note element (must be inline in the HTML), by default is `.footnote` -- `reset` → CSS selector where you want reset note counter. If you want to reset on the page: `page` - - -## Notes in HTML - -In your HTML, the note must be a `` inserted in the text, like this: - -```HTML -Donec tincidunt, odio vel vestibulum sollicitudin, nibh dolor tempor sapien, ac laoreet -sem felis ut purus. Vestibulum neque ex, ullamcorper sit -amet diam sed, pharetra laoreet sem. Morbi cursus bibendum consectetur. Nullam vel -lacus congue nibh pulvinar maximus sit amet eu risus. Curabitur semper odio mauris, nec -imperdiet velit pharetra non. Aenean accumsan nulla ac ex iaculis interdum. -``` - -You can use the [inline_notes` plugin](https://gitlab.com/csspageweaver/plugins/inline_notes) to create these span elements from listed notes, which are more common in conversion tools like Pandoc. - -The inline_notes plugin should be called before the footnotes plugin in the `manifest.json`: - - -```json - "plugins": [ - "inline_notes", - "footnotes_fix", - // other plugins ... - ], -``` - -## Styling call & footer - -It's possible to change the styles of call notes and marker notes directly in your stylesheet like in the following code: - -```CSS -::footnote-call{ - font-weight: bold; -} - -::footnote-marker{ - font-weight: bold; -} -``` - diff --git a/static/csspageweaver/plugins/footnotesFix/config.json b/static/csspageweaver/plugins/footnotesFix/config.json deleted file mode 100644 index b25395b..0000000 --- a/static/csspageweaver/plugins/footnotesFix/config.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "Footnotes", - "description": "Fix footnote reset", - "author": ["Julie Blanc"], - "licence": "MIT", - "version": "1.0", - "hook": "footnotes.js", - "stylesheet": "footnotes.css" -} \ No newline at end of file diff --git a/static/csspageweaver/plugins/footnotesFix/footnotes.css b/static/csspageweaver/plugins/footnotesFix/footnotes.css deleted file mode 100644 index c3a94e4..0000000 --- a/static/csspageweaver/plugins/footnotesFix/footnotes.css +++ /dev/null @@ -1,9 +0,0 @@ -@page { - @footnote { - float: bottom; - } -} - -.footnote { - float: footnote; -} \ No newline at end of file diff --git a/static/csspageweaver/plugins/footnotesFix/footnotes.js b/static/csspageweaver/plugins/footnotesFix/footnotes.js deleted file mode 100644 index 6842b49..0000000 --- a/static/csspageweaver/plugins/footnotesFix/footnotes.js +++ /dev/null @@ -1,85 +0,0 @@ -/** - * @name Footnotes - * @file Reset the way footnote are counted - * @author Julie Blanc - * @see { @link https://gitlab.com/csspageweaver/plugins/footnotesFix/ } - */ - -import { Handler } from '/csspageweaver/lib/paged.esm.js'; - -export default class footnotes extends Handler { - - constructor(chunker, polisher, caller) { - super(chunker, polisher, caller); - this.parameters = cssPageWeaver.features.footnotesFix.parameters; - this.reset = this.parameters?.reset ; - this.counter = 0; - this.selector = this.parameters?.selector || ".footnote"; - } - - beforeParsed(content) { - - - let notes = content.querySelectorAll(this.selector); - notes.forEach(function (note, index) { - note.classList.add("pagedjs_footnote"); - }); - - - - if(this.reset){ - let elems = content.querySelectorAll(this.reset); - elems.forEach(function (elem, index) { - var span = document.createElement('span'); - span.classList.add("reset-fix-footnote"); - span.style.position = "absolute"; - elem.insertBefore(span, elem.firstChild); - }); - }else{ - console.log("[footnotesFix] no reset") - } - - } - - - afterPageLayout(pageElement, page, breakToken){ - - if(this.reset){ - - // reset on pages - if(this.reset === "page"){ - this.counter = 0; - } - - // reset on specific element - let newchapter = pageElement.querySelector('.reset-fix-footnote'); - if(newchapter){ - this.counter = 0; - } - - let footnotes = pageElement.querySelectorAll(".pagedjs_footnote_content [data-note]"); - - let callnotes = pageElement.querySelectorAll('a.pagedjs_footnote'); - callnotes.forEach((call, index) => { - - this.counter = this.counter + 1; // increment - let num = this.counter - 1; - - // update data-counter for call - call.setAttribute('data-counter-footnote-increment', num); - call.style.counterReset = "footnote " + num; - - // update data-counter for marker - let footnote = footnotes[index]; - let dataCounter = num + 1; - footnote.setAttribute('data-counter-note', dataCounter); - footnote.style.counterReset = "footnote-marker " + num; - - - }); - } - } - - - -} \ No newline at end of file diff --git a/static/csspageweaver/plugins/inlineNotes/.gitignore b/static/csspageweaver/plugins/inlineNotes/.gitignore deleted file mode 100644 index 496ee2c..0000000 --- a/static/csspageweaver/plugins/inlineNotes/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.DS_Store \ No newline at end of file diff --git a/static/csspageweaver/plugins/inlineNotes/README.md b/static/csspageweaver/plugins/inlineNotes/README.md deleted file mode 100644 index a838722..0000000 --- a/static/csspageweaver/plugins/inlineNotes/README.md +++ /dev/null @@ -1,77 +0,0 @@ ---- -name: InlineNotes -tags: recommended, stable -description: This script moves listed notes to inline elements at the place of the call. - ---- - -# Inline notes - -To move notes in the correct place in the page, Paged.js needs to have the note element in the flow. But in convert tools like Pandoc, it’s common to have the notes elements presented in a list with link elements in the flow pointing to the correponding note. - -This script moves listed notes to inline elements at the place of the call. - - - -## How to use - -Add this folder in `csspageweaver/plugins/`. - -Call the plugin in `csspageweaver/manifest.json`: - -```json - "plugins": [ - "inlineNotes", - // other plugins ... - ], -``` - -## Config.json - -In `manifest.json`, you can modify/add some parameters: - -``` - "pluginsParameters": { - // parameters of other plugins ... - "inlineNotes": { - "input": ".footnote-ref", - "containerNotes": ".footnotes" - } - }, -``` - -- `input` → CSS selector of the original call element (by default: `.footnote-ref`) -- `containerNotes` → CSS selector of the original container of the footnote list, this container is deleted after moving notes (by default: `#footnotes`) -- `` → Class of the new span created for the note - - -## Exemple - -Before : - -```HTML -

Gutenberg in 1439 was the first European to use movable type. -Among his many contributions to printing are: the invention of -a process for mass-producing movable type; the use of oil-based -ink for printing books; 1 adjustable molds; mechanical movable type; and the use of a wooden printing press similar to the agricultural screw presses of the period.

- - -``` - - -After (wiht the plugin): - -```HTML -

Gutenberg in 1439 was the first European to use movable type. -Among his many contributions to printing are: the invention of -a process for mass-producing movable type; the use of oil-based -ink for printing books; Soap, Sex, and Cigarettes: A Cultural History of American Advertising By Juliann Sivulka, page 5 -adjustable molds; mechanical movable type; and the use -of a wooden printing press similar to the agricultural -screw presses of the period.

-``` diff --git a/static/csspageweaver/plugins/inlineNotes/config.json b/static/csspageweaver/plugins/inlineNotes/config.json deleted file mode 100644 index 25ed0cd..0000000 --- a/static/csspageweaver/plugins/inlineNotes/config.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "Inline notes", - "description": "This script moves listed notes to inline elements at the place of the call", - "author": ["Julie Blanc"], - "license": "MIT License", - "version": "1.0", - "hook": "inlineNotes.js" -} \ No newline at end of file diff --git a/static/csspageweaver/plugins/inlineNotes/inlineNotes.js b/static/csspageweaver/plugins/inlineNotes/inlineNotes.js deleted file mode 100644 index 955476c..0000000 --- a/static/csspageweaver/plugins/inlineNotes/inlineNotes.js +++ /dev/null @@ -1,140 +0,0 @@ -/** - * @name Inline Notes - * @author Julien Bidoret - * @author Julie Blanc - * @see { @link https://gitlab.com/csspageweaver/plugins/inlineNotes } - */ - -import { Handler } from '/csspageweaver/lib/paged.esm.js'; - -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 - } - - beforeParsed(content) { - - // ---- HUGO SPECIFIC // Correction des ids et href 'fn:' en 'fn-' ---- - // 1. Tous les éléments avec un id commençant par "fn:" - content.querySelectorAll('[id^="fn:"]').forEach(el => { - el.id = el.id.replace(/:/g, '-'); - }); - - // 2. Tous les éléments avec un id commençant par "fnref:" - content.querySelectorAll('[id^="fnref:"]').forEach(el => { - el.id = el.id.replace(/:/g, '-'); - }); - - // 3. Tous les éléments avec un href commençant par "#fn:" - content.querySelectorAll('[href^="#fn:"]').forEach(el => { - el.href = el.href.replace(/:/g, '-'); - }); - - // 4. Tous les éléments avec un href commençant par "#fnref:" - content.querySelectorAll('[href^="#fnref:"]').forEach(el => { - el.href = el.href.replace(/:/g, '-'); - }); - - // 5. (optionnel) Tous les 'for' dans labels, si jamais (pas typique) - content.querySelectorAll('[for^="fn:"]').forEach(el => { - el.htmlFor = el.htmlFor.replace(/:/g, '-'); - }); - - - - inlineNotesHandler({ - content: content, - input: this.input, - containerNotes: this.containerNotes, - type: this.newClass - }); - - } -} - - - -function inlineNotesHandler(params){ - - let content = params.content; - let input = params.input; - let type = params.type; - let container = params.containerNotes; - - createNotes(content, input, type, container); - - // let noteContainer = content.querySelector(params.containerNotes); - // if(noteContainer){ - // noteContainer.remove(); - // } - -} - - -function getBlocks(element){ - return element.querySelectorAll('div,p,blockquote,section,article,h1,h2,h3,h4,h5,h6,figure'); -} - -// get only inline-level tags -function unwrapBlockChildren(element) { - let blocks = getBlocks(element); - - blocks.forEach(block => { - block.insertAdjacentHTML("beforebegin", block.innerHTML); - block.remove(); - }); - let remainingblocks = getBlocks(element); - if(remainingblocks.length) unwrapBlockChildren(element); - return element; -} - - -function createNotes(content, input, type, container){ - - let containers = content.querySelectorAll(container); - - containers.forEach(function (container, index) { - let section = container.parentNode; - - let calls = section.querySelectorAll(input); - calls.forEach( (call, index) => { - - let href = call.getAttribute('href'); - let hashIndex = href.indexOf('#'); - let selector = href.slice(hashIndex); - - let note = section.querySelector(selector); - if (!note) { - console.warn('Note non trouvée pour', selector); - return; - } - - let back = note.querySelector(".footnote-back"); - if(back){ - back.remove(); - } - - - - let inline_note = document.createElement('span'); - inline_note.className = type; - let num = index + 1; - inline_note.dataset.counterNote = num; - inline_note.dataset.chapter = section.id; - - inline_note.innerHTML = unwrapBlockChildren(note).innerHTML; - call.after(inline_note); - - call.parentElement.removeChild(call); - - - }) - - container.remove(); - }); - -}