File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 27
27
"devDependencies" : {
28
28
"bit-docs-generate-html" : " ^0.3.3" ,
29
29
"bit-docs-html-toc" : " ^0.2.1"
30
+ },
31
+ "dependencies" : {
32
+ "jquery" : " ^3.1.1"
30
33
}
31
34
}
Original file line number Diff line number Diff line change
1
+ var $ = require ( "jquery" ) ;
2
+
1
3
require ( "./styles/styles.less" ) ;
4
+
5
+ $ ( function ( ) {
6
+ collectHeadings ( ) . each ( function ( ) {
7
+ var $el = $ ( this ) ;
8
+ var id = $el . attr ( "id" ) ;
9
+
10
+ if ( ! id ) {
11
+ id = "section_" + $el . text ( ) . replace ( / \s / g, "" ) . replace ( / [ ^ \w ] / g, "_" ) ;
12
+ $el . attr ( "id" , id ) ;
13
+ }
14
+
15
+ $el . prepend ( anchorTemplate ( { id : id } ) ) ;
16
+ } ) ;
17
+
18
+ function collectHeadings ( ) {
19
+ return $ ( ".content .comment h2, .content .comment h3" ) ;
20
+ }
21
+
22
+ function anchorTemplate ( ctx ) {
23
+ var id = encodeURIComponent ( ctx . id ) ;
24
+
25
+ return (
26
+ '<a class="anchor" href="#' + id + '" aria-hidden="true">' +
27
+ '<svg aria-hidden="true" class="octicon octicon-link" height="16" version="1.1" viewBox="0 0 16 16" width="16">' +
28
+ '<path d="M4 9h1v1h-1c-1.5 0-3-1.69-3-3.5s1.55-3.5 3-3.5h4c1.45 0 3 1.69 3 3.5 0 1.41-0.91 2.72-2 3.25v-1.16c0.58-0.45 1-1.27 1-2.09 0-1.28-1.02-2.5-2-2.5H4c-0.98 0-2 1.22-2 2.5s1 2.5 2 2.5z m9-3h-1v1h1c1 0 2 1.22 2 2.5s-1.02 2.5-2 2.5H9c-0.98 0-2-1.22-2-2.5 0-0.83 0.42-1.64 1-2.09v-1.16c-1.09 0.53-2 1.84-2 3.25 0 1.81 1.55 3.5 3 3.5h4c1.45 0 3-1.69 3-3.5s-1.5-3.5-3-3.5z"></path>' +
29
+ '</svg>' +
30
+ '</a>'
31
+ ) ;
32
+ }
33
+ } ) ;
You can’t perform that action at this time.
0 commit comments