Browse Source

* Text::Dokuwiki::Parser : 'given/when' still experimental

master
Alex 'AdUser' Z 10 years ago
parent
commit
2006bfb204
  1. 100
      lib/Text/Dokuwiki/Parser.pm

100
lib/Text/Dokuwiki/Parser.pm

@ -262,72 +262,58 @@ sub parse {
($buf, $mode, $attrs) = ('', '', {}); ($buf, $mode, $attrs) = ('', '', {});
} }
given ($line) { # macro
# macro if ($line =~ m/~~NO(TOC|CACHE)~~/) {
when (m/~~NO(TOC|CACHE)~~/) { next; # ignore
next; # ignore } elsif ($line =~ m/^\s?(={2,6}) (.+) \g{1}\s*/o) {
}
# header # header
when (m/^\s?(={2,6}) (.+) \g{1}\s*/o) { my $level = $1 =~ tr/=/=/;
my $level = $1 =~ tr/=/=/; $level = 7 - $level; # invert
$level = 7 - $level; # invert push @tree, ["h$level" => {}, $2];
push @tree, ["h$level" => {}, $2]; next;
next; } elsif ($line =~ m/^\s?<(code|file)(?:\s+(\S+)\s+(\S+))?>\s*$/o) {
}
# code/file block # code/file block
when (m/^\s?<(code|file)(?:\s+(\S+)\s+(\S+))?>\s*$/o) { $mode = "block/$1";
$mode = "block/$1"; $attrs = ($2) ? {class => $2, file => $3} : {};
$attrs = ($2) ? {class => $2, file => $3} : {}; next;
next; } elsif ($line =~ m/\s?<nowiki>/o) {
}
# nowiki block # nowiki block
when (m/\s?<nowiki>/o) { $mode = "block/nowiki";
$mode = "block/nowiki"; next;
next; } elsif ($line = m/^(\s{2})+([\*-])\s+(.+)/o) {
}
# lists # lists
when (m/^(\s{2})+([\*-])\s+(.+)/o) { $mode = 'list';
$mode = 'list'; $buf = [];
$buf = []; push @{ $buf }, $line;
push @{ $buf }, $line; next;
next; } elsif ($line = m/^\s?(>)+\s*(.+)/o) {
}
# quotes # quotes
when (m/^\s?(>)+\s*(.+)/o) { my $level = $1 =~ tr/>/>/;
my $level = $1 =~ tr/>/>/; push @tree, [blockquote => {level => $level}, $2];
push @tree, [blockquote => {level => $level}, $2]; next;
next; } elsif ($line = m/^\s?[\|\^]/o) {
}
# table # table
when (m/^\s?[\|\^]/o) { $mode = 'table';
$mode = 'table'; $buf = [];
$buf = []; push @{ $buf }, $line;
push @{ $buf }, $line; next;
next; } elsif ($line = m/^\s{2}(\S.+)/o) {
}
# code idented with two spaces # code idented with two spaces
when (m/^\s{2}(\S.+)/o) { $mode = 'code';
$mode = 'code'; $buf = $line . "\n";
$buf = $line . "\n"; next;
next; } elsif ($line =~ m/^\s?(\S.+)/o) {
}
# nonempty line # nonempty line
when (m/^\s?(\S.+)/o) { push @tree, [p => {}, $self->_parse_text($1)];
push @tree, [p => {}, $self->_parse_text($1)]; next;
next; } elsif ($line =~ m/^\s*$/o) {
} # empty lines
# empty lines; push @tree, [br => {}];
when (m/^\s*$/) { $mode = '';
push @tree, [br => {}]; next;
$mode = '';
next;
}
# catchall
default {
printf "Unmatched % 3d: %s\n", $linenum, $line;
continue;
}
} }
# catchall
printf "Unmatched % 3d: %s\n", $linenum, $line;
} }
return [div => {}, @tree ]; return [div => {}, @tree ];

Loading…
Cancel
Save