Skip to content

fix(shortcodes): size the file fence to the file it wraps - #2148

Merged
markdumay merged 1 commit into
mainfrom
fix/2147-file-shortcode-fence-length
Aug 30, 2026
Merged

fix(shortcodes): size the file fence to the file it wraps#2148
markdumay merged 1 commit into
mainfrom
fix/2147-file-shortcode-fence-length

Conversation

@markdumay

Copy link
Copy Markdown
Collaborator

Summary

Fixes #2147.

The markdown variant of the file shortcode always opened a three-backtick fence:

{{- printf "```%s\n%s\n```" $lang (trim $content "\r\n") -}}

CommonMark ends a fenced block at the first closing run at least as long as the opening one. So when the file being embedded contains its own ```-fenced example, the emitted block closes partway through the file: the remainder is read as prose, and any later fence in the file re-opens and swallows what follows it.

This only affects the .md output — the HTML variant renders such a file correctly, so the two outputs disagree and only the markdown one is wrong.

Reproduce

A page with {{< file file="./skeleton.md" lang="markdown" >}} where skeleton.md is a documentation template that itself contains a ```text example. In the generated markdown the outer block ends at the inner example's closing fence rather than at the end of the file.

Fence structure before, for one such page:

  43  ```markdown     <- opens
 124  ```text
 131  ```             <- closes here (wrong)
 176  ```             <- re-opens

after:

  43  ````markdown    <- opens
 124  ```text
 131  ```             <- now just content
 176  ````            <- closes here (correct)

Approach

Scan the content for its longest fence run and open with one backtick more. A file with no fences is unaffected and still gets three.

Note

There is a second, independent bug behind the same symptom: mod-llm's safe-content.html matches fenced blocks with a single ```+ pattern, so a nested fence also ends its protected region early and the exposed tail is stripped from the output. Verified that fixing this shortcode alone does not resolve that — gethinode/mod-llm#147 covers it.

The markdown variant of the file shortcode always opened a three-backtick
fence. CommonMark ends a fenced block at the first closing run at least as
long as the opening one, so a file that itself contains a ```-fenced
example closed the block partway through: the remainder of the file was
emitted as prose, and any later fence re-opened and swallowed what
followed.

Scan the content for its longest fence run and open with one longer.

Closes #2147
@netlify

netlify Bot commented Aug 30, 2026

Copy link
Copy Markdown

Deploy Preview for gethinode-demo ready!

Name Link
🔨 Latest commit 9a56721
🔍 Latest deploy log https://app.netlify.com/projects/gethinode-demo/deploys/6a93ca1b01a1690008c3a513
😎 Deploy Preview https://deploy-preview-2148--gethinode-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@markdumay
markdumay merged commit 79f1ca0 into main Aug 30, 2026
17 checks passed
@markdumay

Copy link
Copy Markdown
Collaborator Author

🎉 This PR is included in version 3.23.5 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mod-llm safe-content: nested fences break code-block protection, deleting lines from the markdown output

1 participant