Explorar o código

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
Estevao Soares dos Santos %!s(int64=9) %!d(string=hai) anos
pai
achega
799abea767

+ 6 - 5
dist/showdown.js

@@ -1,4 +1,4 @@
-;/*! showdown 19-08-2016 */
+;/*! showdown 30-08-2016 */
 (function(){
 /**
  * Created by Tivie on 13-07-2015.
@@ -1760,12 +1760,13 @@ showdown.subParser('hashHTMLBlocks', function (text, options, globals) {
   }
 
   // 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));
 
-  // Special case for standalone HTML comments:
-  text = text.replace(/(<!--[\s\S]*?-->)/g,
-    showdown.subParser('hashElement')(text, options, globals));
+  // Special case for standalone HTML comments
+  text = showdown.helper.replaceRecursiveRegExp(text, function (txt) {
+    return '\n\n~K' + (globals.gHtmlBlocks.push(txt) - 1) + 'K\n\n';
+  }, '^(?: |\\t){0,3}<!--', '-->', 'gm');
 
   // PHP and ASP-style processor instructions (<?...?> and <%...%>)
   text = text.replace(/(?:\n\n)([ ]{0,3}(?:<([?%])[^\r]*?\2>)[ \t]*(?=\n{2,}))/g,

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 0
dist/showdown.js.map


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 1 - 1
dist/showdown.min.js


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 0
dist/showdown.min.js.map


+ 5 - 4
src/subParsers/hashHTMLBlocks.js

@@ -52,12 +52,13 @@ showdown.subParser('hashHTMLBlocks', function (text, options, globals) {
   }
 
   // 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));
 
-  // Special case for standalone HTML comments:
-  text = text.replace(/(<!--[\s\S]*?-->)/g,
-    showdown.subParser('hashElement')(text, options, globals));
+  // Special case for standalone HTML comments
+  text = showdown.helper.replaceRecursiveRegExp(text, function (txt) {
+    return '\n\n~K' + (globals.gHtmlBlocks.push(txt) - 1) + 'K\n\n';
+  }, '^(?: |\\t){0,3}<!--', '-->', 'gm');
 
   // PHP and ASP-style processor instructions (<?...?> and <%...%>)
   text = text.replace(/(?:\n\n)([ ]{0,3}(?:<([?%])[^\r]*?\2>)[ \t]*(?=\n{2,}))/g,

+ 14 - 0
test/cases/html-comments.html

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

+ 11 - 0
test/cases/html-comments.md

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

+ 9 - 0
test/cases/html-inside-listed-code.html

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

+ 8 - 0
test/cases/html-inside-listed-code.md

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

+ 3 - 0
test/cases/line-starts-with-html.html

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

+ 3 - 0
test/cases/line-starts-with-html.md

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

+ 21 - 0
test/issues/#288.code-blocks-containing-xml-comments-are-not-converted-correctly-when-nested-in-list-items.html

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

+ 21 - 0
test/issues/#288.code-blocks-containing-xml-comments-are-not-converted-correctly-when-nested-in-list-items.md

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

Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio