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

Commit

Permalink
Browse files Browse the repository at this point in the history
loose/tight list
  • Loading branch information
fperrad committed Mar 29, 2009
1 parent 5f65acc commit 8ff776c
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/Compiler.pir
Expand Up @@ -275,8 +275,15 @@ 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>"
L1:
$S0 .= $S1
unless $I0 goto L2
$S0 .= "</p>"
L2:
$S0 .= "</li>\n"
.local pmc code
new code, 'CodeString'
Expand Down
9 changes: 9 additions & 0 deletions src/Node.pir
Expand Up @@ -78,6 +78,15 @@ for Markdown.
.end
.namespace ['Markdown'; 'ListItem']
.sub 'loose' :method
.param pmc value :optional
.param int has_value :opt_flag
.tailcall self.'attr'('loose', value, has_value)
.end
.namespace ['Markdown'; 'RefLink']
.sub 'image' :method
Expand Down
13 changes: 9 additions & 4 deletions src/parser/actions.pm
Expand Up @@ -181,7 +181,9 @@ method BulletListTight($/) {
method BulletListLoose($/) {
my $mast := Markdown::ItemizedList.new();
for $<BulletListItem> {
$mast.push( $( $_ ) );
my $item := $( $_ );
$item.loose( 1 );
$mast.push( $item );
}
make $mast;
}
Expand All @@ -192,11 +194,12 @@ method BulletListItem($/) {

method ListItem($/) {
if ( $<ListContinuationBlock> ) {
my $mast := Markdown::Para.new( $( $<ListBlock> ) );
my $mast := Markdown::ListItem.new( :loose( 1 ),
$( $<ListBlock> ) );
for $<ListContinuationBlock> {
$mast.push( $( $_ ) );
}
make Markdown::ListItem.new( $mast );
make $mast;
}
else {
make Markdown::ListItem.new( $( $<ListBlock> ) );
Expand Down Expand Up @@ -235,7 +238,9 @@ method OrderedListTight($/) {
method OrderedListLoose($/) {
my $mast := Markdown::OrderedList.new();
for $<OrderedListItem> {
$mast.push( $( $_ ) );
my $item := $( $_ );
$item.loose( 1 );
$mast.push( $item );
}
make $mast;
}
Expand Down
2 changes: 1 addition & 1 deletion src/parser/grammar.pg
Expand Up @@ -148,7 +148,7 @@ token BulletListItem {
}

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

Expand Down
16 changes: 15 additions & 1 deletion t/14-list.t
Expand Up @@ -15,7 +15,7 @@ use warnings;
use FindBin;
use lib "$FindBin::Bin/../../../lib", "$FindBin::Bin";

use Parrot::Test tests => 2;
use Parrot::Test tests => 3;
use Test::More;

language_output_is( 'markdown', <<'CODE', <<'OUT', 'unordered' );
Expand Down Expand Up @@ -44,6 +44,20 @@ CODE

OUT

language_output_is( 'markdown', <<'CODE', <<'OUT', 'unordered loose' );
* Bird
* Magic
CODE
<ul>
<li><p>Bird</p></li>
<li><p>Magic</p></li>
</ul>

OUT


# Local Variables:
# mode: cperl
Expand Down

0 comments on commit 8ff776c

Please sign in to comment.