Merge pull request #128 from writeas/fix-c-syntax-highlighting
Fix #124 according to the snippet by @mrvdb
This commit is contained in:
commit
f26e0ca86e
1 changed files with 20 additions and 4 deletions
|
@ -6,9 +6,23 @@
|
||||||
var hlbaseUri = "/js/";
|
var hlbaseUri = "/js/";
|
||||||
var lb = document.querySelectorAll("code[class^='language-']");
|
var lb = document.querySelectorAll("code[class^='language-']");
|
||||||
|
|
||||||
// Set langs to the langs that are included by default (for now: 'common set' on CDN)
|
|
||||||
var langs = [];
|
|
||||||
|
|
||||||
|
// Custom aliasmap
|
||||||
|
var aliasmap = {
|
||||||
|
"elisp" : "lisp",
|
||||||
|
"emacs-lisp" : "lisp",
|
||||||
|
"c" : "cpp",
|
||||||
|
"cc" : "cpp",
|
||||||
|
"h" : "cpp",
|
||||||
|
"c++" : "cpp",
|
||||||
|
"h++" : "cpp",
|
||||||
|
"hpp" : "cpp",
|
||||||
|
"hh" : "cpp",
|
||||||
|
"hxx" : "cpp",
|
||||||
|
"cxx" : "cpp",
|
||||||
|
"sh" : "bash"
|
||||||
|
};
|
||||||
|
|
||||||
// Given a set of nodes, run highlighting on them
|
// Given a set of nodes, run highlighting on them
|
||||||
function highlight(nodes) {
|
function highlight(nodes) {
|
||||||
for (i=0; i < nodes.length; i++) {
|
for (i=0; i < nodes.length; i++) {
|
||||||
|
@ -22,7 +36,7 @@
|
||||||
var sc = document.createElement('script');
|
var sc = document.createElement('script');
|
||||||
sc.src = uri;
|
sc.src = uri;
|
||||||
sc.async = false; // critical?
|
sc.async = false; // critical?
|
||||||
// Set callback on last script
|
// Set callback on last script
|
||||||
if (uris.indexOf(uri) == uris.length-1) {
|
if (uris.indexOf(uri) == uris.length-1) {
|
||||||
// Set callback regardless
|
// Set callback regardless
|
||||||
// so we're sure it will run if last element had error
|
// so we're sure it will run if last element had error
|
||||||
|
@ -46,8 +60,10 @@
|
||||||
// Check what we need to load
|
// Check what we need to load
|
||||||
for (i=0; i < lb.length; i++) {
|
for (i=0; i < lb.length; i++) {
|
||||||
lang = lb[i].className.replace('language-','');
|
lang = lb[i].className.replace('language-','');
|
||||||
|
// Support the aliases specified above
|
||||||
|
if (aliasmap[lang]) lang = aliasmap[lang];
|
||||||
lurl = hlbaseUri + "highlightjs/" + lang + ".min.js";
|
lurl = hlbaseUri + "highlightjs/" + lang + ".min.js";
|
||||||
if (!(langs.includes(lang) || jss.includes(lurl))) {
|
if (!jss.includes(lurl)) {
|
||||||
jss.push(lurl);
|
jss.push(lurl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue