Browse Source

fix(fenced codeblocks): add tilde as fenced code block delimiter

Closes #456
Estevao Soares dos Santos 7 years ago
parent
commit
c956ede4e7

+ 2 - 2
dist/showdown.js

@@ -1,4 +1,4 @@
-;/*! showdown v 1.8.1 - 01-11-2017 */
+;/*! showdown v 1.8.1 - 11-11-2017 */
 (function(){
 /**
  * Created by Tivie on 13-07-2015.
@@ -3076,7 +3076,7 @@ showdown.subParser('githubCodeBlocks', function (text, options, globals) {
 
   text += '¨0';
 
-  text = text.replace(/(?:^|\n)```(.*)\n([\s\S]*?)\n```/g, function (wholeMatch, language, codeblock) {
+  text = text.replace(/(?:^|\n)(```+|~~~+)([^\s`~]*)\n([\s\S]*?)\n\1/g, function (wholeMatch, delim, language, codeblock) {
     var end = (options.omitExtraWLInCodeBlocks) ? '' : '\n';
 
     // First parse the github code block

File diff suppressed because it is too large
+ 0 - 0
dist/showdown.js.map


File diff suppressed because it is too large
+ 0 - 1
dist/showdown.min.js


File diff suppressed because it is too large
+ 0 - 0
dist/showdown.min.js.map


+ 1 - 1
src/subParsers/githubCodeBlocks.js

@@ -20,7 +20,7 @@ showdown.subParser('githubCodeBlocks', function (text, options, globals) {
 
   text += '¨0';
 
-  text = text.replace(/(?:^|\n)```(.*)\n([\s\S]*?)\n```/g, function (wholeMatch, language, codeblock) {
+  text = text.replace(/(?:^|\n)(```+|~~~+)([^\s`~]*)\n([\s\S]*?)\n\1/g, function (wholeMatch, delim, language, codeblock) {
     var end = (options.omitExtraWLInCodeBlocks) ? '' : '\n';
 
     // First parse the github code block

+ 6 - 0
test/cases/github-style-codeblock.html

@@ -6,3 +6,9 @@
 <p>And some HTML</p>
 <pre><code class="html language-html">&lt;div&gt;HTML!&lt;/div&gt;
 </code></pre>
+<p>Use more than 3 backticks</p>
+<pre><code>some code
+</code></pre>
+<p>Use tilde as delimiter</p>
+<pre><code>another piece of code
+</code></pre>

+ 12 - 0
test/cases/github-style-codeblock.md

@@ -12,3 +12,15 @@ And some HTML
 ```html
 <div>HTML!</div>
 ```
+
+Use more than 3 backticks
+
+`````
+some code
+`````
+
+Use tilde as delimiter
+
+~~~
+another piece of code
+~~~

Some files were not shown because too many files changed in this diff