UNPKG

@codedoc/core

Version:

Create beautiful modern documentation websites.

44 lines 2.12 kB
import { funcTransport, onReady } from '@connectv/sdh/transport'; import { getRenderer } from '../../transport/renderer'; export function gatherFootnotes() { const renderer = getRenderer(); onReady(() => { const _exec = () => { let counter = 1; let collected = []; const countermap = {}; document.querySelectorAll('[data-footnote], [data-footnotes]').forEach(child => { if (child.hasAttribute('data-footnote')) { const id = `--codedoc-footnote-${child.getAttribute('data-footnote-id') || counter}`; const index = (id in countermap) ? countermap[id] : (countermap[id] = counter++); if (child.childNodes.length > 0) { child.setAttribute('id', id); child.setAttribute('data-footnote-index', `${index}`); collected.push({ index, $: child }); } if (!child.hasAttribute('data-footnote-block')) { renderer.render(renderer.create("sup", null, renderer.create("a", { href: `#${id}`, style: "text-decoration: none" }, renderer.create("b", null, index)))).before(child); } child.remove(); } else { collected.sort((a, b) => a.index - b.index).forEach(_ => { renderer.render(renderer.create("div", null, renderer.create("span", null, renderer.create("a", null, renderer.create("b", null, _.index))), " ", _.$)).on(child); }); collected = []; } }); }; _exec(); window.addEventListener('navigation', _exec); }); } export const gatherFootnotes$ = /*#__PURE__*/ funcTransport(gatherFootnotes); //# sourceMappingURL=gather-footnotes.js.map