Skip to content

Commit 9c21acd

Browse files
committed
Fix bug with block quote split over two paragraphs and an abutting paragraph at the start.
Closes evilstreak#96 i.e. this case: a > b > c
1 parent 78d07af commit 9c21acd

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

lib/markdown.js

+14-7
Original file line numberDiff line numberDiff line change
@@ -671,26 +671,33 @@ Markdown.dialects.Gruber = {
671671

672672
var jsonml = [];
673673

674-
// separate out the leading abutting block, if any
674+
// separate out the leading abutting block, if any. I.e. in this case:
675+
//
676+
// a
677+
// > b
678+
//
675679
if ( block[ 0 ] != ">" ) {
676680
var lines = block.split( /\n/ ),
677-
prev = [];
681+
prev = [],
682+
line_no = block.lineNumber;
678683

679684
// keep shifting lines until you find a crotchet
680685
while ( lines.length && lines[ 0 ][ 0 ] != ">" ) {
681686
prev.push( lines.shift() );
687+
line_no++;
682688
}
683689

684-
// reassemble!
685-
block = lines.join( "\n" );
686-
jsonml.push.apply( jsonml, this.processBlock( prev.join( "\n" ), [] ) );
690+
var abutting = mk_block( prev.join( "\n" ), "\n", block.lineNumber );
691+
jsonml.push.apply( jsonml, this.processBlock( abutting, [] ) );
692+
// reassemble new block of just block quotes!
693+
block = mk_block( lines.join( "\n" ), block.trailing, line_no );
687694
}
688695

696+
689697
// if the next block is also a blockquote merge it in
690698
while ( next.length && next[ 0 ][ 0 ] == ">" ) {
691699
var b = next.shift();
692-
block = new String(block + block.trailing + b);
693-
block.trailing = b.trailing;
700+
block = mk_block( block + block.trailing + b, b.trailing, block.lineNumber );
694701
}
695702

696703
// Strip off the leading "> " and re-process as a block.

test/regressions.t.js

+10
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,16 @@ test( "blockquote", function(t, md) {
384384
] ],
385385
"blockquote with interesting content");
386386

387+
t.equivalent(
388+
bq.call( md, mk_block( 'p\n> a', '\n\n', 1 ), [ mk_block( '> b', '\n', 4) ] ),
389+
[ [ 'para', 'p' ],
390+
[ 'blockquote',
391+
[ 'para', 'a' ],
392+
[ 'para', 'b' ]
393+
]
394+
],
395+
"blockquote with abutting paragraph");
396+
387397
});
388398

389399
test( "referenceDefn", function(t, md) {

0 commit comments

Comments
 (0)