From c2d7c2c8b7b18531271f18d0b5a18032eb599806 Mon Sep 17 00:00:00 2001 From: Michael Demetriou Date: Tue, 25 Jun 2019 21:17:30 +0300 Subject: [PATCH] Fix #124 according to the snippet by @mrvdb I changed the sh alias to shell instead of bash. The additions to the `highlight(nodes)` function look redundant. It works for me without them but maybe they cover an edge case I cannot think about? --- templates/include/post-render.tmpl | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/templates/include/post-render.tmpl b/templates/include/post-render.tmpl index b0e8582..0f23810 100644 --- a/templates/include/post-render.tmpl +++ b/templates/include/post-render.tmpl @@ -9,6 +9,22 @@ // 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" : "shell" + }; + // Given a set of nodes, run highlighting on them function highlight(nodes) { for (i=0; i < nodes.length; i++) { @@ -22,7 +38,7 @@ var sc = document.createElement('script'); sc.src = uri; sc.async = false; // critical? - // Set callback on last script + // Set callback on last script if (uris.indexOf(uri) == uris.length-1) { // Set callback regardless // so we're sure it will run if last element had error @@ -46,6 +62,8 @@ // Check what we need to load for (i=0; i < lb.length; i++) { lang = lb[i].className.replace('language-',''); + // Support the aliases specified above + if (aliasmap[lang]) lang = aliasmap[lang]; lurl = hlbaseUri + "highlightjs/" + lang + ".min.js"; if (!(langs.includes(lang) || jss.includes(lurl))) { jss.push(lurl);