From 1b5d63fd042e9ee76a2f7435c03452b6b6172544 Mon Sep 17 00:00:00 2001 From: Krisztian Daroczi Date: Sun, 10 May 2026 13:06:59 +0200 Subject: [PATCH] Prevents prefix stripper from eating empty new lines --- src/modelFactory/markdownPrefixStripper.ts | 4 +-- .../cliPrettyfierSystemTests.test.ts | 9 ++++++- .../blockQuoteNewLineNoTable-expected.md | 25 +++++++++++++++++++ .../blockQuoteNewLineNoTable-input.md | 25 +++++++++++++++++++ 4 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 test/systemTests/resources/blockQuoteNewLineNoTable-expected.md create mode 100644 test/systemTests/resources/blockQuoteNewLineNoTable-input.md diff --git a/src/modelFactory/markdownPrefixStripper.ts b/src/modelFactory/markdownPrefixStripper.ts index 7a2e660..9234cb7 100644 --- a/src/modelFactory/markdownPrefixStripper.ts +++ b/src/modelFactory/markdownPrefixStripper.ts @@ -31,14 +31,14 @@ export class MarkdownPrefixStripper { let remaining = line; // Layer 1: Blockquote markers (always strip - unambiguous Markdown syntax) - const bqMatch = remaining.match(/^(\s*(?:>\s*)+)/); + const bqMatch = remaining.match(/^([^\S\r\n]*(?:>[^\S\r\n]*)+)/); if (bqMatch) { prefix += bqMatch[1]; remaining = remaining.substring(bqMatch[1].length); } // Layer 2: List markers (only strip when followed by whitespace + |, i.e., bordered tables) - const listMatch = remaining.match(/^(\s*(?:\d+[.)]|[-*+]))(?=\s+\|)/); + const listMatch = remaining.match(/^([^\S\r\n]*(?:\d+[.)]|[-*+]))(?=[^\S\r\n]+\|)/); if (listMatch) { prefix += listMatch[1]; } diff --git a/test/systemTests/cliPrettyfierSystemTests.test.ts b/test/systemTests/cliPrettyfierSystemTests.test.ts index 16f0942..f6b2ac6 100644 --- a/test/systemTests/cliPrettyfierSystemTests.test.ts +++ b/test/systemTests/cliPrettyfierSystemTests.test.ts @@ -28,7 +28,14 @@ fs.readdir(path.resolve(__dirname, "resources/"), function(err, files) { for (let fileNameRoot of distinctTests) { test(`[${fileNameRoot}]`, () => { const input = readFileContents(`${fileNameRoot}-input.md`); - assert.throws(() => CliPrettify.check(input)); + const expected = readFileContents(`${fileNameRoot}-expected.md`); + const cliOptions = SystemTestsConfig.getCliOptionsFor(fileNameRoot); + + if (input === expected) { + assert.doesNotThrow(() => CliPrettify.check(input, cliOptions)); + } else { + assert.throws(() => CliPrettify.check(input, cliOptions)); + } }); } }); diff --git a/test/systemTests/resources/blockQuoteNewLineNoTable-expected.md b/test/systemTests/resources/blockQuoteNewLineNoTable-expected.md new file mode 100644 index 0000000..eb92c7d --- /dev/null +++ b/test/systemTests/resources/blockQuoteNewLineNoTable-expected.md @@ -0,0 +1,25 @@ +> First line of my note. +> +> Second line. + +> [!NOTE] +> First line of my note. +> +> ```text +> some_code +> ``` + +# Awesome file + +> [!NOTE] +> First line of my note. +> +> ```text +> some_code +> ``` + +Here is a paragraph. + +> A marvelous quotation. + +Second paragraph. \ No newline at end of file diff --git a/test/systemTests/resources/blockQuoteNewLineNoTable-input.md b/test/systemTests/resources/blockQuoteNewLineNoTable-input.md new file mode 100644 index 0000000..eb92c7d --- /dev/null +++ b/test/systemTests/resources/blockQuoteNewLineNoTable-input.md @@ -0,0 +1,25 @@ +> First line of my note. +> +> Second line. + +> [!NOTE] +> First line of my note. +> +> ```text +> some_code +> ``` + +# Awesome file + +> [!NOTE] +> First line of my note. +> +> ```text +> some_code +> ``` + +Here is a paragraph. + +> A marvelous quotation. + +Second paragraph. \ No newline at end of file