Эх сурвалжийг харах

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 жил өмнө
parent
commit
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();
     }

Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно