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

Commit

Permalink
more quoteblock
Browse files Browse the repository at this point in the history
  • Loading branch information
fperrad committed Mar 28, 2009
1 parent d92427e commit 95c189a
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 16 deletions.
14 changes: 8 additions & 6 deletions src/Compiler.pir
Expand Up @@ -197,20 +197,22 @@ Return generated HTML for all of its children.
.local pmc code
new code, 'CodeString'
$S0 = "<blockquote>\n"
set code, $S0
$S0 .= " "
.local pmc iter
iter = node.'iterator'()
iter_loop:
unless iter goto iter_end
.local pmc cpast
cpast = shift iter
$P0 = self.'html'(cpast)
code .= " <p>"
code .= $P0
code .= "</p>\n"
$S1 = self.'html'(cpast)
$S0 .= $S1
goto iter_loop
iter_end:
code .= "</blockquote>\n\n"
$I0 = length $S0
dec $I0
$S0 = substr $S0, 0, $I0
$S0 .= "</blockquote>\n\n"
set code, $S0
.return (code)
.end

Expand Down
35 changes: 33 additions & 2 deletions src/parser/actions.pm
Expand Up @@ -85,13 +85,44 @@ method SetextHeading2($/) {

method BlockQuote($/) {
my $mast := Markdown::BlockQuote.new();
for $<BlockQuoteRaw> {
for $<BlockQuoteChunk> {
$mast.push( $( $_ ) );
}
make $mast;
}

method BlockQuoteRaw($/) {
method BlockQuoteChunk($/) {
my $mast := Markdown::Para.new();
my $first := 1;
for $<BlockQuoteLine> {
unless ( $first ) {
$mast.push( Markdown::Word.new( :text( "\n" ) ) );
}
$mast.push( $( $_ ) );
$first := 0;
}
make $mast;
}

method BlockQuoteLine($/) {
my $mast := Markdown::Node.new();
$mast.push( $( $<BlockQuoteFirstLine> ) );
for $<BlockQuoteNextLine> {
$mast.push( Markdown::Word.new( :text( "\n" ) ) );
$mast.push( $( $_ ) );
}
make $mast;
}

method BlockQuoteFirstLine($/) {
my $mast := Markdown::Node.new();
for $<Inline> {
$mast.push( $( $_ ) );
}
make $mast;
}

method BlockQuoteNextLine($/) {
my $mast := Markdown::Node.new();
for $<Inline> {
$mast.push( $( $_ ) );
Expand Down
25 changes: 18 additions & 7 deletions src/parser/grammar.pg
Expand Up @@ -70,16 +70,27 @@ token Heading {
}

token BlockQuote {
<BlockQuoteRaw>+
[ <BlockQuoteChunk> <.BlankLine>* ]+
{*}
}

token BlockQuoteRaw {
[
<._Chevron> ' '? <Inline>+
[ <!_Chevron> <!BlankLine> <Inline>+ ]*
<.BlankLine>*
]
token BlockQuoteChunk {
<BlockQuoteLine>+
{*}
}

token BlockQuoteLine {
<BlockQuoteFirstLine> <BlockQuoteNextLine>*
{*}
}

token BlockQuoteFirstLine {
<._Chevron> ' '? <Inline>+ <Newline>
{*}
}

token BlockQuoteNextLine {
<!_Chevron> <!BlankLine> <Inline>+ <Newline>
{*}
}

Expand Down
51 changes: 50 additions & 1 deletion t/12-blockquote.t
Expand Up @@ -15,7 +15,7 @@ use warnings;
use FindBin;
use lib "$FindBin::Bin/../../../lib", "$FindBin::Bin";

use Parrot::Test tests => 1;
use Parrot::Test tests => 4;
use Test::More;

language_output_is( 'markdown', <<'CODE', <<'OUT', 'BlockQuote 1' );
Expand All @@ -29,6 +29,55 @@ CODE

OUT

language_output_is( 'markdown', <<'CODE', <<'OUT', 'BlockQuote 2' );
> Use the > character in front of a line, *just like in email*.
> Use it if you're quoting a person, a song or whatever.
CODE
<blockquote>
<p>Use the > character in front of a line, <em>just like in email</em>.
Use it if you're quoting a person, a song or whatever.</p>
</blockquote>
OUT
language_output_is( 'markdown', <<'CODE', <<'OUT', 'BlockQuote 3' );
> You can use *italic* or lists inside them also.
And just like with other paragraphs,
all of these lines are still
part of the blockquote, even without the > character in front.
To end the blockquote, just put a blank line before the following paragraph.
CODE
<blockquote>
<p>You can use <em>italic</em> or lists inside them also.
And just like with other paragraphs,
all of these lines are still
part of the blockquote, even without the > character in front.</p>
</blockquote>
<p>To end the blockquote, just put a blank line before the following paragraph.</p>
OUT
language_output_is( 'markdown', <<'CODE', <<'OUT', 'BlockQuote 4' );
> Use the > character in front of a line, *just like in email*.
> Use it if you're quoting a person, a song or whatever.

CODE
<blockquote>
<p>Use the > character in front of a line, <em>just like in email</em>.</p>

<p>Use it if you're quoting a person, a song or whatever.</p>
</blockquote>
OUT
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
Expand Down

0 comments on commit 95c189a

Please sign in to comment.