#!/usr/bin/perl -T use strict; use warnings; use CGI::Carp qw(fatalsToBrowser); use Parse::BBCode; print "Content-type: text; charset=utf-8\n\n"; my $teststring = "[b]bold[/b] [host] [pic src=/mfolder/myimage.jpg w=100px h=50px style=test] some text [infobox headline=Hello world! content=[pic w=50 h=50 style=left] hier ist mein text.] [gallery path=[host]myfolder/ style=cool navi=standard] [host]"; my $p = Parse::BBCode->new({ direct_attributes => 0, #close_open_tags => 1, tags => { b => '%{parse}s', pic => {output => '%{pic}s', class => 'block', single => 1 }, gallery => {output => '%{gallery}s', class => 'block', single => 1 }, infobox => {output => '%{infobox}s', class => 'block', single => 1 }, host => {output => 'http://www.example.com/', class => 'block', single => 1 }, }, escapes => { pic => sub { my ($parser, $attr, $content, $attribute_fallback) = @_; # Hier will ich die key/vals an eine Sub übergeben. return "{pic $parser, $attr, $content, $attribute_fallback}"; }, gallery => sub { my ($parser, $tag, $text) = @_; return "{gallery $text/}"; }, infobox => sub { my ($parser, $tag, $text) = @_; return "{infobox $text/}"; }, }, } ); my $parsed = $p->render($teststring); print "

input

\n"; print $teststring; print "

output

\n"; print $parsed;