Click here to get back home

Possible bug in HTML::BBCode?

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Possible bug in HTML::BBCode? YorHel 11-01-2005
Posted by YorHel on November 1, 2005, 9:37 am
Please log in for more thread options


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



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



Similar ThreadsPosted
Another bug in HTML::BBCode November 4, 2005, 8:01 am
ANNOUNCE: BBCode::Parser August 27, 2005, 12:43 pm
[RFC] HTML::Dashboard (Spreadsheet-like formatting for HTML tables) April 16, 2007, 4:50 pm
HTML ---> PDF October 27, 2004, 2:13 am
HTML::TableExtract October 11, 2004, 9:30 pm
[RFC] HTML::FormatData May 13, 2005, 2:51 pm
[RFC] HTML::CheckArgs May 13, 2005, 2:49 pm
HTML::TableExtractor November 30, 2004, 6:42 am
CGI.pm and HTML tables December 15, 2004, 12:34 am
[RFC] HTML::Formit.pm February 16, 2005, 9:52 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap