@@ -162,7 +162,9 @@ var Parser = (function () {
162162
163163 html += result ;
164164 } ) ;
165-
165+ if ( this . hooks . afterParse ) {
166+ html = this . call ( 'afterParse' , html ) ;
167+ }
166168 return html ;
167169 }
168170
@@ -241,7 +243,7 @@ var Parser = (function () {
241243
242244 // link
243245 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>' ) ;
245247 } ) ;
246248
247249 text = text . replace ( / < ( \/ ? ) ( [ a - z 0 - 9 - ] + ) ( \s + [ ^ > ] * ) ? > / ig, function ( match , p1 , p2 , p3 ) {
@@ -312,13 +314,14 @@ var Parser = (function () {
312314 } ) ;
313315
314316 // 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 ) ;
322325 text = text . replace ( / < ( [ _ a - z 0 - 9 -\. \+ ] + @ [ ^ @ ] + \. [ a - z ] { 2 , } ) > / ig, "<a href=\"mailto:$1\">$1</a>" ) ;
323326
324327 // autolink url
@@ -334,6 +337,45 @@ var Parser = (function () {
334337 return text ;
335338 }
336339
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+
337379 /**
338380 * parseBlock
339381 *
@@ -344,7 +386,7 @@ var Parser = (function () {
344386 } , {
345387 key : 'parseBlock' ,
346388 value : function parseBlock ( text , lines ) {
347- var _this4 = this ;
389+ var _this5 = this ;
348390
349391 this . blocks = [ ] ;
350392 this . current = 'normal' ;
@@ -447,7 +489,7 @@ var Parser = (function () {
447489 case / ^ { 4 } / . test ( line ) :
448490 emptyCount = 0 ;
449491
450- if ( this . isBlock ( 'pre' ) ) {
492+ if ( this . isBlock ( 'pre' ) || this . isBlock ( 'list' ) ) {
451493 this . setBlock ( key ) ;
452494 } else if ( this . isBlock ( 'normal' ) ) {
453495 this . startBlock ( 'pre' , key ) ;
@@ -459,14 +501,14 @@ var Parser = (function () {
459501 var tableMatches = / ^ ( (?: (?: (?: [ : ] * \- [ : ] * ) + (?: \| | \+ ) ) | (?: (?: \| | \+ ) (?: [ : ] * \- [ : ] * ) + ) | (?: (?: [ : ] * \- [ : ] * ) + (?: \| | \+ ) (?: [ : ] * \- [ : ] * ) + ) ) + ) $ / g. exec ( line ) ;
460502 if ( this . isBlock ( 'normal' ) ) {
461503 ( function ( ) {
462- var block = _this4 . getBlock ( ) ;
504+ var block = _this5 . getBlock ( ) ;
463505 var head = false ;
464506
465507 if ( block . length === 0 || block [ 0 ] !== 'normal' || / ^ \s * $ / . test ( lines [ block [ 2 ] ] ) ) {
466- _this4 . startBlock ( 'table' , key ) ;
508+ _this5 . startBlock ( 'table' , key ) ;
467509 } else {
468510 head = true ;
469- _this4 . backBlock ( 1 , 'table' ) ;
511+ _this5 . backBlock ( 1 , 'table' ) ;
470512 }
471513
472514 if ( tableMatches [ 1 ] [ 0 ] == '|' ) {
@@ -495,7 +537,7 @@ var Parser = (function () {
495537 aligns . push ( align ) ;
496538 } ) ;
497539
498- _this4 . setBlock ( key , [ head , aligns ] ) ;
540+ _this5 . setBlock ( key , [ head , aligns ] ) ;
499541 } ) ( ) ;
500542 }
501543 break ;
@@ -669,10 +711,10 @@ var Parser = (function () {
669711 } , {
670712 key : 'parsePre' ,
671713 value : function parsePre ( lines ) {
672- var _this5 = this ;
714+ var _this6 = this ;
673715
674716 lines . forEach ( function ( line , ind ) {
675- lines [ ind ] = _this5 . htmlspecialchars ( line . substr ( 4 ) ) ;
717+ lines [ ind ] = _this6 . htmlspecialchars ( line . substr ( 4 ) ) ;
676718 } ) ;
677719 var str = lines . join ( '\n' ) ;
678720
@@ -744,15 +786,15 @@ var Parser = (function () {
744786 } , {
745787 key : 'parseList' ,
746788 value : function parseList ( lines ) {
747- var _this6 = this ;
789+ var _this7 = this ;
748790
749791 var html = '' ;
750792 var minSpace = 99999 ;
751793 var rows = [ ] ;
752794
753795 // count levels
754796 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 + ) ( .* ) $ / ) ;
756798 if ( matches ) {
757799 var space = matches [ 1 ] . length ;
758800 var type = / [ \+ \- \* ] / . test ( matches [ 2 ] ) ? 'ul' : 'ol' ;
@@ -790,6 +832,9 @@ var Parser = (function () {
790832 var pattern = new RegExp ( "^\s{" + secondMinSpace + "}" ) ;
791833 leftLines . push ( line . replace ( pattern , '' ) ) ;
792834 } else {
835+ if ( leftLines . length ) {
836+ html += "<li>" + _this7 . parse ( leftLines . join ( "\n" ) ) + "</li>" ;
837+ }
793838 if ( lastType !== type ) {
794839 if ( lastType . length ) {
795840 html += '</' + lastType + '>' ;
@@ -798,10 +843,6 @@ var Parser = (function () {
798843 html += '<' + type + '>' ;
799844 }
800845
801- if ( leftLines . length ) {
802- html += "<li>" + _this6 . parse ( leftLines . join ( "\n" ) ) + "</li>" ;
803- }
804-
805846 leftLines = [ text ] ;
806847 lastType = type ;
807848 }
@@ -826,7 +867,7 @@ var Parser = (function () {
826867 } , {
827868 key : 'parseTable' ,
828869 value : function parseTable ( lines , value ) {
829- var _this7 = this ;
870+ var _this8 = this ;
830871
831872 var _value = _slicedToArray ( value , 2 ) ;
832873
@@ -905,7 +946,7 @@ var Parser = (function () {
905946 html += ' align="' + aligns [ key ] + '"' ;
906947 }
907948
908- html += '>' + _this7 . parseInline ( text ) + ( '</' + tag + '>' ) ;
949+ html += '>' + _this8 . parseInline ( text ) + ( '</' + tag + '>' ) ;
909950 } ) ;
910951
911952 html += '</tr>' ;
@@ -951,10 +992,10 @@ var Parser = (function () {
951992 } , {
952993 key : 'parseNormal' ,
953994 value : function parseNormal ( lines ) {
954- var _this8 = this ;
995+ var _this9 = this ;
955996
956997 lines = lines . map ( function ( line ) {
957- return _this8 . parseInline ( line ) ;
998+ return _this9 . parseInline ( line ) ;
958999 } ) ;
9591000
9601001 var str = lines . join ( "\n" ) . trim ( ) ;
@@ -1012,10 +1053,10 @@ var Parser = (function () {
10121053 } , {
10131054 key : 'parseHtml' ,
10141055 value : function parseHtml ( lines , type ) {
1015- var _this9 = this ;
1056+ var _this10 = this ;
10161057
10171058 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 ] : '' ) ;
10191060 } ) ;
10201061
10211062 return lines . join ( "\n" ) ;
0 commit comments