use ace static highlighter in the main site
This commit is contained in:
parent
e5ce9e7aee
commit
a69fce21f4
3 changed files with 196 additions and 151 deletions
|
|
@ -121,4 +121,31 @@ $(function() {
|
|||
}
|
||||
});
|
||||
}).trigger("hashchange");
|
||||
});
|
||||
|
||||
highlight();
|
||||
});
|
||||
|
||||
|
||||
|
||||
function highlight() {
|
||||
var highlighter = ace.require("ace/ext/static_highlight")
|
||||
var dom = ace.require("ace/lib/dom")
|
||||
function qsa(sel) {
|
||||
return [].slice.call(document.querySelectorAll(sel));
|
||||
}
|
||||
|
||||
qsa("code[class]").forEach(function(el) {
|
||||
var m = el.className.match(/language-(\w+)|(javascript)/);
|
||||
if (!m) return
|
||||
var mode = "ace/mode/" + (m[1] || m[2]);
|
||||
var theme = "ace/theme/xcode";
|
||||
var data = dom.getInnerText(el).trim();
|
||||
|
||||
highlighter.render(data, mode, theme, 1, true, function (highlighted) {
|
||||
dom.importCssString(highlighted.css, "ace_highlight");
|
||||
el.innerHTML = highlighted.html;
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue