Browse Source

+ Text::Dokuwiki->_parse_include

master
Zubrikhin Alexey 10 years ago
parent
commit
00dd2277e2
  1. 36
      lib/Text/Dokuwiki.pm

36
lib/Text/Dokuwiki.pm

@ -118,6 +118,40 @@ sub _parse_link {
return [a => {href => $href}, @text]; return [a => {href => $href}, @text];
} }
sub _parse_include {
my ($self, $content) = @_;
if ($content =~ m|{{([a-z]+)>(.*)}}|oi) {
...
}
my ($lpad, $rpad, $src, %attrs) = ('', '', '');
if ($content =~ m!^{{(\s*)([^\s\|]+)(\s*)\|(.*)}}!oi) {
($lpad, $src, $rpad) = ($1, $2, $3);
$attrs{title} = $4;
} elsif ($content =~ m!^{{(\s*)(\S+)(\s*)}}!) {
($lpad, $src, $rpad) = ($1, $2, $3);
} else {
($src) = ($content =~ s/{{(.+)}}/$1/or);
}
$attrs{align} = ($lpad ne '')
? (($rpad ne '') ? 'center' : 'right')
: 'left';
$src =~ s<\?(\d+)(?:x(\d+))?>
<
$attrs{width} = $1 if $1;
$attrs{height} = $2 if $2;
''
>ioe;
$src =~ s|:|/|o;
$attrs{src} = $src;
return [img => \%attrs];
}
my $inlines = { my $inlines = {
"__" => "__", # underline "__" => "__", # underline
"//" => "//", # italic "//" => "//", # italic
@ -171,9 +205,9 @@ sub _parse_text {
when ("**") { %attrs = ('font-weight' => 'bold'); } when ("**") { %attrs = ('font-weight' => 'bold'); }
when ("''") { %attrs = ('font-family' => 'monospace'); } when ("''") { %attrs = ('font-family' => 'monospace'); }
when ("__") { %attrs = ('text-decoration' => 'underline'); } when ("__") { %attrs = ('text-decoration' => 'underline'); }
when ("{{") { push @parts, $self->_parse_include($content); next; }
when ("[[") { push @parts, $self->_parse_link($content); next; } when ("[[") { push @parts, $self->_parse_link($content); next; }
when ("((") { ...; next; } when ("((") { ...; next; }
when ("{{") { ...; next; }
default { default {
die("unrecognized inline: $match\n"); die("unrecognized inline: $match\n");
next; next;

Loading…
Cancel
Save