@@ -295,6 +295,7 @@ export default class Parser {
295295 let emptyCount = 0
296296 // analyze by line
297297 for ( let key in lines ) {
298+ key = parseInt ( key ) // ES6 的 bug for key in Array 循环时返回的 key 是字符串,不是 int
298299 let line = lines [ key ]
299300 // code block is special
300301 if ( matches = line . match ( / ^ ( \s * ) ( ~ | ` ) { 3 , } ( [ ^ ` ~ ] * ) $ / i) ) {
@@ -353,8 +354,9 @@ export default class Parser {
353354 // list
354355 case / ^ ( \s * ) ( (?: [ 0 - 9 a - z ] \. ) | \- | \+ | \* ) \s + / . test ( line ) :
355356 let matches = line . match ( / ^ ( \s * ) ( (?: [ 0 - 9 a - z ] \. ) | \- | \+ | \* ) \s + / )
357+
356358 let listSpace = matches [ 1 ] . length
357- let emptyCount = 0
359+ emptyCount = 0
358360
359361 // opened
360362 if ( this . isBlock ( 'list' ) ) {
@@ -481,7 +483,7 @@ export default class Parser {
481483 }
482484
483485 emptyCount ++
484- } else if ( emptyCount == 0 ) {
486+ } else if ( emptyCount === 0 ) {
485487 this . setBlock ( key )
486488 } else {
487489 this . startBlock ( 'normal' , key )
@@ -514,7 +516,7 @@ export default class Parser {
514516 }
515517 } else {
516518 let block = this . getBlock ( )
517- if ( ! block || ! block . length || block [ 0 ] !== 'normal' ) {
519+ if ( block === null || block . length === 0 || block [ 0 ] !== 'normal' ) {
518520 this . startBlock ( 'normal' , key )
519521 } else {
520522 this . setBlock ( key )
@@ -535,7 +537,7 @@ export default class Parser {
535537 optimizeBlocks ( blocks , lines ) {
536538 blocks = this . call ( 'beforeOptimizeBlocks' , blocks , lines )
537539
538- blocks . forEach ( function ( block , key ) {
540+ blocks . forEach ( ( block , key ) => {
539541 let prevBlock = blocks [ key - 1 ] ? blocks [ key - 1 ] : null
540542 let nextBlock = blocks [ key + 1 ] ? blocks [ key + 1 ] : null
541543
@@ -552,13 +554,13 @@ export default class Parser {
552554 }
553555
554556 if ( 'normal' === type ) {
555- // one sigle empty line
557+ // combine two splitted list
556558 if ( from === to && lines [ from ] . match ( / ^ \s * $ / )
557- && prevBlock && nextBlock ) {
559+ && prevBlock . length && nextBlock . length ) {
558560 if ( prevBlock [ 0 ] === 'list' && nextBlock [ 0 ] === 'list' ) {
559561 // combine 3 blocks
560562 blocks [ key - 1 ] = [ 'list' , prevBlock [ 1 ] , nextBlock [ 2 ] , null ]
561- array_splice ( blocks , key , 2 )
563+ blocks . splice ( key , 2 )
562564 }
563565 }
564566 }
@@ -840,11 +842,11 @@ export default class Parser {
840842 * @return string
841843 */
842844 parseNormal ( lines ) {
843- lines . forEach ( ( line , key ) => {
844- lines [ key ] = this . parseInline ( line )
845+ lines = lines . map ( line => {
846+ return this . parseInline ( line )
845847 } )
846848
847- let str = lines . join ( "\n" )
849+ let str = lines . join ( "\n" ) . trim ( )
848850 str = str . replace ( / ( \n \s * ) { 2 , } / , "</p><p>" )
849851 str = str . replace ( / \n / , "<br>" )
850852
0 commit comments