From 993085edda713639e5a91fd103a989cf5f918bbd Mon Sep 17 00:00:00 2001 From: Maximilian Falco Widjaya Date: Fri, 29 May 2026 14:24:35 +1000 Subject: [PATCH] fix: terminate html flow block when opener has trailing text --- .../terminate-html-flow-blocks.test.ts | 36 +++++++++++++++++++ .../mdxish/terminate-html-flow-blocks.ts | 10 +++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/__tests__/transformers/terminate-html-flow-blocks.test.ts b/__tests__/transformers/terminate-html-flow-blocks.test.ts index 4b4a7ba89..af259e664 100644 --- a/__tests__/transformers/terminate-html-flow-blocks.test.ts +++ b/__tests__/transformers/terminate-html-flow-blocks.test.ts @@ -164,6 +164,42 @@ const x = 1; const result = terminateHtmlFlowBlocks(input); expect(result).toBe(`
+[/block]`); + }); + + it('inserts blank line after an opening HTML tag with trailing text', () => { + const input = `
  • test +[block:parameters] +{ + "data": { + "h-0": "Heading", + "0-0": "Content" + }, + "cols": 1, + "rows": 1, + "align": [ + "left", + "left" + ] +} +[/block]`; + + const result = terminateHtmlFlowBlocks(input); + expect(result).toBe(`
  • test + +[block:parameters] +{ + "data": { + "h-0": "Heading", + "0-0": "Content" + }, + "cols": 1, + "rows": 1, + "align": [ + "left", + "left" + ] +} [/block]`); }); diff --git a/processor/transform/mdxish/terminate-html-flow-blocks.ts b/processor/transform/mdxish/terminate-html-flow-blocks.ts index 77aaff788..3f83d10a8 100644 --- a/processor/transform/mdxish/terminate-html-flow-blocks.ts +++ b/processor/transform/mdxish/terminate-html-flow-blocks.ts @@ -6,6 +6,10 @@ const STANDALONE_HTML_LINE_REGEX = /^(<[a-z][^<>]*>|<\/[a-z][^<>]*>)+\s*$/; const HTML_LINE_WITH_CONTENT_REGEX = /^<[a-z][^<>]*>.*<\/[a-z][^<>]*>(?:[^<]*)$/; +// Tag at start of line + trailing text, no closer (e.g. `
  • test`). CommonMark +// still opens an HTML block here, so we terminate it. +const HTML_LINE_WITH_TRAILING_CONTENT_REGEX = /^(<[a-z][^<>]*>|<\/[a-z][^<>]*>)\s*\S/; + const TABLE_STRUCTURE_TAGS = ['table', 'thead', 'tbody', 'tfoot', 'tr', 'td', 'th', 'caption', 'colgroup']; // Tags whose contents must be preserved as is, inserting a blank line after the @@ -20,7 +24,11 @@ const RAW_CONTENT_TAG_MATCHERS = RAW_CONTENT_TAGS.map(tag => ({ })); function isLineHtml(line: string) { - return STANDALONE_HTML_LINE_REGEX.test(line) || HTML_LINE_WITH_CONTENT_REGEX.test(line); + return ( + STANDALONE_HTML_LINE_REGEX.test(line) || + HTML_LINE_WITH_CONTENT_REGEX.test(line) || + HTML_LINE_WITH_TRAILING_CONTENT_REGEX.test(line) + ); } // True if any RAW_CONTENT_TAGS opener on this line is not closed on the same line.