|
96 | 96 | document.head.appendChild(s); |
97 | 97 | } |
98 | 98 |
|
99 | | - // CodeMirror syntax highlighting on reference/example pages |
100 | | - if (document.querySelector('.syntax-block, .impl-block, pre#code-pre, #code-cm-wrap') && |
101 | | - !document.getElementById('ref-cm-loaded')) { |
102 | | - const CDNJS = 'https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.16'; |
103 | | - // Preload hints for faster script loading |
104 | | - [CDNJS + '/codemirror.min.js', CDNJS + '/mode/clike/clike.min.js', |
105 | | - SITE + '/assets/cppmode-keywords.js', SITE + '/assets/cppmode.js'].forEach(href => { |
106 | | - const l = document.createElement('link'); |
107 | | - l.rel = 'preload'; l.as = 'script'; l.href = href; |
108 | | - document.head.appendChild(l); |
109 | | - }); |
110 | | - function loadScript(src, cb) { |
111 | | - const s = document.createElement('script'); s.src = src; |
112 | | - s.onload = cb; document.head.appendChild(s); |
113 | | - } |
114 | | - function loadLink(href) { |
115 | | - const l = document.createElement('link'); |
116 | | - l.rel = 'stylesheet'; l.href = href; |
117 | | - document.head.appendChild(l); |
118 | | - } |
119 | | - loadLink(CDNJS + '/codemirror.min.css'); |
120 | | - loadLink(SITE + '/assets/cppmode-theme.css'); |
121 | | - loadScript(CDNJS + '/codemirror.min.js', function() { |
122 | | - loadScript(CDNJS + '/mode/clike/clike.min.js', function() { |
123 | | - loadScript(SITE + '/assets/cppmode-keywords.js', function() { |
124 | | - console.log('KW:', window.CPPMODE_KEYWORDS ? Object.keys(window.CPPMODE_KEYWORDS) : 'MISSING'); |
125 | | - loadScript(SITE + '/assets/cppmode.js', function() { |
126 | | - console.log('CM loaded'); |
127 | | - const marker = document.createElement('span'); |
128 | | - marker.id = 'ref-cm-loaded'; |
129 | | - document.head.appendChild(marker); |
130 | | - const dark = document.body.classList.contains('dark-mode'); |
131 | | - // Reference and example pages: replace .syntax-block and .impl-block |
132 | | - document.querySelectorAll('.syntax-block, .impl-block').forEach(el => { |
133 | | - if (!el.parentNode) return; |
134 | | - const code = el.textContent.trim(); |
135 | | - if (!code) return; |
136 | | - const wrap = document.createElement('div'); |
137 | | - el.parentNode.replaceChild(wrap, el); |
138 | | - const cm2 = CodeMirror(wrap, { |
139 | | - value: '', |
140 | | - mode: 'cppmode', |
141 | | - theme: dark ? 'cppmode-dark' : 'cppmode', |
142 | | - readOnly: true, |
143 | | - lineNumbers: false, |
144 | | - lineWrapping: false, |
145 | | - }); |
146 | | - setTimeout(() => { cm2.setValue(code); cm2.refresh(); }, 0); |
147 | | - }); |
148 | | - }); |
149 | | - }); |
150 | | - }); |
151 | | - }); |
152 | | - } |
| 99 | + |
153 | 100 | // Dark mode via CSS class |
154 | 101 | (function() { |
155 | 102 | if (!document.getElementById('dark-mode-style')) { |
|
0 commit comments