浏览代码

fix(ghCompatibleHeaderId): improve the number of removed chars

Estevao Soares dos Santos 8 年之前
父节点
当前提交
d499feb2aa

+ 1 - 1
README.md

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

+ 3 - 2
dist/showdown.js

@@ -25,7 +25,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: {
@@ -1850,7 +1850,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();

文件差异内容过多而无法显示
+ 0 - 0
dist/showdown.js.map


文件差异内容过多而无法显示
+ 0 - 0
dist/showdown.min.js


文件差异内容过多而无法显示
+ 0 - 0
dist/showdown.min.js.map


+ 1 - 1
src/options.js

@@ -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: {

+ 2 - 1
src/subParsers/headers.js

@@ -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();

+ 2 - 1
test/features/#320.github-compatible-generated-header-id.html

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

+ 3 - 1
test/features/#320.github-compatible-generated-header-id.md

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

部分文件因为文件数量过多而无法显示