1+ // jshint multistr:true
2+
13( function ( w , d ) {
24 'use strict' ;
35
911 DATA_ATTR_NAME = 'data-line-number' ,
1012 BREAK_LINE_REGEXP = / \r \n | \r | \n / g;
1113
12- // string format
13- // https://wcoder.github.io/notes/string-format-for-string-formating-in-javascript
14- var format = function ( str , args ) {
15- return str . replace ( / \{ ( \d + ) \} / g, function ( m , n ) {
16- return args [ n ] ? args [ n ] : m ;
17- } ) ;
18- } ;
19-
2014 if ( w . hljs ) {
2115 w . hljs . initLineNumbersOnLoad = initLineNumbersOnLoad ;
2216 w . hljs . lineNumbersBlock = lineNumbersBlock ;
121115 * Doing deep passage on child nodes.
122116 * @param {HTMLElement } element
123117 */
124- function dublicateMiltilineNodes ( element ) {
118+ function dublicateMiltilineNodes ( element ) {
125119 var nodes = element . childNodes ;
126120 for ( var node in nodes ) {
127121 if ( nodes . hasOwnProperty ( node ) ) {
141135 * Method for fix multi-line elements implementation in highlight.js
142136 * @param {HTMLElement } element
143137 */
144- function dublicateMiltilineNode ( element ) {
138+ function dublicateMiltilineNode ( element ) {
145139 var className = element . parentNode . className ;
146140
147141 if ( ! / h l j s - / . test ( className ) ) return ;
148142
149143 var lines = getLines ( element . textContent ) ;
144+
150145 for ( var i = 0 , result = '' ; i < lines . length ; i ++ ) {
151146 result += format ( '<span class="{0}">{1}</span>\n' , [ className , lines [ i ] ] ) ;
152147 }
153148 element . parentNode . innerHTML = result . trim ( ) ;
154149 }
155150
156- function getLines ( text ) {
151+ function getLines ( text ) {
157152 if ( text . length === 0 ) return [ ] ;
158153 return text . split ( BREAK_LINE_REGEXP ) ;
159154 }
160155
161- function getLinesCount ( text ) {
156+ function getLinesCount ( text ) {
162157 return ( text . trim ( ) . match ( BREAK_LINE_REGEXP ) || [ ] ) . length ;
163158 }
164159
165160 function async ( func ) {
166161 w . setTimeout ( func , 0 ) ;
167162 }
168163
164+ /**
165+ * {@link https://wcoder.github.io/notes/string-format-for-string-formating-in-javascript }
166+ * @param {string } format
167+ * @param {array } args
168+ */
169+ function format ( format , args ) {
170+ return format . replace ( / \{ ( \d + ) \} / g, function ( m , n ) {
171+ return args [ n ] ? args [ n ] : m ;
172+ } ) ;
173+ }
174+
169175} ( window , document ) ) ;
0 commit comments