Skip to content

Commit

Permalink
fix(ghCompatibleHeaderId): improve the number of removed chars
Browse files Browse the repository at this point in the history
  • Loading branch information
tivie committed Dec 30, 2016
1 parent 150a5cd commit d499feb
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ var defaultOptions = showdown.getDefaultOptions();
* **noHeaderId**: (boolean) [default false] Disable the automatic generation of header ids. Setting to true overrides **prefixHeaderId**
* **ghCompatibleHeaderId**: (boolean) [default false] Generate header ids compatible with github style (spaces are replaced with dashes, ][&~$!@#*()=:/,;?+'.%\ chars are removed) (since v1.5.5)
* **ghCompatibleHeaderId**: (boolean) [default false] Generate header ids compatible with github style (spaces are replaced with dashes and a bunch of non alphanumeric chars are removed) (since v1.5.5)
* **prefixHeaderId**: (string/boolean) [default false] Add a prefix to the generated header ids. Passing a string will prefix that string to the header id. Setting to `true` will add a generic 'section' prefix.
Expand Down
5 changes: 3 additions & 2 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.

2 changes: 1 addition & 1 deletion 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.

2 changes: 1 addition & 1 deletion src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function getDefaultOpts(simple) {
},
ghCompatibleHeaderId: {
defaultValue: false,
describe: 'Generate header ids compatible with github style (spaces are replaced with dashes, &~$!@#*()=:/,;?+%\\\'. chars are removed)',
describe: 'Generate header ids compatible with github style (spaces are replaced with dashes, a bunch of non alphanumeric chars are removed)',
type: 'string'
},
headerLevelStart: {
Expand Down
3 changes: 2 additions & 1 deletion src/subParsers/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ showdown.subParser('headers', function (text, options, globals) {
.replace(/~T/g, '')
.replace(/~D/g, '')
//replace rest of the chars (&~$ are repeated as they might have been escaped)
.replace(/[&~$!@#*()=:/,;?+'.%\\]/g, '')
// borrowed from github's redcarpet (some they should produce similar results)
.replace(/[&+$,\/:;=?@"#{}|^~\[\]`\\*)(%.!'<>]/g, '')
.toLowerCase();
} else {
escapedId = m.replace(/[^\w]/g, '').toLowerCase();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
<h1 id="some-header">some header</h1>
<h1 id="some-header-with--chars">some header with ~!@#$&amp;*()=:/,;?+'.\ chars</h1>
<h1 id="some-header-with--chars">some header with &amp;+$,/:;=?@\"#{}|^~[]`\*()%.!' chars</h1>
<h1 id="another-header--with--chars">another header > with &lt; chars</h1>
4 changes: 3 additions & 1 deletion test/features/#320.github-compatible-generated-header-id.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# some header

# some header with ~!@#$&*()=:/,;?+'.\ chars
# some header with &+$,/:;=?@\"#{}|^~[]`\\*()%.!' chars

# another header > with < chars

0 comments on commit d499feb

Please sign in to comment.