|
Posted by YorHel on November 4, 2005, 4:37 am
Please log in for more thread options
YorHel wrote:
> Hello,
>
> While using the HTML::BBCode module (version 1.03 from CPAN), I noticed
> something when using lists while the linebreaks option is true. Have a
> look at the following example:
>
> #!/bin/perl
>
> use strict;
> use warnings;
> use HTML::BBCode;
>
> my $bbc = HTML::BBCode->new({
> no_html => 1,
> linebreaks => 1 });
>
> my $bbcode=<<'BBCODE';
> Some colors:
> [list]
> [*]Red
> [*]Blue
> [*]Yellow
> [/list]
> BBCODE
>
> print $bbc->parse($bbcode);
> __END__
>
>
> this will output:
>
> Some colors:<br />
> <ul><br />
> <li> Red<br />
> </li><li> Blue<br />
> </li><li> Yellow<br />
> </li></ul><br />
>
>
> This would add a total of 2 newlines between the "Some colors" and the
> actual list, not including the margins/paddings set with CSS. This will
> also add a newline after every item, while - depending on your CSS -
> this is done automatically. In most situations, this won't be a
> problem, but it might also be considered as a possible bug.
> The following output would be prefered:
>
> Some colors:<br />
> <ul>
> <li> Red
> </li><li> Blue
> </li><li> Yellow
> </li></ul><br />
>
> Or, even better in my case - also delete the linebreak after the "Some
> colors:" - but I don't think that's really urgent.
> Currently, the only workaround I found is to remove the linebreaks from
> the original BBCode, but this will look pretty nasty for large lists.
>
> Is this a known bug? Or is it a feature? Are there other (prettier)
> workarounds I didn't see?
>
> Greets, YorHel
Ok, since I haven't got any replies, but still wanted some results, I
modified the module a little, so the list-tag-output would be as I
expected. For the people interested in the changes (from version 1.03
of HTML::BBCode from CPAN), here's the output of diff:
353c353,355
< $content =~ s|\[\*\]([^(\[]+)|<li>$1</li>|gs;
---
> $content =~ s|^<br />\n|\n|s;
> # $content =~ s|\[\*\]([^(\[]+)|<li>$1</li>|gs;
> $content =~ s|\[\*\]([^(\[]+)|_list_removelastbr($1)|egs;
362a365,369
> sub _list_removelastbr {
> my $content = shift;
> $content =~ s|<br />[\s\n]*$||;
> return "<li>$content</li>\n";
> }
As you can see, it's a small and ugly modification, but it works fine -
for me at least :)
Greets, //YorHel
|