From 39be5e4ee096082dc45d46d02b5d1218e8bf5efd Mon Sep 17 00:00:00 2001 From: 3y3 <3y3@ya.ru> Date: Mon, 18 Nov 2024 16:51:36 +0300 Subject: [PATCH] fix: Fix notitle includef for empty files --- src/transform/plugins/includes/index.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/transform/plugins/includes/index.ts b/src/transform/plugins/includes/index.ts index 2840966f..b9a76dec 100644 --- a/src/transform/plugins/includes/index.ts +++ b/src/transform/plugins/includes/index.ts @@ -17,7 +17,9 @@ import {MarkdownItIncluded} from './types'; const INCLUDE_REGEXP = /^{%\s*include\s*(notitle)?\s*\[(.+?)]\((.+?)\)\s*%}$/; function stripTitleTokens(tokens: Token[]) { - if (tokens[0].type === 'heading_open' && tokens[2].type === 'heading_close') { + const [open, _, close] = tokens; + + if (open?.type === 'heading_open' && close?.type === 'heading_close') { tokens.splice(0, 3); } } @@ -73,6 +75,7 @@ function unfoldIncludes(md: MarkdownItIncluded, state: StateCore, path: string, let includedTokens; if (hash) { + // TODO: add warning about missed block includedTokens = findBlockTokens(fileTokens, hash); } else { includedTokens = fileTokens;