Skip to content

Commit 2197060

Browse files
committed
nav.js: remove duplicate CM - code-highlight.js handles it
1 parent 4739a8c commit 2197060

1 file changed

Lines changed: 0 additions & 63 deletions

File tree

assets/nav.js

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -103,69 +103,6 @@
103103
}
104104

105105

106-
// CodeMirror syntax highlighting on reference/example pages
107-
if (document.querySelector('.syntax-block, .impl-block')) {
108-
const CDNJS = 'https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.16';
109-
function loadScript(src, cb) {
110-
const s = document.createElement('script'); s.src = src;
111-
s.onload = cb; document.head.appendChild(s);
112-
}
113-
function loadLink(href) {
114-
const l = document.createElement('link');
115-
l.rel = 'stylesheet'; l.href = href;
116-
document.head.appendChild(l);
117-
}
118-
loadLink(CDNJS + '/codemirror.min.css');
119-
loadLink(SITE + '/assets/cppmode-theme.css');
120-
loadScript(CDNJS + '/codemirror.min.js', function() {
121-
loadScript(CDNJS + '/mode/clike/clike.min.js', function() {
122-
loadScript(SITE + '/assets/cppmode-keywords.js', function() {
123-
loadScript(SITE + '/assets/cppmode.js', function() {
124-
const dark = document.body.classList.contains('dark-mode');
125-
const allBlocks = document.querySelectorAll('.syntax-block, .impl-block');
126-
console.log('CM: found', allBlocks.length, 'blocks');
127-
allBlocks.forEach((el, i) => {
128-
console.log('block', i, 'tag:', el.tagName, 'class:', el.className, 'display:', getComputedStyle(el).display, 'content len:', el.textContent.trim().length);
129-
});
130-
console.log('CM wrappers already:', document.querySelectorAll('.cm-editor-wrap').length);
131-
console.log('CM instances already:', document.querySelectorAll('.CodeMirror').length);
132-
document.querySelectorAll('.CodeMirror').forEach((el,i) => {
133-
if(i < 3) console.log('CM', i, 'parent:', el.parentElement?.className, 'grandparent:', el.parentElement?.parentElement?.className);
134-
});
135-
if (document.querySelector('.cm-editor-wrap')) { console.log('GUARD: already rendered'); return; }
136-
console.log('content children:', Array.from(document.querySelector('.content')?.children||[]).map(el=>el.tagName+'.'+el.className).join(', '));
137-
document.querySelectorAll('.syntax-block, .impl-block').forEach(el => {
138-
el.style.cssText = 'display:none!important;visibility:hidden!important;height:0!important;overflow:hidden!important;';
139-
if (!el.parentNode) return;
140-
const code = el.textContent.trim();
141-
if (!code) return;
142-
const wrap = document.createElement('div');
143-
wrap.className = 'cm-editor-wrap';
144-
wrap.style.cssText = 'margin:0;padding:0;border:none;background:none;';
145-
el.parentNode.insertBefore(wrap, el);
146-
const cm = CodeMirror(wrap, {
147-
value: code,
148-
mode: 'cppmode',
149-
theme: dark ? 'cppmode-dark' : 'cppmode',
150-
readOnly: true,
151-
lineNumbers: false,
152-
lineWrapping: false,
153-
});
154-
// Force full height - CM defaults to 300px
155-
const lineCount = cm.lineCount();
156-
const lineHeight = 18;
157-
const height = lineCount * lineHeight + 10;
158-
cm.setSize('100%', height + 'px');
159-
});
160-
// Switch theme on dark toggle
161-
document.querySelectorAll('.CodeMirror').forEach(el => {
162-
if (el.CodeMirror) el.CodeMirror.setOption('theme', dark ? 'cppmode-dark' : 'cppmode');
163-
});
164-
});
165-
});
166-
});
167-
});
168-
}
169106

170107
// Dark mode via CSS class
171108
(function() {

0 commit comments

Comments
 (0)