瀏覽代碼

fix(headerLevelStart): fix for NaN error when specifying a non number as headerLevelStart param

Estevão Soares dos Santos 10 年之前
父節點
當前提交
be72b4879f
共有 7 個文件被更改,包括 23 次插入33 次删除
  1. 1 0
      .gitignore
  2. 11 10
      dist/showdown.js
  3. 0 0
      dist/showdown.js.map
  4. 1 1
      dist/showdown.min.js
  5. 0 0
      dist/showdown.min.js.map
  6. 10 9
      src/subParsers/headers.js
  7. 0 13
      test/single.test.wrapper.js

+ 1 - 0
.gitignore

@@ -4,3 +4,4 @@
 node_modules
 npm-debug.log
 localtest.html
+/*.test.*

+ 11 - 10
dist/showdown.js

@@ -1,4 +1,4 @@
-;/*! showdown 12-07-2015 */
+;/*! showdown 13-07-2015 */
 (function(){
 /**
  * Created by Tivie on 06-01-2015.
@@ -1497,7 +1497,8 @@ showdown.subParser('hashHTMLBlocks', function (text, options, globals) {
 showdown.subParser('headers', function (text, options, globals) {
   'use strict';
 
-  var prefixHeader = options.prefixHeaderId;
+  var prefixHeader = options.prefixHeaderId,
+    headerLevelStart = (isNaN(parseInt(options.headerLevelStart))) ? 1 : parseInt(options.headerLevelStart);
 
   // Set text-style headers:
   //	Header 1
@@ -1509,16 +1510,16 @@ showdown.subParser('headers', function (text, options, globals) {
   text = text.replace(/^(.+)[ \t]*\n=+[ \t]*\n+/gm, function (wholeMatch, m1) {
 
     var spanGamut = showdown.subParser('spanGamut')(m1, options, globals),
-        hID = (options.noHeaderId) ? '' : ' id="' + headerId(m1) + '"',
-        hLevel = parseInt(options.headerLevelStart),
-        hashBlock = '<h' + hLevel + hID + '>' + spanGamut + '</h' + hLevel + '>';
+      hID = (options.noHeaderId) ? '' : ' id="' + headerId(m1) + '"',
+      hLevel = headerLevelStart,
+      hashBlock = '<h' + hLevel + hID + '>' + spanGamut + '</h' + hLevel + '>';
     return showdown.subParser('hashBlock')(hashBlock, options, globals);
   });
 
   text = text.replace(/^(.+)[ \t]*\n-+[ \t]*\n+/gm, function (matchFound, m1) {
     var spanGamut = showdown.subParser('spanGamut')(m1, options, globals),
-        hID = (options.noHeaderId) ? '' : ' id="' + headerId(m1) + '"',
-        hLevel = parseInt(options.headerLevelStart) + 1,
+      hID = (options.noHeaderId) ? '' : ' id="' + headerId(m1) + '"',
+      hLevel = headerLevelStart + 1,
       hashBlock = '<h' + hLevel + hID + '>' + spanGamut + '</h' + hLevel + '>';
     return showdown.subParser('hashBlock')(hashBlock, options, globals);
   });
@@ -1544,9 +1545,9 @@ showdown.subParser('headers', function (text, options, globals) {
 
   text = text.replace(/^(#{1,6})[ \t]*(.+?)[ \t]*#*\n+/gm, function (wholeMatch, m1, m2) {
     var span = showdown.subParser('spanGamut')(m2, options, globals),
-        hID = (options.noHeaderId) ? '' : ' id="' + headerId(m2) + '"',
-        hLevel = parseInt(options.headerLevelStart) - 1 + m1.length,
-        header = '<h' + hLevel + hID + '>' + span + '</h' + hLevel + '>';
+      hID = (options.noHeaderId) ? '' : ' id="' + headerId(m2) + '"',
+      hLevel = headerLevelStart - 1 + m1.length,
+      header = '<h' + hLevel + hID + '>' + span + '</h' + hLevel + '>';
 
     return showdown.subParser('hashBlock')(header, options, globals);
   });

文件差異過大導致無法顯示
+ 0 - 0
dist/showdown.js.map


文件差異過大導致無法顯示
+ 1 - 1
dist/showdown.min.js


文件差異過大導致無法顯示
+ 0 - 0
dist/showdown.min.js.map


+ 10 - 9
src/subParsers/headers.js

@@ -1,7 +1,8 @@
 showdown.subParser('headers', function (text, options, globals) {
   'use strict';
 
-  var prefixHeader = options.prefixHeaderId;
+  var prefixHeader = options.prefixHeaderId,
+    headerLevelStart = (isNaN(parseInt(options.headerLevelStart))) ? 1 : parseInt(options.headerLevelStart);
 
   // Set text-style headers:
   //	Header 1
@@ -13,16 +14,16 @@ showdown.subParser('headers', function (text, options, globals) {
   text = text.replace(/^(.+)[ \t]*\n=+[ \t]*\n+/gm, function (wholeMatch, m1) {
 
     var spanGamut = showdown.subParser('spanGamut')(m1, options, globals),
-        hID = (options.noHeaderId) ? '' : ' id="' + headerId(m1) + '"',
-        hLevel = parseInt(options.headerLevelStart),
-        hashBlock = '<h' + hLevel + hID + '>' + spanGamut + '</h' + hLevel + '>';
+      hID = (options.noHeaderId) ? '' : ' id="' + headerId(m1) + '"',
+      hLevel = headerLevelStart,
+      hashBlock = '<h' + hLevel + hID + '>' + spanGamut + '</h' + hLevel + '>';
     return showdown.subParser('hashBlock')(hashBlock, options, globals);
   });
 
   text = text.replace(/^(.+)[ \t]*\n-+[ \t]*\n+/gm, function (matchFound, m1) {
     var spanGamut = showdown.subParser('spanGamut')(m1, options, globals),
-        hID = (options.noHeaderId) ? '' : ' id="' + headerId(m1) + '"',
-        hLevel = parseInt(options.headerLevelStart) + 1,
+      hID = (options.noHeaderId) ? '' : ' id="' + headerId(m1) + '"',
+      hLevel = headerLevelStart + 1,
       hashBlock = '<h' + hLevel + hID + '>' + spanGamut + '</h' + hLevel + '>';
     return showdown.subParser('hashBlock')(hashBlock, options, globals);
   });
@@ -48,9 +49,9 @@ showdown.subParser('headers', function (text, options, globals) {
 
   text = text.replace(/^(#{1,6})[ \t]*(.+?)[ \t]*#*\n+/gm, function (wholeMatch, m1, m2) {
     var span = showdown.subParser('spanGamut')(m2, options, globals),
-        hID = (options.noHeaderId) ? '' : ' id="' + headerId(m2) + '"',
-        hLevel = parseInt(options.headerLevelStart) - 1 + m1.length,
-        header = '<h' + hLevel + hID + '>' + span + '</h' + hLevel + '>';
+      hID = (options.noHeaderId) ? '' : ' id="' + headerId(m2) + '"',
+      hLevel = headerLevelStart - 1 + m1.length,
+      header = '<h' + hLevel + hID + '>' + span + '</h' + hLevel + '>';
 
     return showdown.subParser('hashBlock')(header, options, globals);
   });

+ 0 - 13
test/single.test.wrapper.js

@@ -1,13 +0,0 @@
-/**
- * Created by Estevao on 10-07-2015.
- */
-/*
-var showdown = require('../dist/showdown.js'),
-  bootstrap = require('./bootstrap.js'),
-  assertion = bootstrap.assertion,
-  testsuite = bootstrap.getTestSuite('test/features/');
-
-describe('makeHtml() single test', function () {
-  'use strict';
-});
-*/

部分文件因文件數量過多而無法顯示