diff --git a/dist/showdown.js b/dist/showdown.js index 6d30511..cbf5522 100644 Binary files a/dist/showdown.js and b/dist/showdown.js differ diff --git a/dist/showdown.js.map b/dist/showdown.js.map index a64543d..79e29c9 100644 Binary files a/dist/showdown.js.map and b/dist/showdown.js.map differ diff --git a/dist/showdown.min.js b/dist/showdown.min.js index 6fe4aee..780bf15 100644 Binary files a/dist/showdown.min.js and b/dist/showdown.min.js differ diff --git a/dist/showdown.min.js.map b/dist/showdown.min.js.map index d3e6f24..6482e8c 100644 Binary files a/dist/showdown.min.js.map and b/dist/showdown.min.js.map differ diff --git a/src/converter.js b/src/converter.js index 57d0a23..1213a6d 100644 --- a/src/converter.js +++ b/src/converter.js @@ -276,6 +276,7 @@ showdown.Converter = function (converterOptions) { }); // run the sub parsers + text = showdown.subParser('hashPreCodeTags')(text, options, globals); text = showdown.subParser('githubCodeBlocks')(text, options, globals); text = showdown.subParser('hashHTMLBlocks')(text, options, globals); text = showdown.subParser('hashHTMLSpans')(text, options, globals); diff --git a/src/subParsers/hashPreCodeTags.js b/src/subParsers/hashPreCodeTags.js new file mode 100644 index 0000000..8315d95 --- /dev/null +++ b/src/subParsers/hashPreCodeTags.js @@ -0,0 +1,15 @@ +/** + * Hash span elements that should not be parsed as markdown + */ +showdown.subParser('hashPreCodeTags', function (text, config, globals) { + 'use strict'; + + var repFunc = function (wholeMatch, match, left, right) { + // encode html entities + var codeblock = left + showdown.subParser('encodeCode')(match) + right; + return '\n\n~G' + (globals.ghCodeBlocks.push({text: wholeMatch, codeblock: codeblock}) - 1) + 'G\n\n'; + }; + + text = showdown.helper.replaceRecursiveRegExp(text, repFunc, '^(?: |\\t){0,3}
]*>\\s*]*>', '^(?: |\\t){0,3}
\\s*
', 'gim');
+ return text;
+});
diff --git a/src/subParsers/paragraphs.js b/src/subParsers/paragraphs.js
index 7f19c38..b5673df 100644
--- a/src/subParsers/paragraphs.js
+++ b/src/subParsers/paragraphs.js
@@ -31,7 +31,6 @@ showdown.subParser('paragraphs', function (text, options, globals) {
for (i = 0; i < end; i++) {
var blockText = '',
grafsOutIt = grafsOut[i],
- child = false,
codeFlag = false;
// if this is a marker for an html block...
while (grafsOutIt.search(/~(K|G)(\d+)\1/) >= 0) {
@@ -42,7 +41,12 @@ showdown.subParser('paragraphs', function (text, options, globals) {
blockText = globals.gHtmlBlocks[num];
} else {
// we need to check if ghBlock is a false positive
- blockText = (codeFlag) ? globals.ghCodeBlocks[num].text : globals.ghCodeBlocks[num].codeblock;
+ if (codeFlag) {
+ // use encoded version of all text
+ blockText = showdown.subParser('encodeCode')(globals.ghCodeBlocks[num].text);
+ } else {
+ blockText = globals.ghCodeBlocks[num].codeblock;
+ }
}
blockText = blockText.replace(/\$/g, '$$$$'); // Escape any dollar signs
@@ -51,7 +55,6 @@ showdown.subParser('paragraphs', function (text, options, globals) {
if (/^]*>\s*]*>/.test(grafsOutIt)) {
codeFlag = true;
}
- child = true;
}
grafsOut[i] = grafsOutIt;
}
diff --git a/test/cases/pre-code-tags-inside-code-block.html b/test/cases/pre-code-tags-inside-code-block.html
new file mode 100644
index 0000000..66544da
--- /dev/null
+++ b/test/cases/pre-code-tags-inside-code-block.html
@@ -0,0 +1,7 @@
+code inception
+
+<pre><code>
+<div>some html code inside code html tags inside a fenced code block</div>
+</code></pre>
+
+
diff --git a/test/cases/pre-code-tags-inside-code-block.md b/test/cases/pre-code-tags-inside-code-block.md
new file mode 100644
index 0000000..79b57f2
--- /dev/null
+++ b/test/cases/pre-code-tags-inside-code-block.md
@@ -0,0 +1,8 @@
+code inception
+
+```
+
+some html code inside code html tags inside a fenced code block
+
+```
+
diff --git a/test/cases/pre-code-tags.html b/test/cases/pre-code-tags.html
new file mode 100644
index 0000000..573b388
--- /dev/null
+++ b/test/cases/pre-code-tags.html
@@ -0,0 +1,16 @@
+
+
+foobar
+
+
+
+blabla
+
+
+foobar
+
+
+
+
+<div>some html code</div>
+
diff --git a/test/cases/pre-code-tags.md b/test/cases/pre-code-tags.md
new file mode 100644
index 0000000..ab1d543
--- /dev/null
+++ b/test/cases/pre-code-tags.md
@@ -0,0 +1,17 @@
+
+
+foobar
+
+
+
+blabla
+
+
+foobar
+
+
+
+
+some html code
+
+
diff --git a/test/issues/#229.2.code-being-parsed-inside-HTML-code-tags.html b/test/issues/#229.2.code-being-parsed-inside-HTML-code-tags.html
index 4f53c72..dff2c46 100644
--- a/test/issues/#229.2.code-being-parsed-inside-HTML-code-tags.html
+++ b/test/issues/#229.2.code-being-parsed-inside-HTML-code-tags.html
@@ -1,12 +1,12 @@
- foo
+foo
- ```javascript
- var s = "JavaScript syntax highlighting";
- alert(s);
- ```
+```javascript
+var s = "JavaScript syntax highlighting";
+alert(s);
+```
- bar
+bar
this is a long paragraph
diff --git a/test/issues/#229.code-being-parsed-inside-HTML-code-tags.html b/test/issues/#229.code-being-parsed-inside-HTML-code-tags.html
index 5a148ce..deba3d4 100644
--- a/test/issues/#229.code-being-parsed-inside-HTML-code-tags.html
+++ b/test/issues/#229.code-being-parsed-inside-HTML-code-tags.html
@@ -11,6 +11,6 @@ print s
```
No language indicated, so no syntax highlighting.
-But let's throw in a tag.
+But let's throw in a <b>tag</b>.
```
diff --git a/test/issues/#230.paragraphs-are-ignored-between-code-tags.html b/test/issues/#230.paragraphs-are-ignored-between-code-tags.html
new file mode 100644
index 0000000..1f2492a
--- /dev/null
+++ b/test/issues/#230.paragraphs-are-ignored-between-code-tags.html
@@ -0,0 +1,12 @@
+```python
+var s;
+```
+
+
+this is a long paragraph
+ +
+```javascript
+var s;
+```
+
diff --git a/test/issues/#230.paragraphs-are-ignored-between-code-tags.md b/test/issues/#230.paragraphs-are-ignored-between-code-tags.md
new file mode 100644
index 0000000..9362a18
--- /dev/null
+++ b/test/issues/#230.paragraphs-are-ignored-between-code-tags.md
@@ -0,0 +1,12 @@
+```python
+var s;
+```
+
+
+this is a long paragraph
+
+
+```javascript
+var s;
+```
+