1
+ // jshint multistr:true
2
+
1
3
( function ( w , d ) {
2
4
'use strict' ;
3
5
9
11
DATA_ATTR_NAME = 'data-line-number' ,
10
12
BREAK_LINE_REGEXP = / \r \n | \r | \n / g;
11
13
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
-
20
14
if ( w . hljs ) {
21
15
w . hljs . initLineNumbersOnLoad = initLineNumbersOnLoad ;
22
16
w . hljs . lineNumbersBlock = lineNumbersBlock ;
121
115
* Doing deep passage on child nodes.
122
116
* @param {HTMLElement } element
123
117
*/
124
- function dublicateMiltilineNodes ( element ) {
118
+ function dublicateMiltilineNodes ( element ) {
125
119
var nodes = element . childNodes ;
126
120
for ( var node in nodes ) {
127
121
if ( nodes . hasOwnProperty ( node ) ) {
141
135
* Method for fix multi-line elements implementation in highlight.js
142
136
* @param {HTMLElement } element
143
137
*/
144
- function dublicateMiltilineNode ( element ) {
138
+ function dublicateMiltilineNode ( element ) {
145
139
var className = element . parentNode . className ;
146
140
147
141
if ( ! / h l j s - / . test ( className ) ) return ;
148
142
149
143
var lines = getLines ( element . textContent ) ;
144
+
150
145
for ( var i = 0 , result = '' ; i < lines . length ; i ++ ) {
151
146
result += format ( '<span class="{0}">{1}</span>\n' , [ className , lines [ i ] ] ) ;
152
147
}
153
148
element . parentNode . innerHTML = result . trim ( ) ;
154
149
}
155
150
156
- function getLines ( text ) {
151
+ function getLines ( text ) {
157
152
if ( text . length === 0 ) return [ ] ;
158
153
return text . split ( BREAK_LINE_REGEXP ) ;
159
154
}
160
155
161
- function getLinesCount ( text ) {
156
+ function getLinesCount ( text ) {
162
157
return ( text . trim ( ) . match ( BREAK_LINE_REGEXP ) || [ ] ) . length ;
163
158
}
164
159
165
160
function async ( func ) {
166
161
w . setTimeout ( func , 0 ) ;
167
162
}
168
163
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
+
169
175
} ( window , document ) ) ;
0 commit comments