@@ -110,24 +110,25 @@ var Parser = (function () {
110
110
} , {
111
111
key : 'makeFootnotes' ,
112
112
value : function makeFootnotes ( html ) {
113
- if ( this . footnotes . length > 0 ) {
114
- html += '<div class="footnotes"><hr><ol>' ;
115
- var index = 1 ;
116
- var val = this . footnotes . pop ( ) ;
117
- while ( val ) {
118
- if ( typeof val === 'string' ) {
119
- val += ' <a href="#fnref-' + index + '" class="footnote-backref">↩</a>' ;
120
- } else {
121
- val [ val . length - 1 ] += ' <a href="#fnref-' + index + '" class="footnote-backref">↩</a>' ;
122
- val = val . length > 1 ? this . parse ( val . join ( "\n" ) ) : this . parseInline ( val [ 0 ] ) ;
123
- }
113
+ var _this2 = this ;
124
114
125
- html += '<li id="fn-' + index + '">' + val + '</li>' ;
115
+ if ( this . footnotes . length > 0 ) {
116
+ ( function ( ) {
117
+ html += '<div class="footnotes"><hr><ol>' ;
118
+ var index = 1 ;
119
+ _this2 . footnotes . forEach ( function ( val ) {
120
+ if ( typeof val === 'string' ) {
121
+ val += ' <a href="#fnref-' + index + '" class="footnote-backref">↩</a>' ;
122
+ } else {
123
+ val [ val . length - 1 ] += ' <a href="#fnref-' + index + '" class="footnote-backref">↩</a>' ;
124
+ val = val . length > 1 ? _this2 . parse ( val . join ( "\n" ) ) : _this2 . parseInline ( val [ 0 ] ) ;
125
+ }
126
126
127
- index ++ ;
128
- val = this . footnotes . pop ( ) ;
129
- }
130
- html += '</ol></div>' ;
127
+ html += '<li id="fn-' + index + '">' + val + '</li>' ;
128
+ index ++ ;
129
+ } ) ;
130
+ html += '</ol></div>' ;
131
+ } ) ( ) ;
131
132
}
132
133
return html ;
133
134
}
@@ -141,7 +142,7 @@ var Parser = (function () {
141
142
} , {
142
143
key : 'parse' ,
143
144
value : function parse ( text ) {
144
- var _this2 = this ;
145
+ var _this3 = this ;
145
146
146
147
var lines = text . split ( "\n" ) ;
147
148
var blocks = this . parseBlock ( text , lines ) ;
@@ -158,9 +159,9 @@ var Parser = (function () {
158
159
var extract = lines . slice ( start , end + 1 ) ;
159
160
var method = 'parse' + type . slice ( 0 , 1 ) . toUpperCase ( ) + type . slice ( 1 ) ;
160
161
var beforeMethod = 'beforeParse' + type . slice ( 0 , 1 ) . toUpperCase ( ) + type . slice ( 1 ) ;
161
- extract = _this2 . call ( beforeMethod , extract , value ) ;
162
- var result = _this2 [ method ] ( extract , value ) ;
163
- result = _this2 . call ( 'after' + method . slice ( 0 , 1 ) . toUpperCase ( ) + method . slice ( 1 ) , result , value ) ;
162
+ extract = _this3 . call ( beforeMethod , extract , value ) ;
163
+ var result = _this3 [ method ] ( extract , value ) ;
164
+ result = _this3 . call ( 'after' + method . slice ( 0 , 1 ) . toUpperCase ( ) + method . slice ( 1 ) , result , value ) ;
164
165
165
166
html += result ;
166
167
} ) ;
@@ -177,23 +178,20 @@ var Parser = (function () {
177
178
*/
178
179
} , {
179
180
key : 'call' ,
180
- value : function call ( type ) {
181
- for ( var _len = arguments . length , value = Array ( _len > 1 ? _len - 1 : 0 ) , _key = 1 ; _key < _len ; _key ++ ) {
182
- value [ _key - 1 ] = arguments [ _key ] ;
183
- }
184
-
181
+ value : function call ( type , value ) {
185
182
if ( ! this . hooks [ type ] ) {
186
- return value [ 0 ] ;
183
+ return value ;
187
184
}
188
185
189
- var args = value ;
186
+ var args = [ ] . slice . call ( arguments ) ;
187
+ args = args . slice ( 1 ) ;
190
188
191
189
this . hooks [ type ] . forEach ( function ( callback ) {
192
- value = callback ( args ) ;
190
+ value = callback . apply ( null , args ) ;
193
191
args [ 0 ] = value ;
194
192
} ) ;
195
193
196
- return value [ 0 ] ;
194
+ return value ;
197
195
}
198
196
199
197
/**
@@ -231,7 +229,7 @@ var Parser = (function () {
231
229
} , {
232
230
key : 'parseInline' ,
233
231
value : function parseInline ( text ) {
234
- var _this3 = this ;
232
+ var _this4 = this ;
235
233
236
234
var whiteList = arguments . length <= 1 || arguments [ 1 ] === undefined ? '' : arguments [ 1 ] ;
237
235
var clearHolders = arguments . length <= 2 || arguments [ 2 ] === undefined ? true : arguments [ 2 ] ;
@@ -245,15 +243,15 @@ var Parser = (function () {
245
243
246
244
// link
247
245
text = text . replace ( / < ( h t t p s ? : \/ \/ .+ ) > / ig, function ( match , p1 ) {
248
- return _this3 . makeHolder ( '<a href="' + p1 + '">' + p1 + '</a>' ) ;
246
+ return _this4 . makeHolder ( '<a href="' + p1 + '">' + p1 + '</a>' ) ;
249
247
} ) ;
250
248
251
249
text = text . replace ( / < ( \/ ? ) ( [ a - z 0 - 9 - ] + ) ( \s + [ ^ > ] * ) ? > / ig, function ( match , p1 , p2 , p3 ) {
252
- var whiteLists = _this3 . commonWhiteList + '|' + whiteList ;
250
+ var whiteLists = _this4 . commonWhiteList + '|' + whiteList ;
253
251
if ( whiteLists . toLowerCase ( ) . indexOf ( p2 . toLowerCase ( ) ) !== - 1 ) {
254
- return _this3 . makeHolder ( match ) ;
252
+ return _this4 . makeHolder ( match ) ;
255
253
} else {
256
- return _this3 . htmlspecialchars ( match ) ;
254
+ return _this4 . htmlspecialchars ( match ) ;
257
255
}
258
256
} ) ;
259
257
@@ -266,11 +264,11 @@ var Parser = (function () {
266
264
var id = _this . footnotes . indexOf ( p1 ) ;
267
265
268
266
if ( id === - 1 ) {
269
- id = _this . footnotes . length + 1 ;
270
- _this . footnotes [ id ] = _this3 . parseInline ( p1 , '' , false ) ;
267
+ id = _this . footnotes . length ;
268
+ _this . footnotes . push ( _this4 . parseInline ( p1 , '' , false ) ) ;
271
269
}
272
270
273
- return _this . makeHolder ( '<sup id="fnref-' + id + '"><a href="#fn-' + id + '" class="footnote-ref">' + id + '</a></sup>' ) ;
271
+ return _this . makeHolder ( '<sup id="fnref-' + ( id + 1 ) + '"><a href="#fn-' + ( id + 1 ) + '" class="footnote-ref">' + ( id + 1 ) + '</a></sup>' ) ;
274
272
} ) ;
275
273
276
274
// image
@@ -339,34 +337,34 @@ var Parser = (function () {
339
337
} , {
340
338
key : 'parseInlineCallback' ,
341
339
value : function parseInlineCallback ( text ) {
342
- var _this4 = this ;
340
+ var _this5 = this ;
343
341
344
342
text = text . replace ( / ( \* { 3 } ) ( .+ ?) \1/ g, function ( match , p1 , p2 ) {
345
- return '<strong><em>' + _this4 . parseInlineCallback ( p2 ) + '</em></strong>' ;
343
+ return '<strong><em>' + _this5 . parseInlineCallback ( p2 ) + '</em></strong>' ;
346
344
} ) ;
347
345
348
346
text = text . replace ( / ( \* { 2 } ) ( .+ ?) \1/ g, function ( match , p1 , p2 ) {
349
- return '<strong>' + _this4 . parseInlineCallback ( p2 ) + '</strong>' ;
347
+ return '<strong>' + _this5 . parseInlineCallback ( p2 ) + '</strong>' ;
350
348
} ) ;
351
349
352
350
text = text . replace ( / ( \* ) ( .+ ?) \1/ g, function ( match , p1 , p2 ) {
353
- return '<em>' + _this4 . parseInlineCallback ( p2 ) + '</em>' ;
351
+ return '<em>' + _this5 . parseInlineCallback ( p2 ) + '</em>' ;
354
352
} ) ;
355
353
356
354
text = text . replace ( / ( \s + | ^ ) ( _ { 3 } ) ( .+ ?) \2( \s + | $ ) / g, function ( match , p1 , p2 , p3 , p4 ) {
357
- return p1 + '<strong><em>' + _this4 . parseInlineCallback ( p3 ) + '</em></strong>' + p4 ;
355
+ return p1 + '<strong><em>' + _this5 . parseInlineCallback ( p3 ) + '</em></strong>' + p4 ;
358
356
} ) ;
359
357
360
358
text = text . replace ( / ( \s + | ^ ) ( _ { 2 } ) ( .+ ?) \2( \s + | $ ) / g, function ( match , p1 , p2 , p3 , p4 ) {
361
- return p1 + '<strong>' + _this4 . parseInlineCallback ( p3 ) + '</strong>' + p4 ;
359
+ return p1 + '<strong>' + _this5 . parseInlineCallback ( p3 ) + '</strong>' + p4 ;
362
360
} ) ;
363
361
364
362
text = text . replace ( / ( \s + | ^ ) ( _ ) ( .+ ?) \2( \s + | $ ) / g, function ( match , p1 , p2 , p3 , p4 ) {
365
- return p1 + '<em>' + _this4 . parseInlineCallback ( p3 ) + '</em>' + p4 ;
363
+ return p1 + '<em>' + _this5 . parseInlineCallback ( p3 ) + '</em>' + p4 ;
366
364
} ) ;
367
365
368
366
text = text . replace ( / ( ~ { 2 } ) ( .+ ?) \1/ g, function ( match , p1 , p2 ) {
369
- return '<del>' + _this4 . parseInlineCallback ( p2 ) + '</del>' ;
367
+ return '<del>' + _this5 . parseInlineCallback ( p2 ) + '</del>' ;
370
368
} ) ;
371
369
return text ;
372
370
}
@@ -381,7 +379,7 @@ var Parser = (function () {
381
379
} , {
382
380
key : 'parseBlock' ,
383
381
value : function parseBlock ( text , lines ) {
384
- var _this5 = this ;
382
+ var _this6 = this ;
385
383
386
384
this . blocks = [ ] ;
387
385
this . current = 'normal' ;
@@ -496,14 +494,14 @@ var Parser = (function () {
496
494
var tableMatches = / ^ ( (?: (?: (?: [ : ] * \- [ : ] * ) + (?: \| | \+ ) ) | (?: (?: \| | \+ ) (?: [ : ] * \- [ : ] * ) + ) | (?: (?: [ : ] * \- [ : ] * ) + (?: \| | \+ ) (?: [ : ] * \- [ : ] * ) + ) ) + ) $ / g. exec ( line ) ;
497
495
if ( this . isBlock ( 'normal' ) ) {
498
496
( function ( ) {
499
- var block = _this5 . getBlock ( ) ;
497
+ var block = _this6 . getBlock ( ) ;
500
498
var head = false ;
501
499
502
500
if ( block . length === 0 || block [ 0 ] !== 'normal' || / ^ \s * $ / . test ( lines [ block [ 2 ] ] ) ) {
503
- _this5 . startBlock ( 'table' , key ) ;
501
+ _this6 . startBlock ( 'table' , key ) ;
504
502
} else {
505
503
head = true ;
506
- _this5 . backBlock ( 1 , 'table' ) ;
504
+ _this6 . backBlock ( 1 , 'table' ) ;
507
505
}
508
506
509
507
if ( tableMatches [ 1 ] [ 0 ] == '|' ) {
@@ -532,7 +530,7 @@ var Parser = (function () {
532
530
aligns . push ( align ) ;
533
531
} ) ;
534
532
535
- _this5 . setBlock ( key , [ head , aligns ] ) ;
533
+ _this6 . setBlock ( key , [ head , aligns ] ) ;
536
534
} ) ( ) ;
537
535
}
538
536
break ;
@@ -671,9 +669,9 @@ var Parser = (function () {
671
669
var types = [ 'list' , 'quote' ] ;
672
670
673
671
if ( from === to && lines [ from ] . match ( / ^ \s * $ / ) && prevBlock && nextBlock ) {
674
- if ( prevBlock [ 0 ] == nextBlock [ 0 ] && types . indexOf ( prevBlock [ 0 ] !== - 1 ) ) {
672
+ if ( prevBlock [ 0 ] == nextBlock [ 0 ] && types . indexOf ( prevBlock [ 0 ] ) !== - 1 ) {
675
673
// combine 3 blocks
676
- blocks [ key - 1 ] = [ prevBlock [ 0 ] , prevBlock [ 1 ] , nextBlock [ 2 ] , NULL ] ;
674
+ blocks [ key - 1 ] = [ prevBlock [ 0 ] , prevBlock [ 1 ] , nextBlock [ 2 ] , null ] ;
677
675
blocks . splice ( key , 2 ) ;
678
676
}
679
677
}
@@ -724,10 +722,10 @@ var Parser = (function () {
724
722
} , {
725
723
key : 'parsePre' ,
726
724
value : function parsePre ( lines ) {
727
- var _this6 = this ;
725
+ var _this7 = this ;
728
726
729
727
lines . forEach ( function ( line , ind ) {
730
- lines [ ind ] = _this6 . htmlspecialchars ( line . substr ( 4 ) ) ;
728
+ lines [ ind ] = _this7 . htmlspecialchars ( line . substr ( 4 ) ) ;
731
729
} ) ;
732
730
var str = lines . join ( '\n' ) ;
733
731
@@ -799,7 +797,7 @@ var Parser = (function () {
799
797
} , {
800
798
key : 'parseList' ,
801
799
value : function parseList ( lines ) {
802
- var _this7 = this ;
800
+ var _this8 = this ;
803
801
804
802
var html = '' ;
805
803
var minSpace = 99999 ;
@@ -846,7 +844,7 @@ var Parser = (function () {
846
844
leftLines . push ( line . replace ( pattern , '' ) ) ;
847
845
} else {
848
846
if ( leftLines . length ) {
849
- html += "<li>" + _this7 . parse ( leftLines . join ( "\n" ) ) + "</li>" ;
847
+ html += "<li>" + _this8 . parse ( leftLines . join ( "\n" ) ) + "</li>" ;
850
848
}
851
849
if ( lastType !== type ) {
852
850
if ( lastType . length ) {
@@ -880,7 +878,7 @@ var Parser = (function () {
880
878
} , {
881
879
key : 'parseTable' ,
882
880
value : function parseTable ( lines , value ) {
883
- var _this8 = this ;
881
+ var _this9 = this ;
884
882
885
883
var _value = _slicedToArray ( value , 2 ) ;
886
884
@@ -959,7 +957,7 @@ var Parser = (function () {
959
957
html += ' align="' + aligns [ key ] + '"' ;
960
958
}
961
959
962
- html += '>' + _this8 . parseInline ( text ) + ( '</' + tag + '>' ) ;
960
+ html += '>' + _this9 . parseInline ( text ) + ( '</' + tag + '>' ) ;
963
961
} ) ;
964
962
965
963
html += '</tr>' ;
@@ -972,9 +970,9 @@ var Parser = (function () {
972
970
} ;
973
971
974
972
for ( var key in lines ) {
975
- var _ret2 = _loop ( key ) ;
973
+ var _ret3 = _loop ( key ) ;
976
974
977
- if ( _ret2 === 'continue' ) continue ;
975
+ if ( _ret3 === 'continue' ) continue ;
978
976
}
979
977
980
978
if ( body !== null ) {
@@ -1005,10 +1003,10 @@ var Parser = (function () {
1005
1003
} , {
1006
1004
key : 'parseNormal' ,
1007
1005
value : function parseNormal ( lines ) {
1008
- var _this9 = this ;
1006
+ var _this10 = this ;
1009
1007
1010
1008
lines = lines . map ( function ( line ) {
1011
- return _this9 . parseInline ( line ) ;
1009
+ return _this10 . parseInline ( line ) ;
1012
1010
} ) ;
1013
1011
1014
1012
var str = lines . join ( "\n" ) . trim ( ) ;
@@ -1066,10 +1064,10 @@ var Parser = (function () {
1066
1064
} , {
1067
1065
key : 'parseHtml' ,
1068
1066
value : function parseHtml ( lines , type ) {
1069
- var _this10 = this ;
1067
+ var _this11 = this ;
1070
1068
1071
1069
lines . forEach ( function ( line ) {
1072
- line = _this10 . parseInline ( line , _this10 . specialWhiteList [ type ] ? _this10 . specialWhiteList [ type ] : '' ) ;
1070
+ line = _this11 . parseInline ( line , _this11 . specialWhiteList [ type ] ? _this11 . specialWhiteList [ type ] : '' ) ;
1073
1071
} ) ;
1074
1072
1075
1073
return lines . join ( "\n" ) ;
@@ -1252,7 +1250,4 @@ var Parser = (function () {
1252
1250
} ) ( ) ;
1253
1251
1254
1252
exports [ 'default' ] = Parser ;
1255
-
1256
- var parser = new Parser ( ) ;
1257
- console . log ( parser . makeHtml ( '[Genymotion](https://www.genymotion.com/)是。[Genymotion](https://www.genymotion.com/) [VirtualBox](https://www.virtualbox.org/)富的[付费版](https://shop.genymotion.com/index.php?controller=order-opc)' ) ) ;
1258
1253
module . exports = exports [ 'default' ] ;
0 commit comments