/usr/share/perl5/Petal/Canonicalizer/XHTML.pm is in libpetal-perl 2.23-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 | # ------------------------------------------------------------------
# Petal::Canonicalizer::XHTML - Builds an XHTML canonical Petal file
# ------------------------------------------------------------------
# Author: Jean-Michel Hiver
# Description: This modules mainly implements the XML::Parser
# 'Stream' interface. It receives XML events and builds Petal
# canonical data, i.e.
#
# <foo petal:if="bar">Hello</foo>
#
# Might be canonicalized to something like
#
# <?petal:if name="bar"?>
# <foo>Hello</foo>
# <?petal:end?>
#
# On top of that, Petal::Canonicalizer::XHTML will self close certain
# XHTML specific tags, like <br /> or <input ... />
# ------------------------------------------------------------------
package Petal::Canonicalizer::XHTML;
use strict;
use warnings;
use base qw /Petal::Canonicalizer::XML/;
# http://lists.webarch.co.uk/pipermail/petal/2002-August/000074.html
# here's a list[1] of empty elements (which need careful handling):
#
# ---8<---
# area
# base
# basefont
# br
# col
# frame
# hr
# img
# input
# isindex
# link
# meta
# param
# --->8---
#
# [1] http://www.w3.org/TR/html401/index/elements.html
# $class->StartTag();
# -------------------
# Called for every start tag with a second parameter of the element type.
# It will check for special PETAL attributes like petal:if, petal:loop, etc...
# and rewrite the start tag into @Petal::Canonicalizer::XML::Result accordingly.
#
# For example
# <foo petal:if="blah">
#
# Is rewritten
# <?petal:if name="blah"?><foo>...
sub StartTag
{
Petal::load_code_generator(); # we will use it later
my $class = shift;
push @Petal::Canonicalizer::XML::NodeStack, {};
return if ($class->_is_inside_content_or_replace());
my $tag = $_;
($tag) = $tag =~ /^<\s*((?:\w|\:|\-)*)/;
my $att = { %_ };
$class->_use_macro ($tag, $att);
$class->_on_error ($tag, $att);
$class->_define ($tag, $att);
$class->_define_slot ($tag, $att);
$class->_condition ($tag, $att);
$class->_repeat ($tag, $att);
$class->_is_xinclude ($tag) and $class->_xinclude ($tag, $att) and return;
$class->_replace ($tag, $att);
my $petal = quotemeta ($Petal::NS);
# if a petal:replace attribute was set, then at this point _is_inside_content_or_replace()
# should return TRUE and this code should not be executed
unless ($class->_is_inside_content_or_replace())
{
# for every attribute which is not a petal: attribute,
# we need to convert $variable into <?var name="variable"?>
foreach my $key (keys %{$att})
{
next if ($key =~ /^$petal:/);
my $text = $att->{$key};
my $token_re = $Petal::Hash::String::TOKEN_RE;
my @vars = $text =~ /$token_re/gsm;
my %vars = map { $_ => 1 } @vars;
@vars = sort { length ($b) <=> length ($a) } keys %vars;
foreach my $var (@vars)
{
my $command = $var;
$command =~ s/^\$//;
$command =~ s/^\{//;
$command =~ s/\}$//;
$command = $class->_encode_backslash_semicolon ($command);
$command = "<?var name=\"$command\"?>";
$text =~ s/\Q$var\E/$command/g;
}
$att->{$key} = $text;
}
$class->_attributes ($tag, $att);
my @att_str = ();
foreach my $key (keys %{$att})
{
next if ($key =~ /^$petal:/);
my $value = $att->{$key};
if ($value =~ /^<\?attr/)
{
push @att_str, $value;
}
else
{
my $tokens = Petal::CodeGenerator->_tokenize (\$value);
my @res = map {
($_ =~ /$Petal::CodeGenerator::PI_RE/s) ?
$_ :
do {
$_ =~ s/\&/&/g;
$_ =~ s/\</</g;
$_ =~ s/\>/>/g;
$_ =~ s/\"/"/g;
$_;
};
} @{$tokens};
push @att_str, $key . '="' . (join '', @res) . '"';
}
}
my $att_str = join " ", @att_str;
if ( (uc ($tag) eq 'AREA') or
(uc ($tag) eq 'BASE') or
(uc ($tag) eq 'BASEFONT') or
(uc ($tag) eq 'BR') or
(uc ($tag) eq 'COL') or
(uc ($tag) eq 'FRAME') or
(uc ($tag) eq 'HR') or
(uc ($tag) eq 'IMG') or
(uc ($tag) eq 'INPUT') or
(uc ($tag) eq 'ISINDEX') or
(uc ($tag) eq 'LINK') or
(uc ($tag) eq 'META') or
(uc ($tag) eq 'PARAM') )
{
if (defined $att->{"$petal:omit-tag"})
{
my $expression = $att->{"$petal:omit-tag"} || 'string:1';
$Petal::Canonicalizer::XML::NodeStack[$#Petal::Canonicalizer::XML::NodeStack]->{'omit-tag'} = $expression;
push @Petal::Canonicalizer::XML::Result, (defined $att_str and $att_str) ?
"<?if name=\"false:$expression\"?><$tag $att_str /><?end?>" :
"<?if name=\"false:$expression\"?><$tag /><?end?>";
}
else
{
push @Petal::Canonicalizer::XML::Result, (defined $att_str and $att_str) ? "<$tag $att_str />" : "<$tag />";
}
}
else
{
if (defined $att->{"$petal:omit-tag"})
{
my $expression = $att->{"$petal:omit-tag"} || 'string:1';
$Petal::Canonicalizer::XML::NodeStack[$#Petal::Canonicalizer::XML::NodeStack]->{'omit-tag'} = $expression;
push @Petal::Canonicalizer::XML::Result, (defined $att_str and $att_str) ?
"<?if name=\"false:$expression\"?><$tag $att_str><?end?>" :
"<?if name=\"false:$expression\"?><$tag><?end?>";
}
else
{
push @Petal::Canonicalizer::XML::Result, (defined $att_str and $att_str) ? "<$tag $att_str>" : "<$tag>";
}
}
$class->_content ($tag, $att);
}
}
# $class->EndTag();
# -----------------
# Called for every end tag with a second parameter of the element type.
# It will check in the @Petal::Canonicalizer::XML::NodeStack to see if this end-tag also needs to close
# some 'condition' or 'repeat' statements, i.e.
#
# </li>
#
# Could be rewritten
#
# </li><?petal:end?>
#
# If the starting LI used a loop, i.e. <li petal:loop="element list">
sub EndTag
{
my $class = shift;
return if ($class->_is_inside_content_or_replace ( 'endtag' ));
my ($tag) = $_ =~ /^<\/\s*((?:\w|\:|\-)*)/;
my $node = pop (@Petal::Canonicalizer::XML::NodeStack);
return if ($class->_is_xinclude ($tag));
if ( (not (defined $node->{replace} and $node->{replace})) and
(uc ($tag) ne 'AREA') and
(uc ($tag) ne 'BASE') and
(uc ($tag) ne 'BASEFONT') and
(uc ($tag) ne 'BR') and
(uc ($tag) ne 'COL') and
(uc ($tag) ne 'FRAME') and
(uc ($tag) ne 'HR') and
(uc ($tag) ne 'IMG') and
(uc ($tag) ne 'INPUT') and
(uc ($tag) ne 'ISINDEX') and
(uc ($tag) ne 'LINK') and
(uc ($tag) ne 'META') and
(uc ($tag) ne 'PARAM') )
{
if (defined $node->{'omit-tag'})
{
my $expression = $node->{'omit-tag'};
push @Petal::Canonicalizer::XML::Result, "<?if name=\"false:$expression\"?></$tag><?end?>";
}
else
{
push @Petal::Canonicalizer::XML::Result, "</$tag>";
}
}
my $repeat = $node->{repeat} || '0';
my $condition = $node->{condition} || '0';
my $define_slot = $node->{define_slot} || '0';
push @Petal::Canonicalizer::XML::Result, map { '<?end?>' } 1 .. ($repeat+$condition+$define_slot);
if (exists $node->{'on-error'})
{
my $expression = $node->{'on-error'};
push @Petal::Canonicalizer::XML::Result, "<?endeval errormsg=\"$expression\"?>";
}
}
1;
|