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 @@ +