Rather than explain the following snippet should give you an idea of what I'm trying to do. I just can't quite get it going and respectfully ask for the help of the monks.
a) Is this right? I'm just trying to save writing the almost the same regex for every tag.
b) I can't figure out how to get the matched variables ($1, $2 etc..) into the text and I'm fresh out of ideas.
Code:
# ...
my %taglist_complex = (
'email' => "<a href='mailto:$1'>$2</a>",
'url' => "<a href='$1'>$2</a>",
'img' => "<img src='$1' alt='$2' />"
);
my %taglist_simple = (
'b' => '<b>$1</b>',
'i' => '<i>$1</i>',
'u' => '<u>$1</u>',
'url' => '<a href=\'$1\'>$1</a>',
'img' => '<img src=\'$1\' alt=\'$1\' />'
);
# Process Complex Tags -> [url="http://www.foo.bar.com"]foobar[/ur
+l]
while (my ($tag, $regex) = each %taglist_complex) {
$post =~ s/\[\s*$tag\s*=\s*['"]?([\w\W][^\]]*?)['"]?\](.[^\[|\
+]]*?)\[\s*\/\s*$tag\s*\]/$regex/gi;
}
# Process Simple Tags -> [url]http://www.foo.bar.com[/url]
while (my ($tag, $regex) = each %taglist_simple) {
$post =~ s/\[\s*$tag\s*\](.[^\[|\]]*?)\[\s*\/\s*$tag\s*\]/$reg
+ex/gi;
}
#...
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|