diff --git a/data/structures/nav-item.yml b/data/structures/nav-item.yml index 8b4de9cd..cfa3f25b 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 3b1a8b0e..6f5d3a27 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"