diff --git a/dist/showdown.js b/dist/showdown.js index 20628cf..4a793b6 100644 Binary files a/dist/showdown.js and b/dist/showdown.js differ diff --git a/dist/showdown.js.map b/dist/showdown.js.map index 37bf9f2..70148e0 100644 Binary files a/dist/showdown.js.map and b/dist/showdown.js.map differ diff --git a/dist/showdown.min.js b/dist/showdown.min.js index 8114fd9..9bf7da0 100644 Binary files a/dist/showdown.min.js and b/dist/showdown.min.js differ diff --git a/dist/showdown.min.js.map b/dist/showdown.min.js.map index 15e9b46..21e0a5b 100644 Binary files a/dist/showdown.min.js.map and b/dist/showdown.min.js.map differ diff --git a/src/options.js b/src/options.js index 70c5f7e..2e8f81b 100644 --- a/src/options.js +++ b/src/options.js @@ -26,6 +26,11 @@ function getDefaultOpts (simple) { describe: 'Generate header ids compatible with github style (spaces are replaced with dashes, a bunch of non alphanumeric chars are removed)', type: 'boolean' }, + rawHeaderId: { + defaultValue: false, + describe: 'Remove only spaces, \' and " from generated header ids (including prefixes), replacing them with dashes (-). WARNING: This might result in malformed ids', + type: 'boolean' + }, headerLevelStart: { defaultValue: false, describe: 'The header blocks level start', diff --git a/src/subParsers/headers.js b/src/subParsers/headers.js index 1156358..3d3e003 100644 --- a/src/subParsers/headers.js +++ b/src/subParsers/headers.js @@ -4,7 +4,6 @@ showdown.subParser('headers', function (text, options, globals) { text = globals.converter._dispatch('headers.before', text, options, globals); var headerLevelStart = (isNaN(parseInt(options.headerLevelStart))) ? 1 : parseInt(options.headerLevelStart), - ghHeaderId = options.ghCompatibleHeaderId, // Set text-style headers: // Header 1 @@ -76,7 +75,7 @@ showdown.subParser('headers', function (text, options, globals) { title = m; } - if (ghHeaderId) { + if (options.ghCompatibleHeaderId) { title = title .replace(/ /g, '-') // replace previously escaped chars (&, ¨ and $) @@ -87,6 +86,16 @@ showdown.subParser('headers', function (text, options, globals) { // borrowed from github's redcarpet (some they should produce similar results) .replace(/[&+$,\/:;=?@"#{}|^¨~\[\]`\\*)(%.!'<>]/g, '') .toLowerCase(); + } else if (options.rawHeaderId) { + title = title + .replace(/ /g, '-') + // replace previously escaped chars (&, ¨ and $) + .replace(/&/g, '&') + .replace(/¨T/g, '¨') + .replace(/¨D/g, '$') + // replace " and ' + .replace(/["']/g, '-') + .toLowerCase(); } else { title = title .replace(/[^\w]/g, '') diff --git a/test/features/rawHeaderId/simple.html b/test/features/rawHeaderId/simple.html new file mode 100644 index 0000000..c6022c2 --- /dev/null +++ b/test/features/rawHeaderId/simple.html @@ -0,0 +1 @@ +

123 My#very/ strange \header*`^ªº-_., yeah

diff --git a/test/features/rawHeaderId/simple.md b/test/features/rawHeaderId/simple.md new file mode 100644 index 0000000..60c4f03 --- /dev/null +++ b/test/features/rawHeaderId/simple.md @@ -0,0 +1 @@ +# 123 My#very/ strange \header*`^ªº-_., yeah diff --git a/test/features/rawHeaderId/with-prefixHeaderId.html b/test/features/rawHeaderId/with-prefixHeaderId.html new file mode 100644 index 0000000..21ed9be --- /dev/null +++ b/test/features/rawHeaderId/with-prefixHeaderId.html @@ -0,0 +1,2 @@ +

some header

+

another !"#$%&/()=?»@£§{[]}«' header

diff --git a/test/features/rawHeaderId/with-prefixHeaderId.md b/test/features/rawHeaderId/with-prefixHeaderId.md new file mode 100644 index 0000000..8e087d7 --- /dev/null +++ b/test/features/rawHeaderId/with-prefixHeaderId.md @@ -0,0 +1,3 @@ +# some header + +# another !"#$%&/()=?»@£§{[]}«' header diff --git a/test/node/testsuite.features.js b/test/node/testsuite.features.js index e6aa433..32661e2 100644 --- a/test/node/testsuite.features.js +++ b/test/node/testsuite.features.js @@ -8,7 +8,8 @@ var bootstrap = require('../bootstrap.js'), tableSuite = bootstrap.getTestSuite('test/features/tables/'), simplifiedAutoLinkSuite = bootstrap.getTestSuite('test/features/simplifiedAutoLink/'), openLinksInNewWindowSuite = bootstrap.getTestSuite('test/features/openLinksInNewWindow/'), - disableForced4SpacesIndentedSublistsSuite = bootstrap.getTestSuite('test/features/disableForced4SpacesIndentedSublists/'); + disableForced4SpacesIndentedSublistsSuite = bootstrap.getTestSuite('test/features/disableForced4SpacesIndentedSublists/'), + html5CompatibleHeaderIdSuite = bootstrap.getTestSuite('test/features/rawHeaderId/'); describe('makeHtml() features testsuite', function () { 'use strict'; @@ -152,4 +153,18 @@ describe('makeHtml() features testsuite', function () { it(suite[i].name.replace(/-/g, ' '), assertion(suite[i], converter)); } }); + + // test rawHeaderId support + describe('rawHeaderId support', function () { + var converter, + suite = html5CompatibleHeaderIdSuite; + for (var i = 0; i < suite.length; ++i) { + if (suite[i].name === 'with-prefixHeaderId') { + converter = new showdown.Converter({rawHeaderId: true, prefixHeaderId: '/prefix/'}); + } else { + converter = new showdown.Converter({rawHeaderId: true}); + } + it(suite[i].name.replace(/-/g, ' '), assertion(suite[i], converter)); + } + }); });