Skip to content

Commit a69fce2

Browse files
committed
use ace static highlighter in the main site
1 parent e5ce9e7 commit a69fce2

File tree

3 files changed

+196
-151
lines changed

3 files changed

+196
-151
lines changed

doc/site/js/main.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,31 @@ $(function() {
121121
}
122122
});
123123
}).trigger("hashchange");
124-
});
124+
125+
highlight();
126+
});
127+
128+
129+
130+
function highlight() {
131+
var highlighter = ace.require("ace/ext/static_highlight")
132+
var dom = ace.require("ace/lib/dom")
133+
function qsa(sel) {
134+
return [].slice.call(document.querySelectorAll(sel));
135+
}
136+
137+
qsa("code[class]").forEach(function(el) {
138+
var m = el.className.match(/language-(\w+)|(javascript)/);
139+
if (!m) return
140+
var mode = "ace/mode/" + (m[1] || m[2]);
141+
var theme = "ace/theme/xcode";
142+
var data = dom.getInnerText(el).trim();
143+
144+
highlighter.render(data, mode, theme, 1, true, function (highlighted) {
145+
dom.importCssString(highlighted.css, "ace_highlight");
146+
el.innerHTML = highlighted.html;
147+
});
148+
});
149+
150+
151+
}

0 commit comments

Comments
 (0)