summaryrefslogtreecommitdiffstats
path: root/static/hlraw.js
diff options
context:
space:
mode:
authorclsr <clsr@clsr.net>2017-08-18 14:08:04 +0200
committerclsr <clsr@clsr.net>2017-08-18 14:08:04 +0200
commit1c15fe67c72b4591feaceeffec0951e34a6c2e46 (patch)
treec22393533916300e73799b9fe630c392a48a1c6b /static/hlraw.js
downloadcn-http-1c15fe67c72b4591feaceeffec0951e34a6c2e46.tar.gz
cn-http-1c15fe67c72b4591feaceeffec0951e34a6c2e46.zip
Initial commitv0.1.0
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();
+})();