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

Commit

Permalink
implement reference link (first step: currently not resolved)
Browse files Browse the repository at this point in the history
  • Loading branch information
fperrad committed Mar 22, 2009
1 parent 2e86cee commit 4bf8542
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/Compiler.pir
Expand Up @@ -239,6 +239,28 @@ Return generated HTML for all of its children.
.return (code)
.end

=item html(Markdown::RefLink node)

=cut

.sub 'html' :method :multi(_,['Markdown';'RefLink'])
.param pmc node
.local pmc code
new code, 'CodeString'
$S0 = "<a href=\"\">"
$S1 = self.'html_children'(node)
if $S1 goto L1
$S1 = node.'key'()
$I0 = length $S1
$I0 -= 2
$S1 = substr $S1, 1, $I0
L1:
$S0 .= $S1
$S0 .= "</a>"
set code, $S0
.return (code)
.end

=item html(Markdown::Email node)

=cut
Expand Down
10 changes: 10 additions & 0 deletions src/Node.pir
Expand Up @@ -30,6 +30,7 @@ for Markdown.
p6meta.'new_class'('Markdown::ListItem', 'parent'=>base)
p6meta.'new_class'('Markdown::OrderedList', 'parent'=>base)
p6meta.'new_class'('Markdown::Para', 'parent'=>base)
p6meta.'new_class'('Markdown::RefLink', 'parent'=>base)
p6meta.'new_class'('Markdown::Space', 'parent'=>base)
p6meta.'new_class'('Markdown::Strong', 'parent'=>base)
p6meta.'new_class'('Markdown::Title', 'parent'=>base)
Expand Down Expand Up @@ -59,6 +60,15 @@ for Markdown.
.end
.namespace [ 'Markdown';'RefLink' ]
.sub 'key' :method
.param pmc value :optional
.param int has_value :opt_flag
.tailcall self.'attr'('key', value, has_value)
.end
.namespace [ 'Markdown';'Title' ]
.sub 'level' :method
Expand Down
16 changes: 16 additions & 0 deletions src/parser/actions.pm
Expand Up @@ -216,6 +216,22 @@ method Link($/, $key) {
make $( $/{$key} );
}

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

method ReferenceLinkDouble($/) {
my $mast := Markdown::RefLink.new( :key( ~$<Label>[1].text() ) );
for $<Label>[0]<Inline> {
$mast.push( $( $_ ) );
}
make $mast;
}

method ReferenceLinkSingle($/) {
make Markdown::RefLink.new( :key( ~$<Label>.text() ) );
}

method ExplicitLink($/) {
my $mast := Markdown::Link.new( :title( ~$<Title>.text() ),
:url( ~$<Source><SourceContents>.text() ) );
Expand Down
18 changes: 18 additions & 0 deletions src/parser/grammar.pg
Expand Up @@ -292,6 +292,24 @@ token StrongUI {
token Link {
| <AutoLink> {*} #= AutoLink
| <ExplicitLink> {*} #= ExplicitLink
| <ReferenceLink> {*} #= ReferenceLink
}

token ReferenceLink {
| <ReferenceLinkDouble> {*} #= ReferenceLinkDouble
| <ReferenceLinkSingle> {*} #= ReferenceLinkSingle
}

token _EmptyLabel { '[]' }

token ReferenceLinkDouble {
<Label> <.Spnl> <!_EmptyLabel> <Label>
{*}
}

token ReferenceLinkSingle {
<Label> [ <.Spnl> <._EmptyLabel> ]?
{*}
}

token ExplicitLink {
Expand Down

0 comments on commit 4bf8542

Please sign in to comment.