浏览代码

feat(ghCodeBlocks): add option to disable GH codeblocks

GFM support fenced codeblocks. Showdown, since very early, adopted this too.
It is now possible to disable GFM codeblocks with the option "ghCodeBlocks" set to false.
It is enabled by default
Estevão Soares dos Santos 10 年之前
父节点
当前提交
c33f98884b

+ 7 - 1
dist/showdown.js

@@ -18,7 +18,8 @@ var showdown = {},
       literalMidWordUnderscores: false,
       literalMidWordUnderscores: false,
       strikethrough:             false,
       strikethrough:             false,
       tables:                    false,
       tables:                    false,
-      tablesHeaderId:            false
+      tablesHeaderId:            false,
+      ghCodeBlocks:              true  // true due to historical reasons
     },
     },
     globalOptions = JSON.parse(JSON.stringify(defaultOptions)); //clone default options out of laziness =P
     globalOptions = JSON.parse(JSON.stringify(defaultOptions)); //clone default options out of laziness =P
 
 
@@ -1254,6 +1255,11 @@ showdown.subParser('escapeSpecialCharsWithinTagAttributes', function (text) {
 showdown.subParser('githubCodeBlocks', function (text, options, globals) {
 showdown.subParser('githubCodeBlocks', function (text, options, globals) {
   'use strict';
   'use strict';
 
 
+  // early exit if option is not enabled
+  if (!options.ghCodeBlocks) {
+    return text;
+  }
+
   text += '~0';
   text += '~0';
 
 
   text = text.replace(/(?:^|\n)```(.*)\n([\s\S]*?)\n```/g, function (wholeMatch, m1, m2) {
   text = text.replace(/(?:^|\n)```(.*)\n([\s\S]*?)\n```/g, function (wholeMatch, m1, m2) {

文件差异内容过多而无法显示
+ 0 - 0
dist/showdown.js.map


文件差异内容过多而无法显示
+ 0 - 0
dist/showdown.min.js


文件差异内容过多而无法显示
+ 0 - 0
dist/showdown.min.js.map


+ 2 - 1
src/showdown.js

@@ -16,7 +16,8 @@ var showdown = {},
       literalMidWordUnderscores: false,
       literalMidWordUnderscores: false,
       strikethrough:             false,
       strikethrough:             false,
       tables:                    false,
       tables:                    false,
-      tablesHeaderId:            false
+      tablesHeaderId:            false,
+      ghCodeBlocks:              true  // true due to historical reasons
     },
     },
     globalOptions = JSON.parse(JSON.stringify(defaultOptions)); //clone default options out of laziness =P
     globalOptions = JSON.parse(JSON.stringify(defaultOptions)); //clone default options out of laziness =P
 
 

+ 5 - 0
src/subParsers/githubCodeBlocks.js

@@ -11,6 +11,11 @@
 showdown.subParser('githubCodeBlocks', function (text, options, globals) {
 showdown.subParser('githubCodeBlocks', function (text, options, globals) {
   'use strict';
   'use strict';
 
 
+  // early exit if option is not enabled
+  if (!options.ghCodeBlocks) {
+    return text;
+  }
+
   text += '~0';
   text += '~0';
 
 
   text = text.replace(/(?:^|\n)```(.*)\n([\s\S]*?)\n```/g, function (wholeMatch, m1, m2) {
   text = text.replace(/(?:^|\n)```(.*)\n([\s\S]*?)\n```/g, function (wholeMatch, m1, m2) {

+ 9 - 0
test/features/disable_gh_codeblocks.html

@@ -0,0 +1,9 @@
+<p>this is some text</p>
+
+<p><code>php
+function thisThing() {
+echo "some weird formatted code!";
+}
+</code></p>
+
+<p>some other text</p>

+ 9 - 0
test/features/disable_gh_codeblocks.md

@@ -0,0 +1,9 @@
+this is some text
+
+```php
+function thisThing() {
+  echo "some weird formatted code!";
+}
+```
+
+some other text

+ 2 - 1
test/node/showdown.js

@@ -27,7 +27,8 @@ describe('showdown.options', function () {
         literalMidWordUnderscores: false,
         literalMidWordUnderscores: false,
         strikethrough:             false,
         strikethrough:             false,
         tables:                    false,
         tables:                    false,
-        tablesHeaderId:            false
+        tablesHeaderId:            false,
+        ghCodeBlocks:              true
       };
       };
       expect(showdown.getDefaultOptions()).to.be.eql(opts);
       expect(showdown.getDefaultOptions()).to.be.eql(opts);
     });
     });

+ 2 - 0
test/node/testsuite.features.js

@@ -21,6 +21,8 @@ describe('makeHtml() features testsuite', function () {
       converter = new showdown.Converter({literalMidWordUnderscores: true});
       converter = new showdown.Converter({literalMidWordUnderscores: true});
     } else if (testsuite[i].name === '#164.3.strikethrough') {
     } else if (testsuite[i].name === '#164.3.strikethrough') {
       converter = new showdown.Converter({strikethrough: true});
       converter = new showdown.Converter({strikethrough: true});
+    }  else if (testsuite[i].name === 'disable_gh_codeblocks') {
+      converter = new showdown.Converter({ghCodeBlocks: false});
     } else {
     } else {
       converter = new showdown.Converter();
       converter = new showdown.Converter();
     }
     }

部分文件因为文件数量过多而无法显示