From: Lady Date: Fri, 28 Jul 2023 08:17:05 +0000 (-0700) Subject: Let `@as` indicate the element to use for emphasis X-Git-Tag: 0.1.2~2 X-Git-Url: https://git.ladys.computer/GitWikiWeb/commitdiff_plain/409dc650c60a1b5a5a6dbe67714d4daaa42d7cec Let `@as` indicate the element to use for emphasis --- diff --git a/build.js b/build.js index 5c8bd39..0544a03 100644 --- 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``, + ]; + } 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(