]> Lady’s Gitweb - GitWikiWeb/commitdiff
Let `@as` indicate the element to use for emphasis
authorLady <redacted>
Fri, 28 Jul 2023 08:17:05 +0000 (01:17 -0700)
committerLady <redacted>
Fri, 28 Jul 2023 08:37:46 +0000 (01:37 -0700)
build.js

index 5c8bd39c54f317780bcab94f79a2f4f0f56d45c1..0544a03217e4407eb18863058ac0486933f7cb8f 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",
@@ -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) {
@@ -765,7 +790,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"
@@ -808,8 +833,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.028033 seconds and 4 git commands to generate.