in reply to Unbalanced Tags
I would recommend a couple of minor changes though. Very specifically in the scrub_input function at the bottom the main loop should probably be:
because at some point you are likely to want to have an optional handler for returns. Something like this:while ($raw =~ /\G([\w ]*)/g) { $scrubbed .= $1; my $pos = pos($raw); if ($raw =~ /\G($is_handled)/g) { $scrubbed .= $handler->{ lc($1) }->(\$raw); # See perlre. If the handler matches something of # length 0, it won't match something of length 0 # the next time through. So... pos($raw) = pos($raw); } unless (pos($raw)) { if (length($raw) == $pos) { # EXIT HERE # return $scrubbed . $handler->{post}->(\$raw); } else { my $char = substr($raw, $pos, 1); pos($raw) = $pos + 1; $scrubbed .= &encode_entities($char); } } }
That handler will preserve indents properly. (I say optional because some users do not like that kind of autoformatting, so it should be user-configurable.)sub { my $t_ref = shift; if ($$t_ref =~ /\G( *)/g) { my $indent = $1; $indent =~ s/ / /g; return "<br>\n$indent"; } else { confess("This shouldn't happen"); } }
Anyways this node will probably make little sense to you without reading the other. Which may take a while to digest...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re (tilly) 1: Unbalanced Tags
by lzcd (Pilgrim) on Jan 19, 2001 at 07:23 UTC |