Skip to content

fix(md)!: change behavior of regions in snippets#5014

Open
its-miroma wants to merge 4 commits intovuejs:mainfrom
its-miroma:regions
Open

fix(md)!: change behavior of regions in snippets#5014
its-miroma wants to merge 4 commits intovuejs:mainfrom
its-miroma:regions

Conversation

@its-miroma
Copy link
Copy Markdown
Contributor

@its-miroma its-miroma commented Nov 3, 2025

Description

  • include all regions with the same name, not just the first one
  • when a file does not contain the region, don't include it entirely, rather warn that the region was not found
  • add option to strip all #region comments from the included snippet
  • support pure JSON files, by allowing regions to be declared in the keys

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

  1. https://github.com/fabioaanthony/markdown-it-vuepress-code-snippet-enhanced/issues/7

  2. https://discord.com/channels/507304429255393322/1208846408552030238/1407245292482330695 via https://discord.fabricmc.net/

  3. https://github.com/IMB11/md-it-enhanced-snippets

@its-miroma

This comment was marked as resolved.

@its-miroma

This comment was marked as outdated.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Nov 6, 2025

npm i https://pkg.pr.new/vitepress@5014

commit: 46fdcf5

@its-miroma its-miroma changed the title feat(markdown): include all regions with same name feat(md)!: include all regions with same name Dec 21, 2025
@its-miroma its-miroma changed the title feat(md)!: include all regions with same name fix(md)!: include all regions with same name Dec 21, 2025
@its-miroma its-miroma changed the title fix(md)!: include all regions with same name fix(md)!: change behavior of regions in snippets Dec 21, 2025
@its-miroma
Copy link
Copy Markdown
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:

  • deprecate @include, replaced with <<< which would not create a code block for Markdown files
  • to import a Markdown file in a code block, put <<< in a code block
  • somehow add support for multiple line ranges in the <<< syntax, without conflicting with highlighting

@its-miroma its-miroma force-pushed the regions branch 2 times, most recently from 0e2e16a to c19b76a Compare December 22, 2025 21:05
@its-miroma its-miroma force-pushed the regions branch 2 times, most recently from 317f38b to 2d0695b Compare January 27, 2026 14:01
@brc-dd brc-dd self-requested a review January 31, 2026 18:16
@brc-dd brc-dd self-assigned this Feb 5, 2026
Comment thread src/node/markdown/plugins/snippet.ts Outdated
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 brc-dd force-pushed the main branch 3 times, most recently from 15a0278 to 09af6c7 Compare March 26, 2026 04:26
* Remove all #region markers when including snippets
* @default false
*/
stripMarkersFromSnippets?: boolean
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Including non-existent regions includes entire file content Multi region snippet support

3 participants