File tree Expand file tree Collapse file tree 3 files changed +21
-105
lines changed
Expand file tree Collapse file tree 3 files changed +21
-105
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 44 * Module dependencies
55 */
66
7- var diacritics = require ( './ diacritics' ) ;
7+ var diacritics = require ( 'diacritics-map ' ) ;
88var utils = require ( 'lazy-cache' ) ( require ) ;
99var fn = require ;
1010require = utils ;
@@ -57,19 +57,28 @@ utils.slugify = function(str, options) {
5757 str = utils . getTitle ( str ) ;
5858 str = utils . stripColor ( str ) ;
5959 str = str . toLowerCase ( ) ;
60+
6061 // `.split()` is often (but not always) faster than `.replace()`
6162 str = str . split ( ' ' ) . join ( '-' ) ;
6263 str = str . split ( / \t / ) . join ( '--' ) ;
63- str = str . split ( / < \/ ? [ ^ > ] + > / ) . join ( '' ) ;
64+ if ( options . stripHeadingTags !== false ) {
65+ str = str . split ( / < \/ ? [ ^ > ] + > / ) . join ( '' ) ;
66+ }
6467 str = str . split ( / [ | $ & ` ~ = \\ \/ @ + * ! ? ( { [ \] } ) < > = . , ; : ' " ^ ] / ) . join ( '' ) ;
6568 str = str . split ( / [ 。 ? ! , 、 ; : “ ” 【 】 ( ) 〔 〕 [ ] ﹃ ﹄ “ ” ‘ ’ ﹁ ﹂ — … - ~ 《 》 〈 〉 「 」 ] / ) . join ( '' ) ;
66- str = diacritics . removeDiacritics ( str ) ;
69+ str = replaceDiacritics ( str ) ;
6770 if ( options . num ) {
6871 str += '-' + options . num ;
6972 }
7073 return str ;
7174} ;
7275
76+ function replaceDiacritics ( str ) {
77+ return str . replace ( / [ À - ž ] / g, function ( ch ) {
78+ return diacritics [ ch ] || ch ;
79+ } ) ;
80+ }
81+
7382/**
7483 * Expose `utils` modules
7584 */
Original file line number Diff line number Diff line change @@ -100,6 +100,15 @@ describe('options: custom functions:', function() {
100100 assert . equal ( toc ( '# Foo <test>' ) . content , '- [Foo](#foo-)' ) ;
101101 } ) ;
102102
103+ it ( 'should not strip HTML tags from headings when `stripHeadingTags` is false' , function ( ) {
104+ var opts = { stripHeadingTags : false } ;
105+ assert . equal ( toc ( '# <test>Foo' , opts ) . content , '- [Foo](#testfoo)' ) ;
106+ assert . equal ( toc ( '# <test> Foo' , opts ) . content , '- [Foo](#test-foo)' ) ;
107+ assert . equal ( toc ( '# <test> Foo ' , opts ) . content , '- [Foo](#test-foo)' ) ;
108+ assert . equal ( toc ( '# <div> Foo </div>' , opts ) . content , '- [Foo](#div-foo-div)' ) ;
109+ assert . equal ( toc ( '# Foo <test>' , opts ) . content , '- [Foo](#foo-test)' ) ;
110+ } ) ;
111+
103112 it ( 'should condense spaces in the heading text' , function ( ) {
104113 var actual = toc ( '# Some Article' ) ;
105114 assert . equal ( actual . content , '- [Some Article](#some----article)' ) ;
You can’t perform that action at this time.
0 commit comments