From e68fade75d2259b10695e85277f5483a084e3ae7 Mon Sep 17 00:00:00 2001 From: T <6601329+cookesan@users.noreply.github.com> Date: Sun, 28 Jun 2026 08:04:16 -0300 Subject: [PATCH] fix: strip frontmatter before heading includes (#5246) --- __tests__/unit/node/markdownToVue.test.ts | 57 +++++++++++++++++++++++ src/node/utils/processIncludes.ts | 11 ++++- 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/__tests__/unit/node/markdownToVue.test.ts b/__tests__/unit/node/markdownToVue.test.ts index 9c88cdb5..ec89e7e0 100644 --- a/__tests__/unit/node/markdownToVue.test.ts +++ b/__tests__/unit/node/markdownToVue.test.ts @@ -67,6 +67,63 @@ describe('node/markdownToVue', () => { }) }) + test('selects included heading sections after frontmatter', async () => { + root = await mkdtemp(path.join(tmpdir(), 'vitepress-include-')) + + const file = path.join(root, 'index.md') + const source = path.join(root, 'source.md') + await writeFile( + source, + [ + '---', + 'description: Source description', + '---', + '# Intro', + '', + 'intro text', + '', + '## Shared', + '', + 'shared before target', + '', + '## Target', + '', + 'target text', + '', + '### Child', + '', + 'child text', + '', + '## Shared', + '', + 'shared after target', + '' + ].join('\n') + ) + const src = '' + await writeFile(file, src) + + const siteConfig = await resolveConfig(root, 'build', 'production') + const render = await createMarkdownToVueRenderFn( + siteConfig.srcDir, + { cache: false }, + '/', + false, + false, + siteConfig + ) + + const result = await render(src, file, 'public') + + expect(result.vueSrc).toContain('
target text
') + expect(result.vueSrc).toContain('