]> Lady’s Gitweb - GitWikiWeb/blobdiff - build.js
Add symbol substitutions
[GitWikiWeb] / build.js
index 4ed0c10bf971a91cbffb0f20c4ddfb1884dd751c..b0df7c074b89343d93fb26373ea6cf2cbfcef966 100644 (file)
--- a/build.js
+++ b/build.js
@@ -53,6 +53,8 @@ const READ_ONLY = {
   writable: false,
 };
 
+const NIL = Object.preventExtensions(Object.create(null));
+
 const rawBlock = (strings, ...substitutions) => ({
   tag: "raw_block",
   format: "html",
@@ -238,7 +240,7 @@ class GitWikiWebPage {
               );
               if (internalLinks.size) {
                 links_section.push(
-                  rawBlock`<details>`,
+                  rawBlock`<details open="">`,
                   rawBlock`<summary>on this wiki</summary>`,
                   listOfInternalLinks(internalLinks),
                   rawBlock`</details>`,
@@ -248,7 +250,7 @@ class GitWikiWebPage {
               }
               if (externalLinks.size) {
                 links_section.push(
-                  rawBlock`<details>`,
+                  rawBlock`<details open="">`,
                   rawBlock`<summary>elsewhere on the Web</summary>`,
                   {
                     tag: "bullet_list",
@@ -295,6 +297,29 @@ class GitWikiWebPage {
             e.children.push(...links_section);
           },
         },
+        emph: {
+          enter: (_) => {},
+          exit: (e) => {
+            const attributes = e.attributes ?? NIL;
+            const { as } = attributes;
+            if (as) {
+              delete attributes.as;
+              if (
+                as == "b" || as == "cite" || as == "i" || as == "u"
+              ) {
+                return [
+                  rawInline`<${as}>`,
+                  ...e.children,
+                  rawInline`</${as}>`,
+                ];
+              } else {
+                /* do nothing */
+              }
+            } else {
+              /* do nothing */
+            }
+          },
+        },
         hard_break: {
           enter: (_) => {
             if (titleSoFar != null) {
@@ -446,6 +471,35 @@ class GitWikiWebPage {
           },
           exit: (_) => {},
         },
+        symb: {
+          enter: (e) => {
+            const { alias } = e;
+            const codepoint = /^U\+([0-9A-Fa-f]+)$/u.exec(alias)?.[1];
+            if (codepoint) {
+              return str`${
+                String.fromCodePoint(parseInt(codepoint, 16))
+              }`;
+            } else {
+              return {
+                "--8": str`${"—\u2060:\u202F"}`, // reverse puppyprick
+                "8--": str`${"\u202F:\u2060—"}`, // forward puppyprick
+                sp: rawInline` `, // space
+                nbsp: str`${"\xA0"}`, // no‐break space
+                cgj: str`${"\u034F"}`, // combining grapheme joiner
+                ensp: str`${"\u2002"}`, // enspace
+                emsp: str`${"\u2003"}`, // emspace
+                figsp: str`${"\u2007"}`, // figure space
+                zwsp: str`${"\u200B"}`, // zero‐width space
+                zwnj: str`${"\u200C"}`, // zero‐width nonjoiner
+                zwj: str`${"\u200D"}`, // zero‐width joiner
+                nnbsp: str`${"\u202F"}`, // narrow no‐break space
+                mathsp: str`${"\u205F"}`, // math space
+                wj: str`${"\u2060"}`, // word joiner
+                fwsp: str`${"\u3000"}`, // fullwidth space
+              }[alias] ?? e;
+            }
+          },
+        },
       };
     });
     Object.defineProperties(this, {
@@ -707,14 +761,16 @@ class GitWikiWebPage {
                             refs,
                           } = result;
                           yield* listOfInternalLinks(refs, (link) => ({
-                            tag: index ? "strong" : "span",
+                            tag: index == 0 ? "span" : "strong",
                             attributes: { "data-recency": `${index}` },
                             children: [
                               link,
-                              str` `,
-                              rawInline`<small>(<time dateTime="${dateTime}">`,
-                              str`${humanReadable}`,
-                              rawInline`</time>)</small>`,
+                              ...(index == 0 ? [] : [
+                                str` `,
+                                rawInline`<small>(<time dateTime="${dateTime}">`,
+                                str`${humanReadable}`,
+                                rawInline`</time>)</small>`,
+                              ]),
                             ],
                           })).children;
                         } else {
@@ -763,7 +819,7 @@ class GitWikiWebPage {
           },
           heading: {
             enter: (e) => {
-              const attributes = e.attributes ?? Object.create(null);
+              const attributes = e.attributes ?? NIL;
               if (
                 isNavigationPage && e.level == 1 &&
                 attributes?.class == "main"
@@ -806,8 +862,7 @@ class GitWikiWebPage {
                 }
                 if (children.length == 0) {
                   const section =
-                    pages.get(reference)?.sections?.main ??
-                      Object.create(null);
+                    pages.get(reference)?.sections?.main ?? NIL;
                   const { v } = attributes;
                   if (v == null) {
                     children.push(
This page took 0.100795 seconds and 4 git commands to generate.