@@ -7,6 +7,26 @@ function setThemeIcon(theme) {
77 : '<i class="fa-solid fa-moon"></i>' ;
88}
99
10+ function highlightBlocks ( root = document ) {
11+ if ( ! window . hljs ) return ;
12+ root . querySelectorAll ( "pre code" ) . forEach ( ( block ) => {
13+ hljs . highlightElement ( block ) ;
14+ } ) ;
15+ }
16+
17+ function syncHighlightTheme ( theme ) {
18+ const dark = document . getElementById ( "hljs-theme-dark" ) ;
19+ const light = document . getElementById ( "hljs-theme-light" ) ;
20+ if ( ! dark || ! light ) return ;
21+ if ( theme === "light" ) {
22+ dark . disabled = true ;
23+ light . disabled = false ;
24+ } else {
25+ dark . disabled = false ;
26+ light . disabled = true ;
27+ }
28+ }
29+
1030function toggleTheme ( ) {
1131 const html = document . documentElement ;
1232 const isLight = html . getAttribute ( "data-theme" ) === "light" ;
@@ -15,10 +35,12 @@ function toggleTheme() {
1535 html . removeAttribute ( "data-theme" ) ;
1636 localStorage . setItem ( "theme" , "dark" ) ;
1737 setThemeIcon ( "dark" ) ;
38+ syncHighlightTheme ( "dark" ) ;
1839 } else {
1940 html . setAttribute ( "data-theme" , "light" ) ;
2041 localStorage . setItem ( "theme" , "light" ) ;
2142 setThemeIcon ( "light" ) ;
43+ syncHighlightTheme ( "light" ) ;
2244 }
2345}
2446
@@ -30,9 +52,13 @@ document.addEventListener("DOMContentLoaded", function () {
3052 if ( savedTheme === "light" ) {
3153 html . setAttribute ( "data-theme" , "light" ) ;
3254 setThemeIcon ( "light" ) ;
55+ syncHighlightTheme ( "light" ) ;
3356 } else {
3457 setThemeIcon ( "dark" ) ;
58+ syncHighlightTheme ( "dark" ) ;
3559 }
60+
61+ highlightBlocks ( ) ;
3662} ) ;
3763
3864// Add smooth scrolling for anchor links
@@ -60,6 +86,7 @@ ws.onmessage = (event) => {
6086 const date = new Date ( ) ;
6187 console . log ( `updating content: ${ date . toLocaleTimeString ( ) } ` ) ;
6288 content . innerHTML = event . data ;
89+ highlightBlocks ( content ) ;
6390} ;
6491
6592ws . onclose = ( ) => console . log ( "closed" ) ;
0 commit comments