File tree 1 file changed +14
-1
lines changed
1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -30,10 +30,14 @@ function onPageLoad() {
30
30
31
31
document . addEventListener ( "DOMContentLoaded" , onPageLoad ) ;
32
32
33
+ function textToAnchorLink ( text ) {
34
+ return text . replace ( / [ \W _ ] + / g, "-" ) ;
35
+ }
36
+
33
37
function addHeaderLink ( ) {
34
38
[ ...document . querySelectorAll ( "h1.notion-heading" ) ] . map ( item => {
35
39
let span = document . createElement ( 'span' ) ;
36
- let anchor_id = item . textContent . replace ( / [ \W _ ] + / g , "-" ) ;
40
+ let anchor_id = textToAnchorLink ( item . textContent ) ;
37
41
span . id = anchor_id ;
38
42
span . className = "notion-heading__anchor"
39
43
let ahref = document . createElement ( 'a' ) ;
@@ -46,3 +50,12 @@ function addHeaderLink () {
46
50
}
47
51
48
52
document . addEventListener ( "DOMContentLoaded" , addHeaderLink ) ;
53
+
54
+ function fixToCLinks ( ) {
55
+ [ ...document . querySelectorAll ( "li.notion-table-of-contents__item > a" ) ] . map ( item => {
56
+ let anchor_id = textToAnchorLink ( item . querySelector ( "span span span" ) . textContent )
57
+ item . href = "#" + anchor_id ;
58
+ } ) ;
59
+ }
60
+
61
+ document . addEventListener ( "DOMContentLoaded" , fixToCLinks ) ;
You can’t perform that action at this time.
0 commit comments