From 6e8827146e670ff8114600858d91c2a7d0ce4dfb Mon Sep 17 00:00:00 2001 From: Miroma Date: Mon, 6 Apr 2026 23:43:38 +0200 Subject: [PATCH] fix(md)!: warn if region not found 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 #4625 --- src/node/markdown/plugins/snippet.ts | 4 ++++ src/node/utils/processIncludes.ts | 10 +++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/node/markdown/plugins/snippet.ts b/src/node/markdown/plugins/snippet.ts index 2acbf4c0f..c3ede0e2d 100644 --- a/src/node/markdown/plugins/snippet.ts +++ b/src/node/markdown/plugins/snippet.ts @@ -218,6 +218,10 @@ export const snippetPlugin = (md: MarkdownItAsync, srcDir: string) => { ) .join('\n') ) + } else { + token.content = `No region #${region} found in path: ${src}` + token.info = '' + return fence(...args) } } diff --git a/src/node/utils/processIncludes.ts b/src/node/utils/processIncludes.ts index 97d3d987c..a3b847489 100644 --- a/src/node/utils/processIncludes.ts +++ b/src/node/utils/processIncludes.ts @@ -70,9 +70,13 @@ export function processIncludes( } } - content = regions - .flatMap((region) => lines.slice(region.start, region.end)) - .join('\n') + if (regions.length > 0) { + content = regions + .flatMap((region) => lines.slice(region.start, region.end)) + .join('\n') + } else { + content = `No region or heading #${region} found in path: ${includePath}` + } } if (range) {