Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions __tests__/transformers/terminate-html-flow-blocks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,42 @@ const x = 1;
const result = terminateHtmlFlowBlocks(input);
expect(result).toBe(`<div>

[/block]`);
});

it('inserts blank line after an opening HTML tag with trailing text', () => {
const input = `<li> 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(`<li> test

[block:parameters]
{
"data": {
"h-0": "Heading",
"0-0": "Content"
},
"cols": 1,
"rows": 1,
"align": [
"left",
"left"
]
}
[/block]`);
});

Expand Down
10 changes: 9 additions & 1 deletion processor/transform/mdxish/terminate-html-flow-blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. `<li> 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
Expand All @@ -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.
Expand Down