Skip to content

Commit

Permalink
fix(headerLevelStart): fix for NaN error when specifying a non number…
Browse files Browse the repository at this point in the history
… as headerLevelStart param
  • Loading branch information
tivie committed Jul 13, 2015
1 parent 7e55bce commit be72b48
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 36 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
node_modules
npm-debug.log
localtest.html
/*.test.*
21 changes: 11 additions & 10 deletions dist/showdown.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/showdown.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/showdown.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/showdown.min.js.map

Large diffs are not rendered by default.

19 changes: 10 additions & 9 deletions src/subParsers/headers.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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);
});
Expand All @@ -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);
});
Expand Down
13 changes: 0 additions & 13 deletions test/single.test.wrapper.js

This file was deleted.

0 comments on commit be72b48

Please sign in to comment.