You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wrote some replacement based on you code - hope that not a problem ;) I put it here - might someone find it useful.
// based on the https://github.com/wcoder/highlightjs-line-numbers.js by @wcoderexportclassHighlightJsLineNumbers{publicstaticreadonlyTABLE_NAME: string='hljs-ln';publicstaticreadonlyLINE_NAME: string='hljs-ln-line';publicstaticreadonlyCODE_BLOCK_NAME: string='hljs-ln-code';publicstaticreadonlyNUMBERS_BLOCK_NAME: string='hljs-ln-numbers';publicstaticreadonlyNUMBER_LINE_NAME: string='hljs-ln-n';publicstaticreadonlyDATA_ATTR_NAME: string='data-line-number';publicstaticformat(str,args){returnstr.replace(/\{(\d+)\}/g,function(m,n){returnargs[n] ? args[n] : m;});};publicstaticlineNumbersBlock(element,options?: any){if(typeofelement!=='object'){return;}// define options or set defaultoptions=options||{singleLine: true// enable plugin for code block with one line};// convert optionsconstfirstLineIndex=!!options.singleLine ? 0 : 1;constlines=this.getLines(element.innerHTML);if(lines.length>firstLineIndex){lethtml='';leti=0;constl=lines.length;console.log(l)for(;i<l;i++){html+=this.format('<tr><td class="{0}"><div class="{1} {2}" {3}="{5}"></div></td><td class="{4}"><div class="{1}">{6}</div></td></tr>',[this.NUMBERS_BLOCK_NAME,this.LINE_NAME,this.NUMBER_LINE_NAME,this.DATA_ATTR_NAME,this.CODE_BLOCK_NAME,i+1,lines[i].length>0 ? lines[i] : ' ']);}element.innerHTML=this.format('<table class="{0}">{1}</table>',[this.TABLE_NAME,html]);}}publicstaticgetLines(text){if(text.length===0){return[];}constlines=text.split(/\r\n|\r|\n/g);// if last line contains only carriage return remove itif(_.trim(_.last(lines))===''){lines.pop();}returnlines;}}
Activity
wcoder commentedon Oct 10, 2017
Thanks for use this plugin!
Currently, this plugin don't have type definitions
.d.ts
file for TypeSctipt.pnowy commentedon Oct 10, 2017
I wrote some replacement based on you code - hope that not a problem ;) I put it here - might someone find it useful.
Styles (SCSS):
And usage:
HighlightJsLineNumbers.lineNumbersBlock(node);
pnowy commentedon Oct 10, 2017
PS. The following part:
is using lodash.