Skip to content
This repository has been archived by the owner on Jul 16, 2021. It is now read-only.

Commit

Permalink
Enable isso comment code highlight.
Browse files Browse the repository at this point in the history
  • Loading branch information
jixunmoe committed May 16, 2017
1 parent 636426b commit 7117021
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/js/app/issoCodeHighlight.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* Automatically convert multiline `code` to a full `pre` block. */
$(function () {
/* globals hljs */
'use strict';
var processedFlag = 'js-hljs';

function renderCode () {
$('code:not(.hljs,.'+ processedFlag +')').each(function (i, el) {
var $el = $(el);
var html = $el.html();
var render = false;

if ($el.parent().is('pre')) {
render = true;
} else if (html.indexOf('\n') !== -1) {
$('<pre>')
.insertBefore($el)
.append($el);
$el.html(html.trim());
render = true;
}

if (render) {
hljs.highlightBlock(el);
}

$el.addClass(processedFlag);
});
}

renderCode();
setTimeout(renderCode, 5000);

// if current tab is active, re-scan for un-processed code tags.
// In-case of isso loading comments slowly.
var renderHandle;
var prevType;
$(window).on("blur focus", function(e) {
if (prevType !== e.type) {
switch (e.type) {
case "blur":
clearInterval(renderHandle);
break;
case "focus":
setInterval(renderCode, 15000);
break;
}
}

prevType = e.type;
});
});

0 comments on commit 7117021

Please sign in to comment.