summaryrefslogtreecommitdiffstats
path: root/static/hlraw.js
diff options
context:
space:
mode:
Diffstat (limited to 'static/hlraw.js')
-rw-r--r--static/hlraw.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/static/hlraw.js b/static/hlraw.js
new file mode 100644
index 0000000..8d57bb4
--- /dev/null
+++ b/static/hlraw.js
@@ -0,0 +1,39 @@
+(function() {
+ 'use strict';
+
+ var highlight = function(block, lang) {
+ var langs = lang.split('_');
+ if (langs.length > 1) {
+ lang = langs[langs.length-1];
+ }
+ if (!lang || typeof hljs.getLanguage(lang) === 'undefined') {
+ return;
+ }
+ var hl = hljs.highlight(lang, block.textContent, true);
+ block.innerHTML = hl.value;
+ };
+
+ var highlightAll = function() {
+ var rawBlocks = document.querySelectorAll('pre.cnm-raw code');
+ for (var i=0; i<rawBlocks.length; i++) {
+ var code = rawBlocks[i];
+ var classes = code.className.split();
+ var lang = '';
+ for (var j=0; j<classes.length; j++) {
+ if (classes[j].startsWith('cnm-raw-')) {
+ lang = classes[j].slice('cnm-raw-'.length);
+ break;
+ }
+ }
+ if (lang) {
+ try {
+ highlight(code, lang);
+ } catch (e) {
+ console.error(e);
+ }
+ }
+ }
+ };
+
+ highlightAll();
+})();