diff --git a/src/Tokenizer.ts b/src/Tokenizer.ts
index f868f4421e..321c496644 100644
--- a/src/Tokenizer.ts
+++ b/src/Tokenizer.ts
@@ -694,8 +694,13 @@ export class _Tokenizer {
const cap = this.rules.block.html.exec(src);
if (cap) {
// an html block of type 7 cannot interrupt a paragraph, so a lazy
- // continuation line that starts one continues the paragraph instead
- if (this.lexer.state.lastToken?.type === 'paragraph' && !this.rules.other.htmlBeginRegex(4).test(src)) {
+ // continuation line that starts one continues the paragraph instead.
+ // Capture 3 identifies a type 6 block, including a tag name followed by
+ // a newline, which htmlBeginRegex (also used on list lines) does not match.
+ // Keep the existing guard for pedantic grammar and the legacy meta tag.
+ if (this.lexer.state.lastToken?.type === 'paragraph'
+ && (this.options.pedantic || !cap[3] || cap[3].toLowerCase() === 'meta')
+ && !this.rules.other.htmlBeginRegex(4).test(src)) {
return;
}
diff --git a/src/rules.ts b/src/rules.ts
index 601c598a8c..14044918ef 100644
--- a/src/rules.ts
+++ b/src/rules.ts
@@ -138,9 +138,15 @@ const _tag = 'address|article|aside|base|basefont|blockquote|body|caption'
+ '|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title'
+ '|tr|track|ul';
// HTML blocks of types (1) to (6) can interrupt a paragraph, type (7) cannot
-const _htmlInterrupt = edit(' {0,3}(?:?(?:tag)(?:[ \\t]+|\\n|/?>)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)|<\\?|)|<(?:(?:script|pre|style|textarea)(?:[\\s>]|$)|!--)|<\\?| = {
const blockPedantic: Record = {
...blockNormal,
+ blockquote: edit(blockquote.source).replace(_htmlInterrupt.source, _htmlInterruptLegacy).getRegex(),
html: edit(
'^ *(?:comment(?: *\\n|\\s*$)'
+ '|<(tag)[\\s\\S]+?\\1>(?: *\\n{2,}|\\s*$)' // closed tag
@@ -303,7 +310,7 @@ const blockPedantic: Record = {
.replace('|list', '')
.replace('|html', '')
.replace('|tag', '')
- .replace('lheading', lheading) // last, so the replacements above do not match inside it
+ .replace('lheading', lheading.source.replaceAll(_htmlInterrupt.source, _htmlInterruptLegacy.source)) // last, so the replacements above do not match inside it
.getRegex(),
};
diff --git a/test/specs/new/html_type6_newline_interrupt.html b/test/specs/new/html_type6_newline_interrupt.html
new file mode 100644
index 0000000000..5c560ebdfb
--- /dev/null
+++ b/test/specs/new/html_type6_newline_interrupt.html
@@ -0,0 +1,37 @@
+a
+
+x
+
a
+a
+
+a
+
+
+x
+
+
+x
+
a
+
+a
+
+a
+
+a
+a
+
+
+a
+
+
+> a
+
+x
+
+
+- a
+
+x
+
+
+a
+
+
+a
+
+
+a
+
+
+a
+
+
+a
+a
+<meta
+x
+
+a
+
+
a
+
{
setOptions(getDefaults());
});
+ describe('type 6 html tag names at end of input', () => {
+ for (const gfm of [false, true]) {
+ for (const tag of ['
{
+ assert.strictEqual(marked.parse(`a\n${tag}`, { gfm }), `
a
\n${tag}`);
+ });
+ }
+ }
+ });
+
describe('Test paragraph token type', () => {
it('should use the "paragraph" type on top level', () => {
const md = 'A Paragraph.\n\n> A blockquote\n\n- list item\n';