Skip to content
This repository has been archived by the owner on Jun 9, 2018. It is now read-only.

Commit

Permalink
fix for list : multi-paragraph vs continuation
Browse files Browse the repository at this point in the history
  • Loading branch information
fperrad committed Mar 29, 2009
1 parent 8ff776c commit 82e7ebf
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 22 deletions.
35 changes: 21 additions & 14 deletions src/Compiler.pir
Expand Up @@ -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'()
Expand All @@ -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)
Expand All @@ -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


Expand Down Expand Up @@ -224,7 +229,7 @@ Return generated HTML for all of its children.
.param pmc node
$S0 = "<blockquote>\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
Expand Down Expand Up @@ -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 = "<li>"
unless $I0 goto L1
$S0 .= "<p>"
$I0 = node.'loose'()
if $I0 goto L1
$S1 = self.'html_children'(node)
goto L2
L1:
$S0 .= $S1
unless $I0 goto L2
$S0 .= "</p>"
$S1 = self.'html_children'(node, "<p>", "</p>\n\n")
$I0 = length $S1
$I0 -= 2
$S1 = substr $S1, 0, $I0
L2:
$S0 .= $S1
$S0 .= "</li>\n"
.local pmc code
new code, 'CodeString'
Expand Down
12 changes: 9 additions & 3 deletions src/parser/actions.pm
Expand Up @@ -194,8 +194,7 @@ method BulletListItem($/) {

method ListItem($/) {
if ( $<ListContinuationBlock> ) {
my $mast := Markdown::ListItem.new( :loose( 1 ),
$( $<ListBlock> ) );
my $mast := Markdown::ListItem.new( $( $<ListBlock> ) );
for $<ListContinuationBlock> {
$mast.push( $( $_ ) );
}
Expand All @@ -211,13 +210,20 @@ method ListBlock($/) {
for $<Inline> {
$mast.push( $( $_ ) );
}
for $<ListBlockLine> {
$mast.push( Markdown::Newline.new() );
$mast.push( $( $_ ) );
}
make $mast;
}

method ListBlockLine($/) {
make $( $<OptionallyIndentedLine><Line> );
}

method ListContinuationBlock($/) {
my $mast := Markdown::Node.new();
for $<ListBlock> {
$mast.push( Markdown::Newline.new() );
$mast.push( $( $_ ) );
}
make $mast;
Expand Down
5 changes: 3 additions & 2 deletions src/parser/grammar.pg
Expand Up @@ -148,12 +148,12 @@ token BulletListItem {
}

token ListItem {
[ <.Bullet> | <.Enumerator> ] <ListBlock> <ListContinuationBlock>* <.Newline>
[ <.Bullet> | <.Enumerator> ] <ListBlock> <ListContinuationBlock>*
{*}
}

token ListBlock {
<Inline>+ <ListBlockLine>*
<Inline>+ <.Newline> <ListBlockLine>*
{*}
}

Expand Down Expand Up @@ -190,6 +190,7 @@ token OrderedListItem {

token ListBlockLine {
<!_ListItem> <!BlankLine> <OptionallyIndentedLine>
{*}
}

token _ListItem {
Expand Down
39 changes: 36 additions & 3 deletions t/14-list.t
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
<ul>
<li>A list item.
With continuation.</li>
<li>Another item in the list.</li>
</ul>

OUT

language_output_is( 'markdown', <<'CODE', <<'OUT', 'with multi-para' );
* Para 1.
Para 2.
* Another item in the list.
CODE
<ul>
<li><p>Para 1.</p>

<p>Para 2.</p></li>
<li><p>Another item in the list.</p></li>
</ul>

OUT


# Local Variables:
# mode: cperl
Expand Down

0 comments on commit 82e7ebf

Please sign in to comment.