From e39f1ef07e6dacf9327a5f06b5f2dc4e10d8f72c Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Fri, 7 Aug 2020 11:19:26 -0500 Subject: [PATCH] fix inline comment and other html blocks --- src/rules.js | 10 ++++++---- test.js | 10 ++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 test.js diff --git a/src/rules.js b/src/rules.js index 619f2050..da2dfb32 100644 --- a/src/rules.js +++ b/src/rules.js @@ -18,9 +18,9 @@ const block = { html: '^ {0,3}(?:' // optional indentation + '<(script|pre|style)[\\s>][\\s\\S]*?(?:[^\\n]*\\n+|$)' // (1) + '|comment[^\\n]*(\\n+|$)' // (2) - + '|<\\?[\\s\\S]*?\\?>\\n*' // (3) - + '|\\n*' // (4) - + '|\\n*' // (5) + + '|<\\?[\\s\\S]*?(?:\\?>\\n*|$)' // (3) + + '|\\n*|$)' // (4) + + '|\\n*|$)' // (5) + '|)[\\s\\S]*?(?:\\n{2,}|$)' // (6) + '|<(?!script|pre|style)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) open tag + '|(?=[ \\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._overlapSkip = '__[^_]*?__|\\*\\*\\[^\\*\\]*?\\*\\*'; +inline._comment = edit(block._comment).replace('(?:-->|$)', '-->').getRegex(); + inline.em.start = edit(inline.em.start) .replace(/punctuation/g, inline._punctuation) .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.tag = edit(inline.tag) - .replace('comment', block._comment) + .replace('comment', inline._comment) .replace('attribute', inline._attribute) .getRegex(); diff --git a/test.js b/test.js new file mode 100644 index 00000000..3b59212a --- /dev/null +++ b/test.js @@ -0,0 +1,10 @@ +const marked = require('./'); + +const md = ` + +`; + +console.log(marked(md).replace(/\r/g, '\\r').replace(/\n/g, '\\n'));