fix(shortcodes): size the file fence to the file it wraps - #2148
Merged
Conversation
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
✅ 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.23.5 🎉 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.
Summary
Fixes #2147.
The markdown variant of the
fileshortcode 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 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
.mdoutput — 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" >}}whereskeleton.mdis a documentation template that itself contains a```textexample. 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:
after:
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'ssafe-content.htmlmatches 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.