use strict; use warnings; use Text::Balanced qw( extract_bracketed ); use HTML::Entities qw( encode_entities ); my $default_allowed_tags = do { my @tags = qw( A ABBR ACRONYM B BIG CITE CODE DFN EM I KBD Q SAMP SMALL SPAN STRONG SUB SUP TT VAR ); qr/${\( join "|", map quotemeta, @tags )}/; }; sub parse_markup { my ($text, $tags) = @_; $tags ||= $default_allowed_tags; my ($before, $match) = ($text =~ m{ \A # start of string (.*?) # leading text ($before) ( # either... \<\!-- # the start of a comment | # or... $tags\< # a tag ) }xsm) or do { my @return = split /\|/, $text; $return[0] = encode_entities($return[0]); return @return; }; # strip $before from $text substr($text, 0, length($before)) = ''; # If the first thing that needed to be handled was a comment if ($match eq ' TEXT