Skip to content

Conversation

@its-miroma
Copy link
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
  • strip all #region comments from the included snippet

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

pkg-pr-new bot commented Nov 6, 2025

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

commit: c19b76a

@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
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>
@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
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

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

---

`<<<` snippets now also strip out all #region markers:

```file.ts
// #region A
// #region B
console.log("Hello, World!");
// #endregion
// #endregion
```

<<< file.ts#A
...does 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

2 participants