fix inline comment and other html blocks

This commit is contained in:
Tony Brix 2020-08-07 11:19:26 -05:00
parent 8d07cffadc
commit e39f1ef07e
2 changed files with 16 additions and 4 deletions

View File

@ -18,9 +18,9 @@ const block = {
html: '^ {0,3}(?:' // optional indentation html: '^ {0,3}(?:' // optional indentation
+ '<(script|pre|style)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)' // (1) + '<(script|pre|style)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)' // (1)
+ '|comment[^\\n]*(\\n+|$)' // (2) + '|comment[^\\n]*(\\n+|$)' // (2)
+ '|<\\?[\\s\\S]*?\\?>\\n*' // (3) + '|<\\?[\\s\\S]*?(?:\\?>\\n*|$)' // (3)
+ '|<![A-Z][\\s\\S]*?>\\n*' // (4) + '|<![A-Z][\\s\\S]*?(?:>\\n*|$)' // (4)
+ '|<!\\[CDATA\\[[\\s\\S]*?\\]\\]>\\n*' // (5) + '|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)' // (5)
+ '|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:\\n{2,}|$)' // (6) + '|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:\\n{2,}|$)' // (6)
+ '|<(?!script|pre|style)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) open tag + '|<(?!script|pre|style)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) open tag
+ '|</(?!script|pre|style)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) closing tag + '|</(?!script|pre|style)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) closing tag
@ -197,6 +197,8 @@ inline.punctuation = edit(inline.punctuation).replace(/punctuation/g, inline._pu
inline._blockSkip = '\\[[^\\]]*?\\]\\([^\\)]*?\\)|`[^`]*?`|<[^>]*?>'; inline._blockSkip = '\\[[^\\]]*?\\]\\([^\\)]*?\\)|`[^`]*?`|<[^>]*?>';
inline._overlapSkip = '__[^_]*?__|\\*\\*\\[^\\*\\]*?\\*\\*'; inline._overlapSkip = '__[^_]*?__|\\*\\*\\[^\\*\\]*?\\*\\*';
inline._comment = edit(block._comment).replace('(?:-->|$)', '-->').getRegex();
inline.em.start = edit(inline.em.start) inline.em.start = edit(inline.em.start)
.replace(/punctuation/g, inline._punctuation) .replace(/punctuation/g, inline._punctuation)
.getRegex(); .getRegex();
@ -249,7 +251,7 @@ inline.autolink = edit(inline.autolink)
inline._attribute = /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/; inline._attribute = /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/;
inline.tag = edit(inline.tag) inline.tag = edit(inline.tag)
.replace('comment', block._comment) .replace('comment', inline._comment)
.replace('attribute', inline._attribute) .replace('attribute', inline._attribute)
.getRegex(); .getRegex();

10
test.js Normal file
View File

@ -0,0 +1,10 @@
const marked = require('./');
const md = `
<!-- multi
line
comment
-->
`;
console.log(marked(md).replace(/\r/g, '\\r').replace(/\n/g, '\\n'));