File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ generate(docMap, {
18
18
"bit-docs-docjs-theme" : __dirname ,
19
19
"bit-docs-prettify" : "^0.1.0" ,
20
20
"bit-docs-html-highlight-line" : "^0.2.2" ,
21
- "bit-docs-html-toc" : "^0.2.1 "
21
+ "bit-docs-html-toc" : "^0.4.0 "
22
22
}
23
23
} ,
24
24
dest : path . join ( __dirname , "temp" ) ,
Original file line number Diff line number Diff line change @@ -3,12 +3,19 @@ var $ = require("jquery");
3
3
require ( "./styles/styles.less" ) ;
4
4
5
5
$ ( function ( ) {
6
+ var headings = { } ;
7
+
6
8
collectHeadings ( ) . each ( function ( ) {
7
9
var $el = $ ( this ) ;
8
10
var id = $el . attr ( "id" ) ;
9
11
10
12
if ( ! id ) {
11
- id = "section_" + $el . text ( ) . replace ( / \s / g, "" ) . replace ( / [ ^ \w ] / g, "_" ) ;
13
+ id = makeAnchorHeadingId ( $el . text ( ) ) ;
14
+ var count = headings [ id ] || 0 ;
15
+
16
+ id += ( count > 0 ) ? "-" + count : "" ;
17
+ headings [ id ] = count + 1 ;
18
+
12
19
$el . attr ( "id" , id ) ;
13
20
}
14
21
@@ -19,6 +26,13 @@ $(function() {
19
26
return $ ( ".content .comment h2, .content .comment h3" ) ;
20
27
}
21
28
29
+ function makeAnchorHeadingId ( anchorText ) {
30
+ return ( anchorText || "" )
31
+ . replace ( / \s / g, "-" ) // replace spaces with dashes
32
+ . replace ( / [ ^ \w \- ] / g, "" ) // remove punctuation
33
+ . toLowerCase ( ) ;
34
+ }
35
+
22
36
function anchorTemplate ( ctx ) {
23
37
var id = encodeURIComponent ( ctx . id ) ;
24
38
You can’t perform that action at this time.
0 commit comments