]> Lady’s Gitweb - GitWikiWeb/commitdiff
Render footnotes inside of doc content 0.2.2
authorLady <redacted>
Sat, 29 Jul 2023 07:23:54 +0000 (00:23 -0700)
committerLady <redacted>
Sat, 29 Jul 2023 07:32:29 +0000 (00:32 -0700)
- 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.

build.js

index b69e9861eeb021d2ca967a78c433ab364e2a0354..3d3a862c3f09af3e5ddc72dc9a89934a4c5263c2 100644 (file)
--- a/build.js
+++ b/build.js
@@ -235,7 +235,6 @@ class GitWikiWebPage {
             const links_section = [];
             if (internalLinks.size || externalLinks.size) {
               links_section.push(
-                rawBlock`<footer>`,
                 rawBlock`<nav id="links">`,
                 {
                   tag: "heading",
@@ -294,12 +293,16 @@ class GitWikiWebPage {
               }
               links_section.push(
                 rawBlock`</nav>`,
-                rawBlock`</footer>`,
               );
             } else {
               /* do nothing */
             }
-            e.children.push(...links_section);
+            e.children.push(
+              rawBlock`<footer>`,
+              rawBlock`${"\uFFFF"}`, // footnote placeholder
+              ...links_section,
+              rawBlock`</footer>`,
+            );
           },
         },
         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 <gitwikiweb-content> element.",
         );
       } else {
-        for (const node of result) {
+        for (const node of [...result]) {
           domutils.prepend(contentElement, node);
         }
         domutils.removeElement(contentElement);
This page took 0.025122 seconds and 4 git commands to generate.