From: Lady Date: Sat, 29 Jul 2023 00:18:15 +0000 (-0700) Subject: Support arbitrary use of @as X-Git-Tag: 0.2.1 X-Git-Url: https://git.ladys.computer/GitWikiWeb/commitdiff_plain/99d9cd95ce439e0c0364a8d27969b561cdffb3b4 Support arbitrary use of @as --- diff --git a/build.js b/build.js index ca07283..b50fe3d 100644 --- a/build.js +++ b/build.js @@ -302,29 +302,6 @@ 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) { @@ -513,6 +490,38 @@ class GitWikiWebPage { } } +{ + // Patches for Djot HTML renderer. + const { HTMLRenderer: { prototype: htmlRendererPrototype } } = djot; + const { inTags: upstreamInTags } = htmlRendererPrototype; + htmlRendererPrototype.inTags = function ( + tag, + node, + newlines, + extraAttrs = undefined, + ) { + const attributes = node.attributes ?? NIL; + if ("as" in attributes) { + const newTag = attributes.as; + delete attributes.as; + return upstreamInTags.call( + this, + newTag, + node, + newlines, + extraAttrs, + ); + } else { + return upstreamInTags.call( + this, + tag, + node, + newlines, + extraAttrs, + ); + } + }; +} { const config = await getRemoteContent("config.yaml").then((yaml) => parseYaml(yaml, { schema: JSON_SCHEMA })