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 65
65
} , 2000 )
66
66
}
67
67
68
+
69
+ document . addEventListener ( 'DOMContentLoaded' , ( ) => {
70
+ const headers = document . querySelectorAll ( 'h1[id], h2[id], h3[id], h4[id]' ) ;
71
+
72
+ headers . forEach ( header => {
73
+ const iconLink = document . createElement ( 'a' ) ;
74
+ iconLink . href = `#${ header . id } ` ;
75
+ iconLink . innerHTML = '#' ;
76
+ iconLink . className = 'header-link' ;
77
+
78
+ // Wrap the icon inside a span to control visibility with CSS
79
+ const wrapper = document . createElement ( 'span' ) ;
80
+ wrapper . className = 'header-link-wrapper' ;
81
+ wrapper . appendChild ( iconLink ) ;
82
+
83
+ // Append the wrapper to the header
84
+ header . appendChild ( wrapper ) ;
85
+ } ) ;
86
+ } ) ;
87
+
68
88
</ script >
Original file line number Diff line number Diff line change @@ -108,3 +108,18 @@ div[class*="language-"] button{
108
108
padding : 5px ;
109
109
}
110
110
111
+ .header-link-wrapper {
112
+ visibility : hidden ;
113
+ margin-left : 2px ;
114
+ padding-left : 2px ;
115
+ }
116
+ /* Show the icon link on hover */
117
+ h1 :hover .header-link-wrapper ,
118
+ h2 :hover .header-link-wrapper ,
119
+ h3 :hover .header-link-wrapper ,
120
+ h4 :hover .header-link-wrapper {
121
+ visibility : visible ;
122
+ }
123
+ .header-link {
124
+ color :#ccc !important
125
+ }
You can’t perform that action at this time.
0 commit comments