Describe the bug
I've experienced, that when rendering content from <!--@include: with a header, if the source had a frontmatter.description, it wouldn't import the correctly. It would either fail in the build or import the same header multiple times and/or text before the header.
Reproduction
- Create two pages with some headers. Please also make some of the headers, some that are identical.
- Create a frontmatter description on both pages (source page should be enough, but why not try both)
- Use an to import the content from one page to another.
- You should see, that it imports more that the selected header, either in plain text before the content or importing additional headers
Expected behavior
When using should only import the content below the heading.
System Info
System:
OS: Windows 11 10.0.26200
CPU: (16) x64 AMD Ryzen 7 5700X 8-Core Processor
Memory: 12.89 GB / 31.92 GB
Binaries:
Node: 26.2.0 - C:\Program Files\nodejs\node.EXE
npm: 11.12.0 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: Chromium (144.0.3719.104)
Firefox: 151.0.2 - C:\Program Files\Mozilla Firefox\firefox.exe
npmPackages:
vitepress: ^2.0.0-alpha.17 => 2.0.0-alpha.17
Additional context
I used GitHub Copilot trying to fix the issue. I ended up being successful by removing the !hasMeta in node_modules\vitepress\dist\node\chunk-CpMTk0EA.js
const atPresent = m1[0] === "@";
const includePath = atPresent ? path.join(srcDir, m1.slice(m1[1] === "/" ? 2 : 1)) : path.join(path.dirname(file), m1);
let content = fs__default.readFileSync(includePath, "utf-8");
+ if (path.extname(includePath) === ".md") {
+ content = matter(content).content;
+ }
if (region) {
const [regionName] = region;
const lines = content.split(/\r?\n/);
...
if (range) {
const [, startLine, endLine] = range;
const lines = content.split(/\r?\n/);
content = lines.slice(
startLine ? parseInt(startLine) - 1 : void 0,
endLine ? parseInt(endLine) : void 0
).join("\n");
}
- if (!hasMeta && path.extname(includePath) === ".md") {
- content = matter(content).content;
- }
includes.push(slash(includePath));
return processIncludes(
md,
srcDir,
content,
includePath,
includes,
cleanUrls
);
});
}
I've also found this issue, that is since long closed: #3195
Validations
Describe the bug
I've experienced, that when rendering content from <!--@include: with a header, if the source had a frontmatter.description, it wouldn't import the correctly. It would either fail in the build or import the same header multiple times and/or text before the header.
Reproduction
Expected behavior
When using should only import the content below the heading.
System Info
Additional context
I used GitHub Copilot trying to fix the issue. I ended up being successful by removing the
!hasMetainnode_modules\vitepress\dist\node\chunk-CpMTk0EA.jsI've also found this issue, that is since long closed: #3195
Validations