Possible bug in HTML::BBCode?

Possible bug in HTML::BBCode?

am 01.11.2005 18:37:32 von YorHel

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:





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:




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

Re: Possible bug in HTML::BBCode?

am 04.11.2005 13:37:36 von YorHel

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:

>



>
>
> 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:

>

>
> 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|\[\*\]([^(\[]+)|
  • $1
  • |gs;
    ---
    > $content =~ s|^
    \n|\n|s;
    > # $content =~ s|\[\*\]([^(\[]+)|
  • $1
  • |gs;
    > $content =~ s|\[\*\]([^(\[]+)|_list_removelastbr($1)|egs;
    362a365,369
    > sub _list_removelastbr {
    > my $content = shift;
    > $content =~ s|
    [\s\n]*$||;
    > return "
  • $content
  • \n";
    > }

    As you can see, it's a small and ugly modification, but it works fine -
    for me at least :)

    Greets, //YorHel