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

Commit

Permalink
implement inline link
Browse files Browse the repository at this point in the history
  • Loading branch information
fperrad committed Mar 21, 2009
1 parent ba4ab03 commit 2e86cee
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/Compiler.pir
Expand Up @@ -226,10 +226,13 @@ Return generated HTML for all of its children.
$S1 = node.'title'()
unless $S1 goto L1
$S0 .= "\" title=\""
$I0 = length $S1
$I0 -= 2
$S1 = substr $S1, 1, $I0
$S0 .= $S1
L1:
$S0 .= "\">"
$S1 = node.'text'()
$S1 = self.'html_children'(node)
$S0 .= $S1
$S0 .= "</a>"
set code, $S0
Expand Down
14 changes: 12 additions & 2 deletions src/parser/actions.pm
Expand Up @@ -216,13 +216,23 @@ method Link($/, $key) {
make $( $/{$key} );
}

method ExplicitLink($/) {
my $mast := Markdown::Link.new( :title( ~$<Title>.text() ),
:url( ~$<Source><SourceContents>.text() ) );
for $<Label><Inline> {
$mast.push( $( $_ ) );
}
make $mast;
}

method AutoLink($/, $key) {
make $( $/{$key} );
}

method AutoLinkUrl($/) {
make Markdown::Link.new( :text( $/[0].text() ),
:url( $/[0].text() ) );
my $mast := Markdown::Link.new( :url( $/[0].text() ) );
$mast.push( Markdown::Line.new( :text( $/[0].text() ) ));
make $mast
}

method AutoLinkEmail($/) {
Expand Down
47 changes: 47 additions & 0 deletions src/parser/grammar.pg
Expand Up @@ -291,6 +291,45 @@ token StrongUI {

token Link {
| <AutoLink> {*} #= AutoLink
| <ExplicitLink> {*} #= ExplicitLink
}

token ExplicitLink {
<Label> <.Spnl> '(' <.Sp> <Source> <.Spnl> <Title> <.Sp> ')'
{*}
}

token Source {
| '<' <SourceContents> '>'
| <SourceContents>
}

token SourceContents {
[ <!_Sc> <Nonspacechar> ]*
}

token _Sc { '(' | ')' | '>' }

token Title {
| <TitleSingle>
| <TitleDouble>
| ''
}

token TitleSingle {
'\'' ( [ <!_TitleS> <!Newline> . ]* ) '\''
}

token _TitleS {
'\'' <.Sp> [ ')' | <.Newline> ]
}

token TitleDouble {
'"' ( [ <!_TitleD> <!Newline> . ]* ) '"'
}

token _TitleD {
'"' <.Sp> [ ')' | <.Newline> ]
}

token AutoLink {
Expand All @@ -310,6 +349,12 @@ token AutoLinkEmail {

token _Gt { '>' }

token Label {
'[' [ <!_EndLabel> <Inline> ]* ']'
}

token _EndLabel { ']' }

token Ticks1 { '`' }
token Ticks2 { '``' }
token Ticks3 { '```' }
Expand Down Expand Up @@ -382,6 +427,8 @@ token Newline { \n }

token Sp { <Spacechar>* }

token Spnl { <.Sp> [<.Newline> <.Sp>]? }

token SpecialChar { '*' | '_' | '`' | '&' | '[' | ']' | '<' | '!' | '\\' }

token NormalChar { <!SpecialChar> <!Spacechar> <!Newline> . }
Expand Down
45 changes: 45 additions & 0 deletions t/31-link.t
@@ -0,0 +1,45 @@
#! perl
# Copyright (C) 2009, Parrot Foundation.
# $Id$

=head1 Markdown inline link
=head2 Synopsis
% perl t/31-link.t
=cut

use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/../../../lib", "$FindBin::Bin";

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

language_output_is( 'markdown', <<'CODE', <<'OUT', 'inline link' );
This is an [example link](http://example.com/).
CODE
<p>This is an <a href="http://example.com/">example link</a>.</p>

OUT

language_output_is( 'markdown', <<'CODE', <<'OUT', 'inline link with title' );
This is an [example link](http://example.com/ "With a Title").
CODE
<p>This is an <a href="http://example.com/" title="With a Title">example link</a>.</p>

OUT


# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4:

0 comments on commit 2e86cee

Please sign in to comment.