Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.