#!/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!][pic w=50 h=50 style=left]hier ist mein text.[/infobox] [gallery style=cool navi=standard]my/path/[/gallery] [host]"; my $p = Parse::BBCode->new({ direct_attributes => 0, #close_open_tags => 1, tags => { b => '%{parse}s', pic => {output => '%{src}A,%{style}A,%{w}A,%{h}A,%a,%s,%{parse}s', class => 'block', single => 1 }, gallery => {output => '%{gallery}a', class => 'block', single => 0 }, infobox => {output => '%{infobox}s', class => 'block', single => 0 }, host => {output => 'http://www.example.com/', class => 'block', single => 1 }, }, escapes => { pic => sub { my ($w, $h) = @_; # Hier will ich die key/vals an eine Sub übergeben. return "{pic $w, $h}"; }, 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;