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

cbxk1xg
 2010-11-27 22:02
#143137 #143137
User since
2003-10-20
496 Artikel
BenutzerIn
[default_avatar]
Quick and dirty. Verstehe.

Also ich hab jetzt das hier:

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
sub parse {
    my ($text,$mode) = @_;
    my $output = "";
    my $stack = [];
    while (length $text) {
        if ($text =~ s/^\[(pic|gallery|audio|video|infobox)=//) {
            my $name = $1;
            # tag
            my $attr = "";
            if ($text =~ s/^([^\[\]]+)//) {
                $attr = $1;
            }
            push @$stack, [$name, $attr, ""];
        }
        else {
            my $out;
            if ($text =~ s/^\[//) {
                $out = "[";
            }
            if ($text =~ s/^\]//) {
                # closing tag
                my $last = pop @$stack;
                my ($name, $attr, $content) = @$last;
                $out = render($mode, $name, $attr, $content);
            }
            else {
                # text
                if ($text =~ s/^([^\[\]]+)//) {
                    $out = $1;
                }
            }
            if (@$stack > 0) {
                $stack->[-1]->[2] .= $out;
            }
            else {
                $output .= $out;
            }
        }
    }
    return $output;
}


Und das schmeisst mir nen komischen Fehler.
Code: (dl )
Can't use an undefined value as an ARRAY reference at /var/www/index.pl line 2841


2841 bezieht sich auf
Code (perl): (dl )
                my ($name, $attr, $content) = @$last;


Kann man das nicht etwas dahingehend verfeinern, daß die Regex immer matched, egal auf welchen Tag? Hauptsache er ist syntaktisch korrekt? Dann könnte ich doch in der sub render alles rauswerfen, was da nicht hingehört. Z.B. mit
Code (perl): (dl )
1
2
3
if ($tag eq "pic"){...machwas...}
if ($tag eq "gallery"){...machwas...}
else {return;}


Edit: Ich hab jetzt schon jede erdenklich RegEx ausprobiert. Das bringt alles nix. Der Code läuft super wenn die Tags vorhanden sind. Aber wenn nur ein Tag nixht existiert, ist alles im Ar... Das ist echt frustrierend.
Last edited: 2010-11-27 22:36:21 +0100 (CET)

View full thread CMS Tags parsen