From: Lady Date: Sat, 29 Jul 2023 07:23:54 +0000 (-0700) Subject: Render footnotes inside of doc content X-Git-Tag: 0.2.2 X-Git-Url: https://git.ladys.computer/GitWikiWeb/commitdiff_plain/0c65336dbe28121e7973aac6f7c68e499eb29a0a?hp=ee8812741aa9018537b39ce40ffca964e2703950 Render footnotes inside of doc content - Fixes adding nodes to document by cloning the array. - Adds a `raw_block` sigil to the document and then overrides rendering to insert the footnotes at that point in time. --- diff --git a/build.js b/build.js index b69e986..3d3a862 100644 --- a/build.js +++ b/build.js @@ -235,7 +235,6 @@ class GitWikiWebPage { const links_section = []; if (internalLinks.size || externalLinks.size) { links_section.push( - rawBlock``, ); } else { /* do nothing */ } - e.children.push(...links_section); + e.children.push( + rawBlock``, + ); }, }, hard_break: { @@ -923,7 +926,23 @@ class GitWikiWebPage { }); const renderedAST = djot.renderAST(ast); const doc = getDOM(template); - const result = getDOM(`${djot.renderHTML(ast)}`); + const result = getDOM(djot.renderHTML(ast, { + overrides: { + raw_block: (node, context) => { + if (node.format == "html" && node.text == "\uFFFF") { + if (context.nextFootnoteIndex > 1) { + const result = context.renderNotes(ast.footnotes); + context.nextFootnoteIndex = 1; + return result; + } else { + return ""; + } + } else { + return context.renderAstNodeDefault(node); + } + }, + }, + })); const headElement = domutils.findOne( (node) => node.name == "head", doc, @@ -963,7 +982,7 @@ class GitWikiWebPage { "GitWikiWeb: Template did not include a element.", ); } else { - for (const node of result) { + for (const node of [...result]) { domutils.prepend(contentElement, node); } domutils.removeElement(contentElement);