Skip to content

Commit

Permalink
feat(noHeaderId): add option to suppress automatic generation of ids …
Browse files Browse the repository at this point in the history
…in headers

Passing the option `noHeaderId; true` to showdown or showdown converter removes the automatic generation of header ids
  • Loading branch information
tivie committed Jun 8, 2015
1 parent dcbdc61 commit 7ac893e
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 15 deletions.
18 changes: 12 additions & 6 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.

3 changes: 2 additions & 1 deletion src/converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ showdown.Converter = function (converterOptions) {
*/
options = {
omitExtraWLInCodeBlocks: false,
prefixHeaderId: false
prefixHeaderId: false,
noHeaderId: false
},

/**
Expand Down
3 changes: 2 additions & 1 deletion src/showdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ var showdown = {},
extensions = {},
defaultOptions = {
omitExtraWLInCodeBlocks: false,
prefixHeaderId: false
prefixHeaderId: false,
noHeaderId: false
},
globalOptions = JSON.parse(JSON.stringify(defaultOptions)); //clone default options out of laziness =P

Expand Down
10 changes: 7 additions & 3 deletions src/subParsers/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ 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),
hashBlock = '<h1 id="' + headerId(m1) + '">' + spanGamut + '</h1>';
hID = (options.noHeaderId) ? '' : 'id="' + headerId(m1) + '"',
hashBlock = '<h1' + hID + '>' + spanGamut + '</h1>';
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),
hashBlock = '<h2 id="' + headerId(m1) + '">' + spanGamut + '</h2>';
hID = (options.noHeaderId) ? '' : 'id="' + headerId(m1) + '"',
hashBlock = '<h2' + hID + '>' + spanGamut + '</h2>';
return showdown.subParser('hashBlock')(hashBlock, options, globals);
});

Expand All @@ -43,7 +46,8 @@ 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),
header = '<h' + m1.length + ' id="' + headerId(m2) + '">' + span + '</h' + m1.length + '>';
hID = (options.noHeaderId) ? '' : 'id="' + headerId(m1) + '"',
header = '<h' + m1.length + hID + '>' + span + '</h' + m1.length + '>';

return showdown.subParser('hashBlock')(header, options, globals);
});
Expand Down

0 comments on commit 7ac893e

Please sign in to comment.