diff --git a/src/Compiler.pir b/src/Compiler.pir index 7d8c0c8..c66a3af 100644 --- a/src/Compiler.pir +++ b/src/Compiler.pir @@ -106,8 +106,10 @@ Return generated HTML for all of its children. .sub 'html_children' :method .param pmc node - .param string sep :optional - .param int has_sep :opt_flag + .param string ssep :optional + .param int has_ssep :opt_flag + .param string esep :optional + .param int has_esep :opt_flag .local pmc code, iter code = new 'CodeString' iter = node.'iterator'() @@ -118,10 +120,13 @@ Return generated HTML for all of its children. $P0 = self.'html'(cpast) $I0 = elements $P0 unless $I0 goto iter_loop - code .= $P0 - unless has_sep goto L1 - code .= sep + unless has_ssep goto L1 + code .= ssep L1: + code .= $P0 + unless has_esep goto L2 + code .= esep + L2: goto iter_loop iter_end: .return (code) @@ -144,7 +149,7 @@ Return generated HTML for all of its children. .sub 'html' :method :multi(_, ['Markdown'; 'Document']) .param pmc node - .tailcall self.'html_children'(node, "\n\n") + .tailcall self.'html_children'(node, '', "\n\n") .end @@ -224,7 +229,7 @@ Return generated HTML for all of its children. .param pmc node $S0 = "
\n" $S0 .= " " - $S1 = self.'html_children'(node, "\n\n") + $S1 = self.'html_children'(node, '', "\n\n") $I0 = length $S1 dec $I0 $S1 = substr $S1, 0, $I0 @@ -274,16 +279,18 @@ Return generated HTML for all of its children. .sub 'html' :method :multi(_, ['Markdown'; 'ListItem']) .param pmc node - $S1 = self.'html_children'(node) - $I0 = node.'loose'() $S0 = "
  • " - unless $I0 goto L1 - $S0 .= "

    " + $I0 = node.'loose'() + if $I0 goto L1 + $S1 = self.'html_children'(node) + goto L2 L1: - $S0 .= $S1 - unless $I0 goto L2 - $S0 .= "

    " + $S1 = self.'html_children'(node, "

    ", "

    \n\n") + $I0 = length $S1 + $I0 -= 2 + $S1 = substr $S1, 0, $I0 L2: + $S0 .= $S1 $S0 .= "
  • \n" .local pmc code new code, 'CodeString' diff --git a/src/parser/actions.pm b/src/parser/actions.pm index 07c0354..3b7f09a 100644 --- a/src/parser/actions.pm +++ b/src/parser/actions.pm @@ -194,8 +194,7 @@ method BulletListItem($/) { method ListItem($/) { if ( $ ) { - my $mast := Markdown::ListItem.new( :loose( 1 ), - $( $ ) ); + my $mast := Markdown::ListItem.new( $( $ ) ); for $ { $mast.push( $( $_ ) ); } @@ -211,13 +210,20 @@ method ListBlock($/) { for $ { $mast.push( $( $_ ) ); } + for $ { + $mast.push( Markdown::Newline.new() ); + $mast.push( $( $_ ) ); + } make $mast; } +method ListBlockLine($/) { + make $( $ ); +} + method ListContinuationBlock($/) { my $mast := Markdown::Node.new(); for $ { - $mast.push( Markdown::Newline.new() ); $mast.push( $( $_ ) ); } make $mast; diff --git a/src/parser/grammar.pg b/src/parser/grammar.pg index cae5540..97d78d7 100644 --- a/src/parser/grammar.pg +++ b/src/parser/grammar.pg @@ -148,12 +148,12 @@ token BulletListItem { } token ListItem { - [ <.Bullet> | <.Enumerator> ] * <.Newline> + [ <.Bullet> | <.Enumerator> ] * {*} } token ListBlock { - + * + + <.Newline> * {*} } @@ -190,6 +190,7 @@ token OrderedListItem { token ListBlockLine { + {*} } token _ListItem { diff --git a/t/14-list.t b/t/14-list.t index e2c735e..0c45321 100644 --- a/t/14-list.t +++ b/t/14-list.t @@ -15,10 +15,10 @@ use warnings; use FindBin; use lib "$FindBin::Bin/../../../lib", "$FindBin::Bin"; -use Parrot::Test tests => 3; +use Parrot::Test tests => 5; use Test::More; -language_output_is( 'markdown', <<'CODE', <<'OUT', 'unordered' ); +language_output_is( 'markdown', <<'CODE', <<'OUT', 'unordered tight' ); - An item in a bulleted (unordered) list - Another item in a bulleted list @@ -31,7 +31,7 @@ CODE OUT -language_output_is( 'markdown', <<'CODE', <<'OUT', 'ordered' ); +language_output_is( 'markdown', <<'CODE', <<'OUT', 'ordered tight' ); 1. An item in a enumeradted (ordered) list 2. Another item in a enumeradted list @@ -58,6 +58,39 @@ CODE OUT +language_output_is( 'markdown', <<'CODE', <<'OUT', 'with continuation' ); + +* A list item. + With continuation. +* Another item in the list. + +CODE +
      +
    • A list item. +With continuation.
    • +
    • Another item in the list.
    • +
    + +OUT + +language_output_is( 'markdown', <<'CODE', <<'OUT', 'with multi-para' ); + +* Para 1. + + Para 2. + +* Another item in the list. + +CODE +
      +
    • Para 1.

      + +

      Para 2.

    • +
    • Another item in the list.

    • +
    + +OUT + # Local Variables: # mode: cperl