Skip to content

Instantly share code, notes, and snippets.

@mupkoo
Created June 24, 2014 07:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mupkoo/3a8592bae8dca70d38c1 to your computer and use it in GitHub Desktop.
Save mupkoo/3a8592bae8dca70d38c1 to your computer and use it in GitHub Desktop.
PrismJS line numbers tweak for Ghost
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