From 184ee1f7d026f009d8ae5d942064e3fe657c1a1a Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Fri, 15 May 2015 14:22:33 +1000 Subject: [PATCH] * Text::Dokuwiki::Parser : 'given/when' still experimental --- lib/Text/Dokuwiki/Parser.pm | 48 ++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 28 deletions(-) diff --git a/lib/Text/Dokuwiki/Parser.pm b/lib/Text/Dokuwiki/Parser.pm index f7b3fc6..ae7fdc2 100644 --- a/lib/Text/Dokuwiki/Parser.pm +++ b/lib/Text/Dokuwiki/Parser.pm @@ -177,40 +177,32 @@ sub _parse_text { last; } - given ($match) { - when ('\\ ') { # force newline - push @parts, [br => {}]; + if ($match eq '\\ ') { # force newline + push @parts, [br => {}]; + $line = $after; + next; + } elsif ($match) { + $endtag = $inlines->{$match}; + $endpos = index($after, $endtag, 0); + if ($endpos < 0) { # no closing marker? + push @parts, $match; $line = $after; next; } - default { - $endtag = $inlines->{$match}; - $endpos = index($after, $endtag, 0); - if ($endpos < 0) { # no closing marker? - push @parts, $match; - $line = $after; - next; - } - $content = substr($after, 0, $endpos); - $line = substr($after, $endpos + 2); - continue; - } + $content = substr($after, 0, $endpos); + $line = substr($after, $endpos + 2); } my %attrs; - given ($match) { - when ("//") { %attrs = ('font-style' => 'italic'); } - when ("**") { %attrs = ('font-weight' => 'bold'); } - when ("''") { %attrs = ('font-family' => 'monospace'); } - when ("__") { %attrs = ('text-decoration' => 'underline'); } - when ("{{") { push @parts, $self->_parse_include($content); next; } - when ("[[") { push @parts, $self->_parse_link($content); next; } - when ("((") { ...; next; } - default { - die("unrecognized inline: $match\n"); - next; - } - } + if ($match eq "//") { %attrs = ('font-style' => 'italic'); } + elsif ($match eq "**") { %attrs = ('font-weight' => 'bold'); } + elsif ($match eq "''") { %attrs = ('font-family' => 'monospace'); } + elsif ($match eq "__") { %attrs = ('text-decoration' => 'underline'); } + elsif ($match eq "{{") { push @parts, $self->_parse_include($content); next; } + elsif ($match eq "[[") { push @parts, $self->_parse_link($content); next; } + elsif ($match eq "((") { ...; next; } + elsif ($match) { die("unrecognized inline: $match\n"); } + if (%attrs) { push @parts, [span => \%attrs, $self->_parse_text($content)]; next;