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