@@ -162,7 +162,9 @@ var Parser = (function () {
162
162
163
163
html += result ;
164
164
} ) ;
165
-
165
+ if ( this . hooks . afterParse ) {
166
+ html = this . call ( 'afterParse' , html ) ;
167
+ }
166
168
return html ;
167
169
}
168
170
@@ -241,7 +243,7 @@ var Parser = (function () {
241
243
242
244
// link
243
245
text = text . replace ( / < ( h t t p s ? : \/ \/ .+ ) > / ig, function ( match , p1 ) {
244
- return '<a href="' + p1 + '">' + p1 + '</a>' ;
246
+ return _this3 . makeHolder ( '<a href="' + p1 + '">' + p1 + '</a>' ) ;
245
247
} ) ;
246
248
247
249
text = text . replace ( / < ( \/ ? ) ( [ a - z 0 - 9 - ] + ) ( \s + [ ^ > ] * ) ? > / ig, function ( match , p1 , p2 , p3 ) {
@@ -312,13 +314,14 @@ var Parser = (function () {
312
314
} ) ;
313
315
314
316
// strong and em and some fuck
315
- text = text . replace ( / ( \* { 3 } ) ( .+ ?) \1/ g, "<strong><em>$2</em></strong>" ) ;
316
- text = text . replace ( / ( \* { 2 } ) ( .+ ?) \1/ g, "<strong>$2</strong>" ) ;
317
- text = text . replace ( / ( \* ) ( .+ ?) \1/ g, "<em>$2</em>" ) ;
318
- text = text . replace ( / ( \s + ) ( _ { 3 } ) ( .+ ?) \2( \s + ) / g, "$1<strong><em>$3</em></strong>$4" ) ;
319
- text = text . replace ( / ( \s + ) ( _ { 2 } ) ( .+ ?) \2( \s + ) / g, "$1<strong>$3</strong>$4" ) ;
320
- text = text . replace ( / ( \s + ) ( _ ) ( .+ ?) \2( \s + ) / g, "$1<em>$3</em>$4" ) ;
321
- text = text . replace ( / ( ~ { 2 } ) ( .+ ?) \1/ g, "<del>$2</del>" ) ;
317
+ // text = text.replace(/(\*{3})(.+?)\1/g, "<strong><em>$2</em></strong>")
318
+ // text = text.replace(/(\*{2})(.+?)\1/g, "<strong>$2</strong>")
319
+ // text = text.replace(/(\*)(.+?)\1/g, "<em>$2</em>")
320
+ // text = text.replace(/(\s+)(_{3})(.+?)\2(\s+)/g, "$1<strong><em>$3</em></strong>$4")
321
+ // text = text.replace(/(\s+)(_{2})(.+?)\2(\s+)/g, "$1<strong>$3</strong>$4")
322
+ // text = text.replace(/(\s+)(_)(.+?)\2(\s+)/g, "$1<em>$3</em>$4")
323
+ // text = text.replace(/(~{2})(.+?)\1/g, "<del>$2</del>")
324
+ text = this . parseInlineCallback ( text ) ;
322
325
text = text . replace ( / < ( [ _ a - z 0 - 9 -\. \+ ] + @ [ ^ @ ] + \. [ a - z ] { 2 , } ) > / ig, "<a href=\"mailto:$1\">$1</a>" ) ;
323
326
324
327
// autolink url
@@ -334,6 +337,45 @@ var Parser = (function () {
334
337
return text ;
335
338
}
336
339
340
+ /**
341
+ * @param text
342
+ * @return mixed
343
+ */
344
+ } , {
345
+ key : 'parseInlineCallback' ,
346
+ value : function parseInlineCallback ( text ) {
347
+ var _this4 = this ;
348
+
349
+ text = text . replace ( / ( \* { 3 } ) ( .+ ?) \1/ g, function ( match , p1 , p2 ) {
350
+ return '<strong><em>' + _this4 . parseInlineCallback ( p2 ) + '</em></strong>' ;
351
+ } ) ;
352
+
353
+ text = text . replace ( / ( \* { 2 } ) ( .+ ?) \1/ g, function ( match , p1 , p2 ) {
354
+ return '<strong>' + _this4 . parseInlineCallback ( p2 ) + '</strong>' ;
355
+ } ) ;
356
+
357
+ text = text . replace ( / ( \* ) ( .+ ?) \1/ g, function ( match , p1 , p2 ) {
358
+ return '<em>' + _this4 . parseInlineCallback ( p2 ) + '</em>' ;
359
+ } ) ;
360
+
361
+ text = text . replace ( / ( \s + | ^ ) ( _ { 3 } ) ( .+ ?) \2( \s + | $ ) / g, function ( match , p1 , p2 , p3 , p4 ) {
362
+ return p1 + '<strong><em>' + _this4 . parseInlineCallback ( p3 ) + '</em></strong>' + p4 ;
363
+ } ) ;
364
+
365
+ text = text . replace ( / ( \s + | ^ ) ( _ { 2 } ) ( .+ ?) \2( \s + | $ ) / g, function ( match , p1 , p2 , p3 , p4 ) {
366
+ return p1 + '<strong>' + _this4 . parseInlineCallback ( p3 ) + '</strong>' + p4 ;
367
+ } ) ;
368
+
369
+ text = text . replace ( / ( \s + | ^ ) ( _ ) ( .+ ?) \2( \s + | $ ) / g, function ( match , p1 , p2 , p3 , p4 ) {
370
+ return p1 + '<em>' + _this4 . parseInlineCallback ( p3 ) + '</em>' + p4 ;
371
+ } ) ;
372
+
373
+ text = text . replace ( / ( ~ { 2 } ) ( .+ ?) \1/ g, function ( match , p1 , p2 ) {
374
+ return '<del>' + _this4 . parseInlineCallback ( p2 ) + '</del>' ;
375
+ } ) ;
376
+ return text ;
377
+ }
378
+
337
379
/**
338
380
* parseBlock
339
381
*
@@ -344,7 +386,7 @@ var Parser = (function () {
344
386
} , {
345
387
key : 'parseBlock' ,
346
388
value : function parseBlock ( text , lines ) {
347
- var _this4 = this ;
389
+ var _this5 = this ;
348
390
349
391
this . blocks = [ ] ;
350
392
this . current = 'normal' ;
@@ -447,7 +489,7 @@ var Parser = (function () {
447
489
case / ^ { 4 } / . test ( line ) :
448
490
emptyCount = 0 ;
449
491
450
- if ( this . isBlock ( 'pre' ) ) {
492
+ if ( this . isBlock ( 'pre' ) || this . isBlock ( 'list' ) ) {
451
493
this . setBlock ( key ) ;
452
494
} else if ( this . isBlock ( 'normal' ) ) {
453
495
this . startBlock ( 'pre' , key ) ;
@@ -459,14 +501,14 @@ var Parser = (function () {
459
501
var tableMatches = / ^ ( (?: (?: (?: [ : ] * \- [ : ] * ) + (?: \| | \+ ) ) | (?: (?: \| | \+ ) (?: [ : ] * \- [ : ] * ) + ) | (?: (?: [ : ] * \- [ : ] * ) + (?: \| | \+ ) (?: [ : ] * \- [ : ] * ) + ) ) + ) $ / g. exec ( line ) ;
460
502
if ( this . isBlock ( 'normal' ) ) {
461
503
( function ( ) {
462
- var block = _this4 . getBlock ( ) ;
504
+ var block = _this5 . getBlock ( ) ;
463
505
var head = false ;
464
506
465
507
if ( block . length === 0 || block [ 0 ] !== 'normal' || / ^ \s * $ / . test ( lines [ block [ 2 ] ] ) ) {
466
- _this4 . startBlock ( 'table' , key ) ;
508
+ _this5 . startBlock ( 'table' , key ) ;
467
509
} else {
468
510
head = true ;
469
- _this4 . backBlock ( 1 , 'table' ) ;
511
+ _this5 . backBlock ( 1 , 'table' ) ;
470
512
}
471
513
472
514
if ( tableMatches [ 1 ] [ 0 ] == '|' ) {
@@ -495,7 +537,7 @@ var Parser = (function () {
495
537
aligns . push ( align ) ;
496
538
} ) ;
497
539
498
- _this4 . setBlock ( key , [ head , aligns ] ) ;
540
+ _this5 . setBlock ( key , [ head , aligns ] ) ;
499
541
} ) ( ) ;
500
542
}
501
543
break ;
@@ -669,10 +711,10 @@ var Parser = (function () {
669
711
} , {
670
712
key : 'parsePre' ,
671
713
value : function parsePre ( lines ) {
672
- var _this5 = this ;
714
+ var _this6 = this ;
673
715
674
716
lines . forEach ( function ( line , ind ) {
675
- lines [ ind ] = _this5 . htmlspecialchars ( line . substr ( 4 ) ) ;
717
+ lines [ ind ] = _this6 . htmlspecialchars ( line . substr ( 4 ) ) ;
676
718
} ) ;
677
719
var str = lines . join ( '\n' ) ;
678
720
@@ -744,15 +786,15 @@ var Parser = (function () {
744
786
} , {
745
787
key : 'parseList' ,
746
788
value : function parseList ( lines ) {
747
- var _this6 = this ;
789
+ var _this7 = this ;
748
790
749
791
var html = '' ;
750
792
var minSpace = 99999 ;
751
793
var rows = [ ] ;
752
794
753
795
// count levels
754
796
lines . forEach ( function ( line , key ) {
755
- var matches = line . match ( / ^ ( \s * ) ( (?: [ 0 - 9 a - z ] \. ? ) | \- | \+ | \* ) ( \s + ) ( .* ) $ / ) ;
797
+ var matches = line . match ( / ^ ( \s * ) ( (?: [ 0 - 9 a - z ] + \. ? ) | \- | \+ | \* ) ( \s + ) ( .* ) $ / ) ;
756
798
if ( matches ) {
757
799
var space = matches [ 1 ] . length ;
758
800
var type = / [ \+ \- \* ] / . test ( matches [ 2 ] ) ? 'ul' : 'ol' ;
@@ -790,6 +832,9 @@ var Parser = (function () {
790
832
var pattern = new RegExp ( "^\s{" + secondMinSpace + "}" ) ;
791
833
leftLines . push ( line . replace ( pattern , '' ) ) ;
792
834
} else {
835
+ if ( leftLines . length ) {
836
+ html += "<li>" + _this7 . parse ( leftLines . join ( "\n" ) ) + "</li>" ;
837
+ }
793
838
if ( lastType !== type ) {
794
839
if ( lastType . length ) {
795
840
html += '</' + lastType + '>' ;
@@ -798,10 +843,6 @@ var Parser = (function () {
798
843
html += '<' + type + '>' ;
799
844
}
800
845
801
- if ( leftLines . length ) {
802
- html += "<li>" + _this6 . parse ( leftLines . join ( "\n" ) ) + "</li>" ;
803
- }
804
-
805
846
leftLines = [ text ] ;
806
847
lastType = type ;
807
848
}
@@ -826,7 +867,7 @@ var Parser = (function () {
826
867
} , {
827
868
key : 'parseTable' ,
828
869
value : function parseTable ( lines , value ) {
829
- var _this7 = this ;
870
+ var _this8 = this ;
830
871
831
872
var _value = _slicedToArray ( value , 2 ) ;
832
873
@@ -905,7 +946,7 @@ var Parser = (function () {
905
946
html += ' align="' + aligns [ key ] + '"' ;
906
947
}
907
948
908
- html += '>' + _this7 . parseInline ( text ) + ( '</' + tag + '>' ) ;
949
+ html += '>' + _this8 . parseInline ( text ) + ( '</' + tag + '>' ) ;
909
950
} ) ;
910
951
911
952
html += '</tr>' ;
@@ -951,10 +992,10 @@ var Parser = (function () {
951
992
} , {
952
993
key : 'parseNormal' ,
953
994
value : function parseNormal ( lines ) {
954
- var _this8 = this ;
995
+ var _this9 = this ;
955
996
956
997
lines = lines . map ( function ( line ) {
957
- return _this8 . parseInline ( line ) ;
998
+ return _this9 . parseInline ( line ) ;
958
999
} ) ;
959
1000
960
1001
var str = lines . join ( "\n" ) . trim ( ) ;
@@ -1012,10 +1053,10 @@ var Parser = (function () {
1012
1053
} , {
1013
1054
key : 'parseHtml' ,
1014
1055
value : function parseHtml ( lines , type ) {
1015
- var _this9 = this ;
1056
+ var _this10 = this ;
1016
1057
1017
1058
lines . forEach ( function ( line ) {
1018
- line = _this9 . parseInline ( line , _this9 . specialWhiteList [ type ] ? _this9 . specialWhiteList [ type ] : '' ) ;
1059
+ line = _this10 . parseInline ( line , _this10 . specialWhiteList [ type ] ? _this10 . specialWhiteList [ type ] : '' ) ;
1019
1060
} ) ;
1020
1061
1021
1062
return lines . join ( "\n" ) ;
0 commit comments