@@ -570,9 +570,10 @@ var Parser = (function () {
570
570
// normal
571
571
default :
572
572
if ( this . isBlock ( 'list' ) ) {
573
- var _matches = line . match ( / ^ ( \s * ) / ) ;
574
-
575
- if ( line . length == _matches [ 1 ] . length ) {
573
+ // let matches = line.match(/^(\s*)/)
574
+ //
575
+ // if (line.length == matches[1].length) { // empty line
576
+ if ( / ^ ( \s * ) / . test ( line ) ) {
576
577
// empty line
577
578
if ( emptyCount > 0 ) {
578
579
this . startBlock ( 'normal' , key ) ;
@@ -587,9 +588,9 @@ var Parser = (function () {
587
588
this . startBlock ( 'normal' , key ) ;
588
589
}
589
590
} else if ( this . isBlock ( 'footnote' ) ) {
590
- var _matches2 = line . match ( / ^ ( \s * ) / ) ;
591
+ var _matches = line . match ( / ^ ( \s * ) / ) ;
591
592
592
- if ( _matches2 [ 1 ] . length >= this . getBlock ( ) [ 3 ] [ 0 ] ) {
593
+ if ( _matches [ 1 ] . length >= this . getBlock ( ) [ 3 ] [ 0 ] ) {
593
594
this . setBlock ( key ) ;
594
595
} else {
595
596
this . startBlock ( 'normal' , key ) ;
@@ -613,10 +614,19 @@ var Parser = (function () {
613
614
this . startBlock ( 'normal' , key ) ;
614
615
}
615
616
} else if ( this . isBlock ( 'quote' ) ) {
616
- if ( / ^ \s * $ / . test ( line ) ) {
617
- this . startBlock ( 'normal' , key ) ;
618
- } else {
617
+ if ( / ^ ( \s * ) / . test ( line ) ) {
618
+ // empty line
619
+ if ( emptyCount > 0 ) {
620
+ this . startBlock ( 'normal' , key ) ;
621
+ } else {
622
+ this . setBlock ( key ) ;
623
+ }
624
+
625
+ emptyCount ++ ;
626
+ } else if ( $emptyCount == 0 ) {
619
627
this . setBlock ( key ) ;
628
+ } else {
629
+ this . startBlock ( 'normal' , key ) ;
620
630
}
621
631
} else {
622
632
var block = this . getBlock ( ) ;
@@ -664,11 +674,13 @@ var Parser = (function () {
664
674
}
665
675
666
676
if ( 'normal' === type ) {
667
- // combine two splitted list
677
+ // combine two blocks
678
+ var types = [ 'list' , 'quote' ] ;
679
+
668
680
if ( from === to && lines [ from ] . match ( / ^ \s * $ / ) && prevBlock && nextBlock ) {
669
- if ( prevBlock [ 0 ] === 'list' && nextBlock [ 0 ] === 'list' ) {
681
+ if ( prevBlock [ 0 ] == nextBlock [ 0 ] && types . indexOf ( prevBlock [ 0 ] !== - 1 ) ) {
670
682
// combine 3 blocks
671
- blocks [ key - 1 ] = [ 'list' , prevBlock [ 1 ] , nextBlock [ 2 ] , null ] ;
683
+ blocks [ key - 1 ] = [ prevBlock [ 0 ] , prevBlock [ 1 ] , nextBlock [ 2 ] , NULL ] ;
672
684
blocks . splice ( key , 2 ) ;
673
685
}
674
686
}
@@ -777,7 +789,6 @@ var Parser = (function () {
777
789
} , {
778
790
key : 'parseQuote' ,
779
791
value : function parseQuote ( lines ) {
780
- console . log ( lines ) ;
781
792
lines . forEach ( function ( line , key ) {
782
793
lines [ key ] = line . replace ( / ^ \s * > ? / , '' ) ;
783
794
} ) ;
@@ -1248,7 +1259,4 @@ var Parser = (function () {
1248
1259
} ) ( ) ;
1249
1260
1250
1261
exports [ 'default' ] = Parser ;
1251
-
1252
- var parser = new Parser ( ) ;
1253
- console . log ( parser . makeHtml ( '>1234\n1234' ) ) ;
1254
1262
module . exports = exports [ 'default' ] ;
0 commit comments