2018-11-20 21:51:39 +01:00
|
|
|
<!-- Miscelaneous render related template parts we use multiple times -->
|
|
|
|
{{define "highlighting"}}
|
2018-11-23 18:12:47 +01:00
|
|
|
<script>
|
|
|
|
// TODO: this feels more like a mutation observer
|
|
|
|
addEventListener('DOMContentLoaded', function () {
|
2018-12-07 22:37:14 +01:00
|
|
|
var hlbaseUri = "/js/";
|
2018-11-29 16:25:53 +01:00
|
|
|
var lb = document.querySelectorAll("code[class^='language-']");
|
|
|
|
|
|
|
|
|
2019-06-25 20:17:30 +02:00
|
|
|
// 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",
|
2019-06-26 23:12:18 +02:00
|
|
|
"sh" : "bash"
|
2019-06-25 20:17:30 +02:00
|
|
|
};
|
|
|
|
|
2018-11-29 16:25:53 +01:00
|
|
|
// Given a set of nodes, run highlighting on them
|
|
|
|
function highlight(nodes) {
|
|
|
|
for (i=0; i < nodes.length; i++) {
|
|
|
|
hljs.highlightBlock(nodes[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Given a array of URIs, load them in order
|
|
|
|
function loadLanguages(uris, callback) {
|
|
|
|
uris.forEach(function(uri) {
|
2018-12-03 18:18:04 +01:00
|
|
|
var sc = document.createElement('script');
|
|
|
|
sc.src = uri;
|
|
|
|
sc.async = false; // critical?
|
2019-06-25 20:17:30 +02:00
|
|
|
// Set callback on last script
|
2018-12-03 18:18:04 +01:00
|
|
|
if (uris.indexOf(uri) == uris.length-1) {
|
2019-03-05 14:36:40 +01:00
|
|
|
// Set callback regardless
|
|
|
|
// so we're sure it will run if last element had error
|
|
|
|
// (we only know after loading, so we've had load time already)
|
|
|
|
sc.onload = callback; sc.onerror = callback;
|
2018-12-03 18:18:04 +01:00
|
|
|
}
|
|
|
|
document.head.appendChild(sc);
|
2018-11-29 16:25:53 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// We don't have to do anything if there are no language blocks
|
|
|
|
if (lb.length > 0) {
|
|
|
|
// We have blocks to be highlighted, so we load css
|
2018-11-23 18:12:47 +01:00
|
|
|
var st = document.createElement('link');
|
|
|
|
st.rel = "stylesheet";
|
2018-12-07 22:37:14 +01:00
|
|
|
st.href = "/css/lib/atom-one-light.min.css";
|
2018-11-29 16:25:53 +01:00
|
|
|
document.head.appendChild(st);
|
2018-11-22 14:31:25 +01:00
|
|
|
|
2018-11-29 16:25:53 +01:00
|
|
|
// Construct set of files to load, in order
|
|
|
|
var jss = [hlbaseUri + "highlight.min.js"];
|
|
|
|
// Check what we need to load
|
|
|
|
for (i=0; i < lb.length; i++) {
|
|
|
|
lang = lb[i].className.replace('language-','');
|
2019-06-25 20:17:30 +02:00
|
|
|
// Support the aliases specified above
|
|
|
|
if (aliasmap[lang]) lang = aliasmap[lang];
|
2018-12-07 22:37:14 +01:00
|
|
|
lurl = hlbaseUri + "highlightjs/" + lang + ".min.js";
|
2019-06-27 17:13:20 +02:00
|
|
|
if (!jss.includes(lurl)) {
|
2018-12-03 18:18:04 +01:00
|
|
|
jss.push(lurl);
|
|
|
|
}
|
2018-11-23 18:12:47 +01:00
|
|
|
}
|
2018-11-29 16:25:53 +01:00
|
|
|
// Load files in order, higlight on last load
|
|
|
|
loadLanguages(jss, () => {highlight(lb)});
|
2018-11-23 18:12:47 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
2018-11-20 21:51:39 +01:00
|
|
|
{{end}}
|
2018-11-20 22:01:25 +01:00
|
|
|
|
|
|
|
<!-- Include mathjax configuration -->
|
|
|
|
{{define "mathjax"}}
|
|
|
|
<script type="text/x-mathjax-config">
|
|
|
|
MathJax.Hub.Config({
|
|
|
|
extensions: ["tex2jax.js"],
|
|
|
|
jax: ["input/TeX", "output/HTML-CSS"],
|
|
|
|
tex2jax: {
|
|
|
|
inlineMath: [ ['$','$'], ["\\(","\\)"] ],
|
|
|
|
displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
|
|
|
|
processEscapes: true
|
|
|
|
},
|
|
|
|
"HTML-CSS": { fonts: ["TeX"] }
|
|
|
|
});
|
|
|
|
</script>
|
2018-12-07 22:50:29 +01:00
|
|
|
<script type="text/javascript" src="/js/mathjax/MathJax.js?config=TeX-MML-AM_CHTML" async></script>
|
2018-11-20 22:01:25 +01:00
|
|
|
{{end}}
|