From: Lady Date: Sat, 29 Jul 2023 00:18:15 +0000 (-0700) Subject: Support arbitrary use of @as X-Git-Tag: 0.2.1^0 X-Git-Url: https://git.ladys.computer/GitWikiWeb/commitdiff_plain/ec82c7286badf5d109dec2a0f6bc71b3d4e3ef64?ds=inline 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 })