From 4510a44b7827dc4a4d01ab44e68787ee40265d7a Mon Sep 17 00:00:00 2001 From: Mark Dumay <61946753+markdumay@users.noreply.github.com> Date: Fri, 7 Aug 2026 12:51:50 +0200 Subject: [PATCH] feat(nav-item): add raw-body to pass an already-rendered body through MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit assets/nav-item.html resolves a pane body with `body | page.RenderString`, which is correct for prose but destroys a body that is already HTML. A nav-item whose body is a nested shortcode reaches RenderString indistinguishable from raw HTML typed into markdown, so a site running goldmark with renderer.unsafe = false escapes or drops it — the pane shows a stray comment and an escaped code block instead of the component. The partial already accepts a `raw` field that bypasses RenderString, but nothing wired it from the shortcode, leaving the field unreachable from markdown. raw-body opts into it. It is a separate argument rather than exposing `raw` itself because the two carry different things: `raw` takes resolved HTML, which cannot be supplied from a shortcode attribute, while raw-body is the flag saying the body is already HTML. Defaults to false, so every existing call site is unaffected: the empty string it then passes leaves `or .raw (...)` on the original path. --- data/structures/nav-item.yml | 12 ++++++++++++ layouts/_shortcodes/nav-item.html | 11 +++++++++++ 2 files changed, 23 insertions(+) diff --git a/data/structures/nav-item.yml b/data/structures/nav-item.yml index 8b4de9cd1..cfa3f25b6 100644 --- a/data/structures/nav-item.yml +++ b/data/structures/nav-item.yml @@ -27,6 +27,18 @@ arguments: raw: group: partial release: v1.3.0 + raw-body: + type: bool + default: false + optional: true + group: shortcode + release: v3.21.0 + comment: >- + Flag to pass the item's body through as already-rendered HTML instead of + running it through the page's markdown renderer. Set this when the body + is a nested shortcode that emits HTML of its own: on a site configured + with `markup.goldmark.renderer.unsafe = false`, that markup is otherwise + treated as raw HTML typed into markdown and is escaped or dropped. navitem-type: release: v1.0.0 illustration: diff --git a/layouts/_shortcodes/nav-item.html b/layouts/_shortcodes/nav-item.html index 3b1a8b0e9..6f5d3a27b 100644 --- a/layouts/_shortcodes/nav-item.html +++ b/layouts/_shortcodes/nav-item.html @@ -39,6 +39,15 @@ {{- $itemID := printf "%s-btn-%d" $parent $id }} {{- $disabledID := cond $args.disabled $itemID "" }} {{- $body := trim .Inner " \r\n" -}} + {{/* + assets/nav-item.html resolves a pane body with `$args.body | $args.page.RenderString`, + which is right for prose but destroys a body that is already HTML — a nested shortcode's + output reaches RenderString indistinguishable from raw HTML typed into markdown, and a + site running goldmark with renderer.unsafe = false then escapes or drops it. The partial + already accepts a `raw` field that bypasses RenderString; raw-body wires it from the + shortcode. Empty when unset, so `or $args.raw (...)` keeps the original path. + */}} + {{- $raw := cond $args.rawBody $body "" -}} {{- $current := "" -}} {{/* Main code */}} @@ -50,6 +59,7 @@ "title" $title "class" $args.class "body" $body + "raw" $raw "show" $args.show "disabled" $args.disabled "_default" $args.default @@ -84,6 +94,7 @@ "title" $title "class" $args.class "body" $body + "raw" $raw "show" $args.show "disabled" $args.disabled "navitem-type" "accordion"