in reply to Regex to match between [ref] and [/ref]

:) HTML::BBCode, Parse::BBCode
  • Comment on Re: Regex to match between [ref] and [/ref]

Replies are listed 'Best First'.
Re^2: Regex to match between [ref] and [/ref]
by ultranerds (Hermit) on Jul 17, 2009 at 10:31 UTC
    Hi,

    Thanks for the reply. I just tried a basic test with Parse::BBcode, using their example:

    #!/usr/bin/perl print qq|Content-Type: text/html \n\n|; use Parse::BBCode; # \[\[([^]]+)\|([^]]+)\]\] my $test = qq|==Getting There== testing [ref]bla bla bla [[http://www.google.com]] <b> test </b> and [ +[http://www.google.com\|testing]] [/ref] hhh testing [ref]bla bla bla an[/ref] hhh |; my $p = Parse::BBCode->new({ tags => { # load the default tags Parse::BBCode::HTML->defaults, # add/override tags url => 'url:<a href="%{link}A">%{parse}s</a>', i => '<i>%{parse}s</i>', b => '<b>%{parse}s</b>', noparse => '<pre>%{html}s</pre>', code => sub { my ($parser, $attr, $content, $attribute_fallback) + = @_; if ($attr eq 'perl') { # use some syntax highlighter $content = highlight_perl($content); } else { $content = Parse::BBCode::escape_html($$conten +t); } "<tt>$content</tt>" }, test => 'this is klingon: %{klingon}s', }, escapes => { klingon => sub { my ($parser, $tag, $text) = @_; return translate_into_klingon($text); }, }, } ); my $code = $test; my $parsed = $p->render($code); use Data::Dumper; print Dumper($parsed);


    ..but I get an error:

    Not a HASH reference at /usr/lib/perl5/vendor_perl/5.8.4/Parse/BBCode.pm line 81.

    Any suggestions? I've never had much luck with those BBCode perl modules (thats why I tend to try and just do it with regex rules =))

    TIA

    Andy
      There is an error in the documentation (I thought I had already fixed that): any declaration that has a subref in it must be written like this:
      tagname => { code => sub { ... }, },
      I forgot this because the tagname is 'code', and my brain probably refused to duplicate a word. Please report, if you find any further bugs or documentation issues.

      edit: so that means it must be:

      my $p = Parse::BBCode->new({ tags => { ... code => { code => sub { my ($parser, $attr, $content, $attribute_fallback) = @ +_; }, }, ...