mirror of
https://github.com/showdownjs/showdown.git
synced 2024-03-22 13:30:55 +08:00
fix(parser): fix issue with comments inside nested code blocks
Code blocks containing comments are now converted correctly when nested in list items. Closes #288
This commit is contained in:
parent
5d2016c0c1
commit
799abea767
BIN
dist/showdown.js
vendored
BIN
dist/showdown.js
vendored
Binary file not shown.
BIN
dist/showdown.js.map
vendored
BIN
dist/showdown.js.map
vendored
Binary file not shown.
BIN
dist/showdown.min.js
vendored
BIN
dist/showdown.min.js
vendored
Binary file not shown.
BIN
dist/showdown.min.js.map
vendored
BIN
dist/showdown.min.js.map
vendored
Binary file not shown.
|
@ -52,12 +52,13 @@ showdown.subParser('hashHTMLBlocks', function (text, options, globals) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// HR SPECIAL CASE
|
// HR SPECIAL CASE
|
||||||
text = text.replace(/(\n[ ]{0,3}(<(hr)\b([^<>])*?\/?>)[ \t]*(?=\n{2,}))/g,
|
text = text.replace(/(\n {0,3}(<(hr)\b([^<>])*?\/?>)[ \t]*(?=\n{2,}))/g,
|
||||||
showdown.subParser('hashElement')(text, options, globals));
|
showdown.subParser('hashElement')(text, options, globals));
|
||||||
|
|
||||||
// Special case for standalone HTML comments:
|
// Special case for standalone HTML comments
|
||||||
text = text.replace(/(<!--[\s\S]*?-->)/g,
|
text = showdown.helper.replaceRecursiveRegExp(text, function (txt) {
|
||||||
showdown.subParser('hashElement')(text, options, globals));
|
return '\n\n~K' + (globals.gHtmlBlocks.push(txt) - 1) + 'K\n\n';
|
||||||
|
}, '^(?: |\\t){0,3}<!--', '-->', 'gm');
|
||||||
|
|
||||||
// PHP and ASP-style processor instructions (<?...?> and <%...%>)
|
// PHP and ASP-style processor instructions (<?...?> and <%...%>)
|
||||||
text = text.replace(/(?:\n\n)([ ]{0,3}(?:<([?%])[^\r]*?\2>)[ \t]*(?=\n{2,}))/g,
|
text = text.replace(/(?:\n\n)([ ]{0,3}(?:<([?%])[^\r]*?\2>)[ \t]*(?=\n{2,}))/g,
|
||||||
|
|
14
test/cases/html-comments.html
Normal file
14
test/cases/html-comments.html
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
<!-- a comment -->
|
||||||
|
|
||||||
|
<!-- a comment with *bogus* __markdown__ inside -->
|
||||||
|
|
||||||
|
<p>words <!-- a comment --> words</p>
|
||||||
|
|
||||||
|
<!-- comment -->
|
||||||
|
|
||||||
|
<p>words</p>
|
||||||
|
|
||||||
|
<!-- comment -->
|
||||||
|
|
||||||
|
<pre><code><!-- comment -->
|
||||||
|
</code></pre>
|
11
test/cases/html-comments.md
Normal file
11
test/cases/html-comments.md
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
<!-- a comment -->
|
||||||
|
|
||||||
|
<!-- a comment with *bogus* __markdown__ inside -->
|
||||||
|
|
||||||
|
words <!-- a comment --> words
|
||||||
|
|
||||||
|
<!-- comment --> words
|
||||||
|
|
||||||
|
<!-- comment -->
|
||||||
|
|
||||||
|
<!-- comment -->
|
9
test/cases/html-inside-listed-code.html
Normal file
9
test/cases/html-inside-listed-code.html
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
<ul>
|
||||||
|
<li><p>list item 1</p>
|
||||||
|
|
||||||
|
<pre><code class="html language-html"><a href="www.google.com">google</a>
|
||||||
|
<div>
|
||||||
|
<div>some div</div>
|
||||||
|
</div>
|
||||||
|
</code></pre></li>
|
||||||
|
</ul>
|
8
test/cases/html-inside-listed-code.md
Normal file
8
test/cases/html-inside-listed-code.md
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
- list item 1
|
||||||
|
|
||||||
|
```html
|
||||||
|
<a href="www.google.com">google</a>
|
||||||
|
<div>
|
||||||
|
<div>some div</div>
|
||||||
|
</div>
|
||||||
|
```
|
3
test/cases/line-starts-with-html.html
Normal file
3
test/cases/line-starts-with-html.html
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
<p><a href="foo">some text</a> words</p>
|
||||||
|
|
||||||
|
<p><br> words</p>
|
3
test/cases/line-starts-with-html.md
Normal file
3
test/cases/line-starts-with-html.md
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
<a href="foo">some text</a> words
|
||||||
|
|
||||||
|
<br> words
|
|
@ -0,0 +1,21 @@
|
||||||
|
<ul>
|
||||||
|
<li><p>list item 1</p>
|
||||||
|
|
||||||
|
<pre><code><parent>
|
||||||
|
<child>child1</child>
|
||||||
|
<!-- This is a comment -->
|
||||||
|
<child>child2</child>
|
||||||
|
<child>some text <!-- a comment --></child>
|
||||||
|
</parent>
|
||||||
|
</code></pre></li>
|
||||||
|
|
||||||
|
<li><p>list item 2</p></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<pre><code><parent>
|
||||||
|
<child>child1</child>
|
||||||
|
<!-- This is a comment -->
|
||||||
|
<child>child2</child>
|
||||||
|
<child>some text <!-- a comment --></child>
|
||||||
|
</parent>
|
||||||
|
</code></pre>
|
|
@ -0,0 +1,21 @@
|
||||||
|
* list item 1
|
||||||
|
|
||||||
|
```
|
||||||
|
<parent>
|
||||||
|
<child>child1</child>
|
||||||
|
<!-- This is a comment -->
|
||||||
|
<child>child2</child>
|
||||||
|
<child>some text <!-- a comment --></child>
|
||||||
|
</parent>
|
||||||
|
```
|
||||||
|
|
||||||
|
* list item 2
|
||||||
|
|
||||||
|
```
|
||||||
|
<parent>
|
||||||
|
<child>child1</child>
|
||||||
|
<!-- This is a comment -->
|
||||||
|
<child>child2</child>
|
||||||
|
<child>some text <!-- a comment --></child>
|
||||||
|
</parent>
|
||||||
|
```
|
Loading…
Reference in New Issue
Block a user