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:
Estevao Soares dos Santos 2016-08-30 06:07:57 +01:00
parent 5d2016c0c1
commit 799abea767
13 changed files with 95 additions and 4 deletions

BIN
dist/showdown.js vendored

Binary file not shown.

BIN
dist/showdown.js.map vendored

Binary file not shown.

BIN
dist/showdown.min.js vendored

Binary file not shown.

Binary file not shown.

View File

@ -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,

View 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>&lt;!-- comment --&gt;
</code></pre>

View File

@ -0,0 +1,11 @@
<!-- a comment -->
<!-- a comment with *bogus* __markdown__ inside -->
words <!-- a comment --> words
<!-- comment --> words
<!-- comment -->
<!-- comment -->

View File

@ -0,0 +1,9 @@
<ul>
<li><p>list item 1</p>
<pre><code class="html language-html">&lt;a href="www.google.com"&gt;google&lt;/a&gt;
&lt;div&gt;
&lt;div&gt;some div&lt;/div&gt;
&lt;/div&gt;
</code></pre></li>
</ul>

View File

@ -0,0 +1,8 @@
- list item 1
```html
<a href="www.google.com">google</a>
<div>
<div>some div</div>
</div>
```

View File

@ -0,0 +1,3 @@
<p><a href="foo">some text</a> words</p>
<p><br> words</p>

View File

@ -0,0 +1,3 @@
<a href="foo">some text</a> words
<br> words

View File

@ -0,0 +1,21 @@
<ul>
<li><p>list item 1</p>
<pre><code>&lt;parent&gt;
&lt;child&gt;child1&lt;/child&gt;
&lt;!-- This is a comment --&gt;
&lt;child&gt;child2&lt;/child&gt;
&lt;child&gt;some text &lt;!-- a comment --&gt;&lt;/child&gt;
&lt;/parent&gt;
</code></pre></li>
<li><p>list item 2</p></li>
</ul>
<pre><code>&lt;parent&gt;
&lt;child&gt;child1&lt;/child&gt;
&lt;!-- This is a comment --&gt;
&lt;child&gt;child2&lt;/child&gt;
&lt;child&gt;some text &lt;!-- a comment --&gt;&lt;/child&gt;
&lt;/parent&gt;
</code></pre>

View File

@ -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>
```