Skip Menu |

This queue is for tickets about the Parse-BBCode CPAN distribution.

Maintainer(s)' notes

If you have any wishes, feel free to create a ticket.

Plans:

I would like to add callbacks to the parser so that you can gather some information about specific tags and ideally can manipulate them during parsing.

But there are already enough informations to create a download link for code tags, for example. See example/code_download.pl.

Parse::BBCode is now hosted on github, so for bug reports also check https://github.com/perlpunk/Parse-BBCode

Report information
The Basics
Id: 70931
Status: resolved
Priority: 0/
Queue: Parse-BBCode

People
Owner: Nobody in particular
Requestors: mendoza [...] pvv.ntnu.no
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: 0.13_003



I'd love to have a way of passing a custom attribute parsing routine. Right now I'm trying to inherit from Parse::BBCode and provide my own _validate_attr() method, but I'm not able to.
ti. 13. sep. 2011 10.35.04 skrev NICOMEN: Show quoted text
> I'd love to have a way of passing a custom attribute parsing routine. > > Right now I'm trying to inherit from Parse::BBCode and provide my own > _validate_attr() method, but I'm not able to.
I was able to successfully subclass it and check my own style of attributes ;)
Am Do 15. Sep 2011, 05:43:16, NICOMEN schrieb: Show quoted text
> ti. 13. sep. 2011 10.35.04 skrev NICOMEN:
> > I'd love to have a way of passing a custom attribute parsing routine. > > > > Right now I'm trying to inherit from Parse::BBCode and provide my own > > _validate_attr() method, but I'm not able to.
> > I was able to successfully subclass it and check my own style of > attributes ;)
hm, then maybe I should remove the underscore from the method (and actually I should rename it since it does not only validation but also the attribute parsing). thanks, I'll have to think a bit about it.
Show quoted text
> hm, then maybe I should remove the underscore from the method (and > actually I should rename it since it does not only validation but
also Show quoted text
> the attribute parsing).
So how about a method 'parse_attributes' that one can override? It gets called like that: # found a start of a tag $tagname, rest of the text is in $after my ($ok, $attributes, $attr_string, $end) = $self->parse_attributes( text => \$after, tag => lc $tagname, ); Example: '[foo some attribute string]text[/foo] bla' text in $after: ' some attribute string]text[/foo] bla' The method should remove the matched text in $after so that it contains: 'text[/foo] bla' The method must return a list: $ok: is the attribute string valid? 1 or 0 $attributes: an arrayref containing the attributes the method parsed, in the usual Parse::BBCode form $attr_string: the complete attribute string (needed for the output of the raw bbcode) $end: the closing square bracket if no closing bracket was found, it should return (0, [''], $attr_string, '') This makes it possible to parse attributes in any form, even containing square brackets itself. sub parse_attributes { my ($self, %args) = @_; my $text = $args{text}; my $tagname = $args{tag}; if ($tagname eq 'foo') { # work on $$text return $valid, ([@attr], $attr_string, ']'); } else { return $self->SUPER::parse_attributes(@_); } } What do you think?
I uploaded 0.13_002. the parse_attributes method can be overridden. I actually need this for non standard bbcode from an old forum software myself. If you have any feedback, let me know. I will make a regular release soon.
on. 28. sep. 2011 18.18.10 skrev TINITA: Show quoted text
> I uploaded 0.13_002. > > the parse_attributes method can be overridden. > > I actually need this for non standard bbcode from an old forum
software Show quoted text
> myself. > > If you have any feedback, let me know. > I will make a regular release soon.
Ok, thanks will download _002 and check it out. (Will file two new issues btw. So don't go anywhere! ;)
Am Mi 28. Sep 2011, 12:25:07, NICOMEN schrieb: Show quoted text
> (Will file two new > issues btw. So don't go anywhere! ;)
give me a break, I'm doing this in my free time =)
to. 29. sep. 2011 11.14.14 skrev TINITA: Show quoted text
> Am Mi 28. Sep 2011, 12:25:07, NICOMEN schrieb:
> > (Will file two new > > issues btw. So don't go anywhere! ;)
> > give me a break, I'm doing this in my free time =)
Hm, not exactly sure what should go in $end when actually finding something?
to. 29. sep. 2011 13.42.43 skrev NICOMEN: Show quoted text
> to. 29. sep. 2011 11.14.14 skrev TINITA:
> > Am Mi 28. Sep 2011, 12:25:07, NICOMEN schrieb:
> > > (Will file two new > > > issues btw. So don't go anywhere! ;)
> > > > give me a break, I'm doing this in my free time =)
> > Hm, not exactly sure what should go in $end when actually finding > something?
Ah sorry got it.
to. 29. sep. 2011 13.43.58 skrev NICOMEN: Show quoted text
> to. 29. sep. 2011 13.42.43 skrev NICOMEN:
> > to. 29. sep. 2011 11.14.14 skrev TINITA:
> > > Am Mi 28. Sep 2011, 12:25:07, NICOMEN schrieb:
> > > > (Will file two new > > > > issues btw. So don't go anywhere! ;)
> > > > > > give me a break, I'm doing this in my free time =)
> > > > Hm, not exactly sure what should go in $end when actually finding > > something?
> > Ah sorry got it.
It seems to me that get_attr_raw() is not working on the tag anymore?
to. 29. sep. 2011 15.38.50 skrev NICOMEN: Show quoted text
> to. 29. sep. 2011 13.43.58 skrev NICOMEN:
> > to. 29. sep. 2011 13.42.43 skrev NICOMEN:
> > > to. 29. sep. 2011 11.14.14 skrev TINITA:
> > > > Am Mi 28. Sep 2011, 12:25:07, NICOMEN schrieb:
> > > > > (Will file two new > > > > > issues btw. So don't go anywhere! ;)
> > > > > > > > give me a break, I'm doing this in my free time =)
> > > > > > Hm, not exactly sure what should go in $end when actually finding > > > something?
> > > > Ah sorry got it.
> > It seems to me that get_attr_raw() is not working on the tag anymore?
Also, maybe it would be an idea to be able to pass a subref in the constructor to not have to subclass it?
Am Do 29. Sep 2011, 09:38:50, NICOMEN schrieb: Show quoted text
> It seems to me that get_attr_raw() is not working on the tag anymore?
yes, you're right. I've never used this and I also have no test for it, so I didn't see the error. Fixed it in subversion. thanks
Am Do 29. Sep 2011, 09:44:29, NICOMEN schrieb: Show quoted text
> Also, maybe it would be an idea to be able to pass a subref in the > constructor to not have to subclass it?
Yes, I also thought about that. Parse::BBCode->new({ ... attribute_parser => $coderef, }); like that?