소스 검색

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,
       strikethrough:             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
 
@@ -1254,6 +1255,11 @@ showdown.subParser('escapeSpecialCharsWithinTagAttributes', function (text) {
 showdown.subParser('githubCodeBlocks', function (text, options, globals) {
   'use strict';
 
+  // early exit if option is not enabled
+  if (!options.ghCodeBlocks) {
+    return text;
+  }
+
   text += '~0';
 
   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,
       strikethrough:             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
 

+ 5 - 0
src/subParsers/githubCodeBlocks.js

@@ -11,6 +11,11 @@
 showdown.subParser('githubCodeBlocks', function (text, options, globals) {
   'use strict';
 
+  // early exit if option is not enabled
+  if (!options.ghCodeBlocks) {
+    return text;
+  }
+
   text += '~0';
 
   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,
         strikethrough:             false,
         tables:                    false,
-        tablesHeaderId:            false
+        tablesHeaderId:            false,
+        ghCodeBlocks:              true
       };
       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});
     } else if (testsuite[i].name === '#164.3.strikethrough') {
       converter = new showdown.Converter({strikethrough: true});
+    }  else if (testsuite[i].name === 'disable_gh_codeblocks') {
+      converter = new showdown.Converter({ghCodeBlocks: false});
     } else {
       converter = new showdown.Converter();
     }

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.