Created
June 24, 2014 07:26
-
-
Save mupkoo/3a8592bae8dca70d38c1 to your computer and use it in GitHub Desktop.
PrismJS line numbers tweak for Ghost
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Prism.hooks.add("after-highlight", function(e) { | |
var el = e.element, | |
t = el.parentNode; | |
// Add 'line-numbers' class to the parent | |
if (el.className.indexOf('line-numbers') !== -1) { | |
t.className = t.className + ' line-numbers'; | |
} | |
// The rest of the plugin | |
if(!t||!/pre/i.test(t.nodeName)||t.className.indexOf("line-numbers")===-1){return}var n=1+e.code.split("\n").length;var r;lines=new Array(n);lines=lines.join("<span></span>");r=document.createElement("span");r.className="line-numbers-rows";r.innerHTML=lines;if(t.hasAttribute("data-start")){t.style.counterReset="linenumber "+(parseInt(t.getAttribute("data-start"),10)-1)}e.element.appendChild(r) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment