feat(nav-item): add raw-body to pass an already-rendered body through - #2127
Merged
Conversation
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.
✅ Deploy Preview for gethinode-demo ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Collaborator
Author
|
🎉 This PR is included in version 3.21.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
assets/nav-item.htmlresolves a pane body with$args.body | $args.page.RenderString. That is correct for prose or image bodies, but it destroys a body that is already HTML.A
nav-itemwhose body is a single nested shortcode reachesRenderStringindistinguishable from raw HTML typed directly into markdown. On a site running goldmark withrenderer.unsafe = false— which is Hinode's own default, and whatexampleSiteuses — CommonMark then comments the block out and renders the indented remainder as an escaped code block.The partial already exposes a
rawfield that bypassesRenderStringentirely (assets/nav-item.html:75,87), but nothing wires it from the shortcode call and no caller in the module sets it, so the field is unreachable from markdown.Change
Adds an opt-in
raw-bodyboolean to thenav-itemshortcode. When set, the already-resolved body is passed straight through as the partial'sraw.It is a separate argument rather than exposing
rawitself, because the two carry different things:rawtakes the resolved HTML, which cannot sensibly be supplied from a shortcode attribute, whileraw-bodyis the flag that says "my body is already HTML". Overloading one name across the shortcode/partial boundary would put two types behind it.Declared
type: bool,default: false,group: shortcode, soInitArgsresolves it without the| defaultclobber that would break an explicitfalse.Backward compatibility
Defaults to
false, so every existing call site is unaffected: the empty string it then passes leavesor $args.raw (...)on the originalRenderStringpath. Both the tab-pane and accordion call sites are wired.Verification
Built
exampleSite(which runsrenderer.unsafe = false) with three panes:Just <strong>markdown</strong> prose— existing path unchangedraw-body<!-- raw HTML omitted -->plus an escaped<pre><code>block — the bugraw-body=true<div class="d-flex alert alert-info" role="alert">— renders correctlynpm testpasses (lint + template tests).Note for anyone reproducing locally: a stale
_vendorwill failtest:templateswith unrelatedsection-titleschema errors —pnpm mod:vendorfixes it (mine was pinned at mod-utils v6.8.3 against a v6.9.0 requirement).Downstream
Found on a downstream site that renders a tabbed component whose panes each hold a single nested shortcode. It currently carries a full-file fork of this shortcode as an interim workaround; the fork is deleted once this ships.