Thread CMS Tags parsen (29 answers)
Opened by cbxk1xg at 2010-11-26 16:27

cbxk1xg
 2011-05-25 11:49
#149147 #149147
User since
2003-10-20
496 Artikel
BenutzerIn
[default_avatar]
Ok, neuer Tag, neuer Versuch. Ich versuche das nun mit dem Modul zu machen. Klappt aber eher noch schlechter. Verschachtelungen werden nicht erkannt und ich raffe einfach nicht, wie ich meine key/values an eine Sub übergeben kann.

Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/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   => '<b>%{parse}s</b>',
                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 "<h2>input</h2>\n";
print $teststring;
print "<h2>output</h2>\n";
print $parsed;

View full thread CMS Tags parsen