fix(md)!: change behavior of regions in snippets - #5014
Open
its-miroma wants to merge 11 commits into
Open
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as outdated.
This comment was marked as outdated.
commit: |
Contributor
Author
|
I hope this PR can get some reviews. I'd also want to make the following breaking changes, but possibly for another PR:
|
its-miroma
force-pushed
the
regions
branch
2 times, most recently
from
December 22, 2025 21:05
0e2e16a to
c19b76a
Compare
its-miroma
force-pushed
the
regions
branch
2 times, most recently
from
January 27, 2026 14:01
317f38b to
2d0695b
Compare
brc-dd
self-requested a review
January 31, 2026 18:16
its-miroma
commented
Feb 12, 2026
its-miroma
added a commit
to its-miroma/fmc
that referenced
this pull request
Mar 16, 2026
its-miroma
added a commit
to its-miroma/fmc
that referenced
this pull request
Mar 16, 2026
its-miroma
added a commit
to its-miroma/fmc
that referenced
this pull request
Mar 16, 2026
its-miroma
added a commit
to its-miroma/fmc
that referenced
this pull request
Mar 16, 2026
its-miroma
added a commit
to its-miroma/fmc
that referenced
this pull request
Mar 22, 2026
its-miroma
added a commit
to its-miroma/fmc
that referenced
this pull request
Mar 22, 2026
its-miroma
added a commit
to its-miroma/fmc
that referenced
this pull request
Mar 22, 2026
its-miroma
added a commit
to its-miroma/fmc
that referenced
this pull request
Mar 22, 2026
its-miroma
added a commit
to its-miroma/fmc
that referenced
this pull request
Mar 22, 2026
its-miroma
added a commit
to its-miroma/fmc
that referenced
this pull request
Mar 23, 2026
* 'migration' (early part): apply some manual fixes the migration script drop mention of transclusions fix: transclusions from FabricMC#415 feat: apply vuejs/vitepress#5014 chore: set minimumReleaseAge to 3 days chore: migrate to pnpm
its-miroma
added a commit
to its-miroma/fmc
that referenced
this pull request
Mar 24, 2026
its-miroma
added a commit
to FabricMC/fabric-docs
that referenced
this pull request
Mar 25, 2026
* chore: migrate to pnpm * chore: set minimumReleaseAge to 3 days * feat: apply vuejs/vitepress#5014 * fix: transclusions from #415
brc-dd
force-pushed
the
main
branch
3 times, most recently
from
March 26, 2026 04:26
15a0278 to
09af6c7
Compare
its-miroma
commented
Mar 29, 2026
| * Remove all #region markers when including snippets | ||
| * @default false | ||
| */ | ||
| stripMarkersFromSnippets?: boolean |
Contributor
Author
There was a problem hiding this comment.
Maybe I should add a configurable mutateSnippet(regions: string[], context: ...) function, that will be run for every snippet. Some use cases:
- Stripping imports from all snippets
- Replacing comments with translated versions
- Adding
// :::at region cuts - Adding a comment at the top with the full file path
This comment was marked as resolved.
This comment was marked as resolved.
its-miroma
force-pushed
the
regions
branch
5 times, most recently
from
July 25, 2026 12:53
a04f385 to
5082cdc
Compare
VitePress supports including a part of a file through a VS Code region. However, when multiple regions have the same name, only one is included. The workaround plugin suggested in vuejs#3690 is no longer maintained. [^1] Furthermore, it suffers from a memory leak causing huge RAM usage. [^2] While we at Fabric Docs have forked the plugin [^3] to fix some issues, it still feels fragile. Another problem is having to use two different syntaxes (`<<<` vs `@[]()`) for doing the same thing, causing confusion. Since this feature has been requested by VitePress directly, I don't think there's any point in working on the plugin any further. fix vuejs#3690 [^1]: <fabioaanthony/markdown-it-vuepress-code-snippet-enhanced#7> [^2]: <https://discord.com/channels/507304429255393322/1208846408552030238/1407245292482330695> via <https://discord.fabricmc.net/> [^3]: <https://github.com/IMB11/md-it-enhanced-snippets>
when a region is not in the source file, instead of including the whole file, warn that the #region was not found in it. fix vuejs#4625
if `stripMarkersFromSnippets` is set, `<<<`
snippets will strip out all region markers:
```file.ts
// #region A
// #region B
console.log("Hello, World!");
// #endregion
// #endregion
```
<<< file.ts#A
...would not include "#region B" anymore
- require # before region, just like vscode - do not accept `# #region`, just like vscode - support case-insensitive REM comment - require space after REM
in `.gitignore`, `gitignore` is now detected as the extension
change signature of dedent too, to avoid splitting and joining
with this refactor, findRegions now iterates over each line only once, and checks all markers to find the first satisfied. For example, #a on: ```ts // #region a const a = 1 /* #region a */ const b = 2 // #endregion a const c = 3 /* #endregion a */ ``` ...which would previously be rendered (assuming stripMarkers): ```ts const a = 1 const b = 2 const b = 2 const c = 3 ``` ...is now correctly rendered: ```ts const a = 1 const b = 2 const c = 3 ``` BREAKING CHANGE: previously, the code stripped matching nested comments, even when stripMarkersFromSnippets was false. For example, #a on: ```ts // #region a const a = 1 // #region a const b = 2 // #endregion a const c = 3 // #region b const d = 4 // #endregion b const e = 5 // #endregion a ``` ...which would previously be rendered (assuming !stripMarkers): ```ts const a = 1 const b = 2 const c = 3 // #region b const d = 4 // #endregion b const e = 5 ``` ...is now rendered: ```ts const a = 1 // #region a const b = 2 // #endregion a const c = 3 // #region b const d = 4 // #endregion b const e = 5 ```
previously, the frontmatter was not stripped prior to finding regions in
processIncludes. if a region was found in the frontmatter, the included
snippet would break in rendering.
For example, #a on:
```md
---
#region a
# this comment becomes a heading
#endregion a
---
Hello, World!
<!-- #region a -->
Some content
<!-- #endregion a -->
```
...which would previously be rendered:
```md
# this comment becomes a heading
Some content
```
...is now rendered as:
```md
Some content
```
other improvements:
- split and join `content` into `lines` only once
- place # outside capturing group in regionRE, to avoid a slice(1)
- call matter() only once, at the beginning. see comment in source
- avoid `as any` cast by using Infinity instead of undefined as end
- anchor #region at $ - ranges on regions still work: #region{1,3}
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.
Description
Rationale
VitePress supports including a part of a file through a VS Code region. However, when multiple regions have the same name, only one is included.
The workaround plugin suggested in #3690 is no longer maintained. 1 Furthermore, it suffers from a memory leak causing huge RAM usage. 2
While we at Fabric Docs have forked the plugin 3 to fix some issues, it still feels fragile.
Another problem is having to use two different syntaxes (
<<<vs@[]()) for doing the same thing, causing confusion.Since this feature has been requested by VitePress directly, I don't think there's any point in working on the plugin any further.
Linked Issues
fix #3690
fix #4625
Additional Context
Footnotes
https://github.com/fabioaanthony/markdown-it-vuepress-code-snippet-enhanced/issues/7 ↩
https://discord.com/channels/507304429255393322/1208846408552030238/1407245292482330695 via https://discord.fabricmc.net/ ↩
https://github.com/IMB11/md-it-enhanced-snippets ↩