Bläddra i källkod

refactor: create horizontal rules own subParser

Estevao Soares dos Santos 8 år sedan
förälder
incheckning
4613260cdf

+ 17 - 4
dist/showdown.js

@@ -1407,10 +1407,7 @@ showdown.subParser('blockGamut', function (text, options, globals) {
   text = showdown.subParser('headers')(text, options, globals);
 
   // Do Horizontal Rules:
-  var key = showdown.subParser('hashBlock')('<hr />', options, globals);
-  text = text.replace(/^ {0,2}( ?-){3,}[ \t]*$/gm, key);
-  text = text.replace(/^ {0,2}( ?\*){3,}[ \t]*$/gm, key);
-  text = text.replace(/^ {0,2}( ?_){3,}[ \t]*$/gm, key);
+  text = showdown.subParser('horizontalRule')(text, options, globals);
 
   text = showdown.subParser('lists')(text, options, globals);
   text = showdown.subParser('codeBlocks')(text, options, globals);
@@ -1957,6 +1954,22 @@ showdown.subParser('headers', function (text, options, globals) {
   return text;
 });
 
+/**
+ * Turn Markdown link shortcuts into XHTML <a> tags.
+ */
+showdown.subParser('horizontalRule', function (text, options, globals) {
+  'use strict';
+  text = globals.converter._dispatch('horizontalRule.before', text, options, globals);
+
+  var key = showdown.subParser('hashBlock')('<hr />', options, globals);
+  text = text.replace(/^ {0,2}( ?-){3,}[ \t]*$/gm, key);
+  text = text.replace(/^ {0,2}( ?\*){3,}[ \t]*$/gm, key);
+  text = text.replace(/^ {0,2}( ?_){3,}[ \t]*$/gm, key);
+
+  text = globals.converter._dispatch('horizontalRule.after', text, options, globals);
+  return text;
+});
+
 /**
  * Turn Markdown image shortcuts into <img> tags.
  */

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 0 - 0
dist/showdown.js.map


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 0 - 0
dist/showdown.min.js


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 0 - 0
dist/showdown.min.js.map


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 0 - 0
performance.json


+ 31 - 31
performance.log.md

@@ -6,41 +6,41 @@
 ### Test Suite: Basic (50 cycles)
 | test | avgTime | max | min |
 |:-----|--------:|----:|----:|
-|Simple "Hello World"|0.311|5.505|0.157|
-|readme.md|25.527|48.200|23.654|
+|Simple "Hello World"|0.330|5.345|0.168|
+|readme.md|25.823|46.558|23.516|
 
 ### Test Suite: subParsers (20 cycles)
 | test | avgTime | max | min |
 |:-----|--------:|----:|----:|
-|hashHTMLBlocks|2.571|7.892|1.848|
-|anchors|0.500|4.097|0.272|
-|autoLinks|0.093|0.220|0.071|
-|blockGamut|16.474|22.569|13.148|
-|blockQuotes|3.115|5.541|2.719|
-|codeBlocks|0.284|1.167|0.173|
-|codeSpans|0.209|0.453|0.174|
-|detab|0.095|0.135|0.088|
-|encodeAmpsAndAngles|0.047|0.074|0.037|
-|encodeBackslashEscapes|0.074|0.112|0.068|
-|encodeCode|0.544|1.438|0.480|
-|escapeSpecialCharsWithinTagAttributes|0.359|0.446|0.330|
-|githubCodeBlocks|0.199|0.779|0.146|
-|hashBlock|0.120|1.556|0.037|
-|hashElement|0.002|0.034|0.000|
-|hashHTMLSpans|0.354|1.562|0.255|
-|hashPreCodeTags|0.132|0.233|0.114|
-|headers|0.838|2.014|0.724|
-|images|0.156|0.825|0.088|
-|italicsAndBold|0.099|0.198|0.090|
-|lists|4.856|5.639|4.491|
-|outdent|0.181|0.576|0.141|
-|paragraphs|6.092|9.738|3.413|
-|spanGamut|2.472|4.012|1.641|
-|strikethrough|0.004|0.082|0.000|
-|stripBlankLines|0.118|0.138|0.089|
-|stripLinkDefinitions|0.205|0.520|0.148|
-|tables|0.007|0.117|0.000|
-|unescapeSpecialChars|0.011|0.055|0.007|
+|hashHTMLBlocks|2.599|8.291|1.929|
+|anchors|0.519|4.014|0.272|
+|autoLinks|0.089|0.193|0.071|
+|blockQuotes|3.127|6.063|2.751|
+|codeBlocks|0.178|0.294|0.168|
+|codeSpans|0.233|0.569|0.178|
+|detab|0.129|0.796|0.087|
+|encodeAmpsAndAngles|0.042|0.076|0.037|
+|encodeBackslashEscapes|0.072|0.104|0.068|
+|encodeCode|0.529|0.826|0.484|
+|escapeSpecialCharsWithinTagAttributes|0.359|0.444|0.325|
+|githubCodeBlocks|0.189|0.776|0.141|
+|hashBlock|0.056|0.343|0.037|
+|hashElement|0.002|0.028|0.000|
+|hashHTMLSpans|0.599|3.072|0.248|
+|hashPreCodeTags|0.200|0.343|0.132|
+|headers|1.069|1.445|0.934|
+|horizontalRule|0.310|1.091|0.198|
+|images|0.192|0.310|0.116|
+|italicsAndBold|0.194|0.243|0.141|
+|lists|5.782|9.187|4.470|
+|outdent|0.158|0.226|0.141|
+|paragraphs|3.712|4.484|3.384|
+|spanGamut|1.586|2.240|1.380|
+|strikethrough|0.002|0.042|0.000|
+|stripBlankLines|0.089|0.119|0.083|
+|stripLinkDefinitions|0.170|0.279|0.143|
+|tables|0.003|0.036|0.000|
+|unescapeSpecialChars|0.008|0.038|0.006|
 
 
 ## [version 1.6.0](https://github.com/showdownjs/showdown/tree/1.6.0)

+ 1 - 4
src/subParsers/blockGamut.js

@@ -13,10 +13,7 @@ showdown.subParser('blockGamut', function (text, options, globals) {
   text = showdown.subParser('headers')(text, options, globals);
 
   // Do Horizontal Rules:
-  var key = showdown.subParser('hashBlock')('<hr />', options, globals);
-  text = text.replace(/^ {0,2}( ?-){3,}[ \t]*$/gm, key);
-  text = text.replace(/^ {0,2}( ?\*){3,}[ \t]*$/gm, key);
-  text = text.replace(/^ {0,2}( ?_){3,}[ \t]*$/gm, key);
+  text = showdown.subParser('horizontalRule')(text, options, globals);
 
   text = showdown.subParser('lists')(text, options, globals);
   text = showdown.subParser('codeBlocks')(text, options, globals);

+ 15 - 0
src/subParsers/horizontalRule.js

@@ -0,0 +1,15 @@
+/**
+ * Turn Markdown link shortcuts into XHTML <a> tags.
+ */
+showdown.subParser('horizontalRule', function (text, options, globals) {
+  'use strict';
+  text = globals.converter._dispatch('horizontalRule.before', text, options, globals);
+
+  var key = showdown.subParser('hashBlock')('<hr />', options, globals);
+  text = text.replace(/^ {0,2}( ?-){3,}[ \t]*$/gm, key);
+  text = text.replace(/^ {0,2}( ?\*){3,}[ \t]*$/gm, key);
+  text = text.replace(/^ {0,2}( ?_){3,}[ \t]*$/gm, key);
+
+  text = globals.converter._dispatch('horizontalRule.after', text, options, globals);
+  return text;
+});

+ 36 - 31
test/node/performance.js

@@ -29,7 +29,7 @@ var globals = {
   options = showdown.getOptions();
 
 function runTests() {
-  var readmeMD = fs.readFileSync('test/performance.testfile.md', 'utf8');
+  var testMDFile = fs.readFileSync('test/performance.testfile.md', 'utf8');
   new performance.Suite('Basic')
     .setOption('cycles', 50)
     .add('Simple "Hello World"', function () {
@@ -37,7 +37,7 @@ function runTests() {
     })
     .add('readme.md', {
       prepare: function () {
-        return readmeMD;
+        return testMDFile;
       },
       test: function (mdText) {
         converter.makeHtml(mdText);
@@ -46,91 +46,96 @@ function runTests() {
   new performance.Suite('subParsers')
     .setOption('cycles', 20)
     .add('hashHTMLBlocks', function () {
-      showdown.subParser('hashHTMLBlocks')(readmeMD, options, globals);
+      showdown.subParser('hashHTMLBlocks')(testMDFile, options, globals);
     })
     .add('anchors', function () {
-      showdown.subParser('anchors')(readmeMD, options, globals);
+      showdown.subParser('anchors')(testMDFile, options, globals);
     })
     .add('autoLinks', function () {
-      showdown.subParser('autoLinks')(readmeMD, options, globals);
+      showdown.subParser('autoLinks')(testMDFile, options, globals);
     })
+    /*
     .add('blockGamut', function () {
-      showdown.subParser('blockGamut')(readmeMD, options, globals);
+      showdown.subParser('blockGamut')(testMDFile, options, globals);
     })
+    */
     .add('blockQuotes', function () {
-      showdown.subParser('blockQuotes')(readmeMD, options, globals);
+      showdown.subParser('blockQuotes')(testMDFile, options, globals);
     })
     .add('codeBlocks', function () {
-      showdown.subParser('codeBlocks')(readmeMD, options, globals);
+      showdown.subParser('codeBlocks')(testMDFile, options, globals);
     })
     .add('codeSpans', function () {
-      showdown.subParser('codeSpans')(readmeMD, options, globals);
+      showdown.subParser('codeSpans')(testMDFile, options, globals);
     })
     .add('detab', function () {
-      showdown.subParser('detab')(readmeMD, options, globals);
+      showdown.subParser('detab')(testMDFile, options, globals);
     })
     .add('encodeAmpsAndAngles', function () {
-      showdown.subParser('encodeAmpsAndAngles')(readmeMD, options, globals);
+      showdown.subParser('encodeAmpsAndAngles')(testMDFile, options, globals);
     })
     .add('encodeBackslashEscapes', function () {
-      showdown.subParser('encodeBackslashEscapes')(readmeMD, options, globals);
+      showdown.subParser('encodeBackslashEscapes')(testMDFile, options, globals);
     })
     .add('encodeCode', function () {
-      showdown.subParser('encodeCode')(readmeMD, options, globals);
+      showdown.subParser('encodeCode')(testMDFile, options, globals);
     })
     .add('escapeSpecialCharsWithinTagAttributes', function () {
-      showdown.subParser('escapeSpecialCharsWithinTagAttributes')(readmeMD, options, globals);
+      showdown.subParser('escapeSpecialCharsWithinTagAttributes')(testMDFile, options, globals);
     })
     .add('githubCodeBlocks', function () {
-      showdown.subParser('githubCodeBlocks')(readmeMD, options, globals);
+      showdown.subParser('githubCodeBlocks')(testMDFile, options, globals);
     })
     .add('hashBlock', function () {
-      showdown.subParser('hashBlock')(readmeMD, options, globals);
+      showdown.subParser('hashBlock')(testMDFile, options, globals);
     })
     .add('hashElement', function () {
-      showdown.subParser('hashElement')(readmeMD, options, globals);
+      showdown.subParser('hashElement')(testMDFile, options, globals);
     })
     .add('hashHTMLSpans', function () {
-      showdown.subParser('hashHTMLSpans')(readmeMD, options, globals);
+      showdown.subParser('hashHTMLSpans')(testMDFile, options, globals);
     })
     .add('hashPreCodeTags', function () {
-      showdown.subParser('hashPreCodeTags')(readmeMD, options, globals);
+      showdown.subParser('hashPreCodeTags')(testMDFile, options, globals);
     })
     .add('headers', function () {
-      showdown.subParser('headers')(readmeMD, options, globals);
+      showdown.subParser('headers')(testMDFile, options, globals);
+    })
+    .add('horizontalRule', function () {
+      showdown.subParser('horizontalRule')(testMDFile, options, globals);
     })
     .add('images', function () {
-      showdown.subParser('images')(readmeMD, options, globals);
+      showdown.subParser('images')(testMDFile, options, globals);
     })
     .add('italicsAndBold', function () {
-      showdown.subParser('italicsAndBold')(readmeMD, options, globals);
+      showdown.subParser('italicsAndBold')(testMDFile, options, globals);
     })
     .add('lists', function () {
-      showdown.subParser('lists')(readmeMD, options, globals);
+      showdown.subParser('lists')(testMDFile, options, globals);
     })
     .add('outdent', function () {
-      showdown.subParser('outdent')(readmeMD, options, globals);
+      showdown.subParser('outdent')(testMDFile, options, globals);
     })
     .add('paragraphs', function () {
-      showdown.subParser('paragraphs')(readmeMD, options, globals);
+      showdown.subParser('paragraphs')(testMDFile, options, globals);
     })
     .add('spanGamut', function () {
-      showdown.subParser('spanGamut')(readmeMD, options, globals);
+      showdown.subParser('spanGamut')(testMDFile, options, globals);
     })
     .add('strikethrough', function () {
-      showdown.subParser('strikethrough')(readmeMD, options, globals);
+      showdown.subParser('strikethrough')(testMDFile, options, globals);
     })
     .add('stripBlankLines', function () {
-      showdown.subParser('stripBlankLines')(readmeMD, options, globals);
+      showdown.subParser('stripBlankLines')(testMDFile, options, globals);
     })
     .add('stripLinkDefinitions', function () {
-      showdown.subParser('stripLinkDefinitions')(readmeMD, options, globals);
+      showdown.subParser('stripLinkDefinitions')(testMDFile, options, globals);
     })
     .add('tables', function () {
-      showdown.subParser('tables')(readmeMD, options, globals);
+      showdown.subParser('tables')(testMDFile, options, globals);
     })
     .add('unescapeSpecialChars', function () {
-      showdown.subParser('unescapeSpecialChars')(readmeMD, options, globals);
+      showdown.subParser('unescapeSpecialChars')(testMDFile, options, globals);
     });
 }
 

Vissa filer visades inte eftersom för många filer har ändrats