Gossamer Forum
Home : General : Perl Programming :

Markup instead of HTML

Quote Reply
Markup instead of HTML
Hi, with the following code subs I can allow users only to use:

- bold-tags
- italic tags
- newline tags

But how can I make sure that a startmarkup will
only get changed if the endmarkup is alsow there?
So change if alsow exists!


Then: bla bla bla I forgot the end on will not get changed!
But: this will!

Code:
sub join_encode {
# --------------------------------------------------------

my %hash = @_;
my ($tmp, $col, $output);

foreach $col (@db_cols) {
$tmp = $hash{$col};
$tmp =~ s/^\s //g; # Trim leading blanks...
$tmp =~ s/\s $//g; # Trim trailing blanks...
$tmp =~ s/\Q$db_delim\E/~~/og; # Change delimeter to ~~ symbol.
$tmp =~ s/\n/ /g; # Change newline to extra space
$tmp =~ s/\r//g; # Remove Windows linefeed character.
$tmp =~ s/<([^>]|\n)*>//g; # Markup Mod: first remove all html.
$tmp =~ s/\[enter\]/< br >/ig; # Markup Mod: [ enter ] => < br >
$tmp =~ s/\[b\]/<b>/ig; # Markup Mod: => < b >
$tmp =~ s/\[\/b\]/<\/b>/ig; # Markup Mod:
=> < /b >
$tmp =~ s/\[i\]/<i>/ig; # Markup Mod: => < /i >
$tmp =~ s/\[\/i\]/<\/i>/ig; # Markup Mod:
=> < /i >
$output .= $tmp . $db_delim; # Build Output.
}
chop $output; # remove extra delimeter.
$output .= "\n"; # add linefeed char.
return $output;
}

sub split_decode {
# --------------------------------------------------------

my ($input) = shift;
my (@array) = split (/\Q$db_delim\E/o, $input, $#db_cols 1);
foreach (@array) {
s/~~/$db_delim/g; # Retrieve Delimiter..
}
return @array;
}
Just remove the extra spaced at < br > < b > and so on! UUB sucks Wink
Quote Reply
Re: Markup instead of HTML In reply to
$tmp =~ s~\[b\]([^\[]+)\[/b\]~<b>$1</b>~ig; # Bold tags
$tmp =~ s~\[i\]([^\[]+)\[/i\]~<i>$1</i>~ig; # Italic tags

- Mark


Astro-Boy!!
http://www.zip.com.au/~astroboy/
Quote Reply
Re: Markup instead of HTML In reply to
It's was very late when I posted this :-)

But I thought this morning that I should find [ starttag ] en the [ / endtag] and then replace the tags with the text inside. Is this what the code you provided does?

....and what will happen in peope will enter only a [ starttag ]? Can I let the script search and remove all starttags en endtags at the end of my subs. So tags that didn't get converted (only starters or only ends) get removed! Or is this not the way?



ADDED:
.....and does this make the formprocessing much slower? Because my forms now takes a lot longer too process; or is it just my bad connection this morning?
Quote Reply
Re: Markup instead of HTML In reply to
Nobody?

I hope someone can answer my added "red" question! I'm really wondering Wink

Quote Reply
Re: Markup instead of HTML In reply to
Not at all.

Probably your connection :)

Paul Wilson.
http://www.wiredon.net/gt/
http://www.perlmad.com/
Quote Reply
Re: Markup instead of HTML In reply to
Thanks Paul; now I can sleep in peace tonight.

- Chris

BTW It's already 2:51 in amsterdam, holland

Quote Reply
Re: Markup instead of HTML In reply to
OOOO how weird.

I never looked at your profile and always assumed you were female. Your username reminded me of Christina.....lol

Ah well......it's 1.50am in Manchester, England :)

How come your homepage is gossamer-threads?

Paul Wilson.
http://www.wiredon.net/gt/
http://www.perlmad.com/