PApp
view release on metacpan or search on metacpan
PApp/XML.pm view on Meta::CPAN
use Convert::Scalar ':utf8';
use PApp::Util;
use PApp::Exception qw(fancydie);
use base 'Exporter';
$VERSION = 2.3;
@EXPORT_OK = qw(
xml_quote xml_attr xml_unquote xml_tag xml_cdata
xml_check xml_encoding xml2utf8 pod2xml
xml_include expand_pi xml_errorparser
);
=head2 Functions for XML-Generation
=over 4
=item xml_quote $string
Quotes (and returns) the given string so that it's contents won't be
interpreted by an XML parser (quotes ', ", <, & and > to avoid ]]>). Example:
print xml_quote q( <xx> & <[[]]> );
=> <xx> & <[[]]>
=item xml_cdata $string
Does the same thing as C<xml_quote>, but using CDATA constructs, rather
than quoting individual characters. Example:
print xml_cdata q(hi ]]> there);
=> <![CDATA[hi ]]]]><![CDATA[> there ]]>
=item xml_unquote $string
Unquotes (and returns) an XML string (by resolving it's entities and
CDATA sections). Currently, only the named predefined xml entities and
numerical character entities are resolved. Everything else is silently
ignored. Example:
print xml_unquote q( <![CDATA[text1]]> & text2! );
PApp/XML.pm view on Meta::CPAN
sub xml_quote {
local $_ = shift;
s/&/&/g;
s/</</g;
s/>/>/g;
#s/]]>/]]>/g; # avoids problems when ]] and > are quoted in seperate calls
$_;
}
sub xml_cdata {
local $_ = shift;
s/]]>/]]]]><![CDATA[>/g;
"<![CDATA[$_]]>";
}
sub xml_attr {
my $attrs;
for (my $i = 0; $i < $#_; $i += 2) {
local $_ = $_[$i+1];
s/&/&/g;
s/"/"/g;
PApp/XML.pm view on Meta::CPAN
api_version => 3,
strict_names => 1,
xml_mode => 1,
unbroken_text => 1,
case_sensitive => 1,
ignore_elements=> [qw(script)],
text_h => [sub {
if ($_[1] >= $errofs) {
$err->("<error>$errmsg, source<pre>\n"
. (xml_cdata substr $xml, $errofs >= 160 ? $errofs - 160 : 0, $errofs >= 160 ? 160 : $errofs)
. "÷"
. (xml_cdata substr $xml, $errofs, 160)
. "\n</pre></error>");
$errofs = 1e99;
} else {
$delayed and $err->();
}
$output .= PApp::XML::xml_quote $_[0];
}, "dtext, offset"],
start_h => [sub {
my $tag = $xmlname->($_[0]);
push @tag, $tag;
PApp/XML.pm view on Meta::CPAN
sub view_pod { stag pod => xmlns => "http://www.nethype.de/xmlns/xmlpod" => $_[1]->content->present ($_[0]) }
sub view_head1 { title_tag head1 => $_[1]->title->present ($_[0]) => $_[1]->content->present ($_[0]) }
sub view_head2 { title_tag head2 => $_[1]->title->present ($_[0]) => $_[1]->content->present ($_[0]) }
sub view_head3 { title_tag head3 => $_[1]->title->present ($_[0]) => $_[1]->content->present ($_[0]) }
sub view_head4 { title_tag head4 => $_[1]->title->present ($_[0]) => $_[1]->content->present ($_[0]) }
sub view_over { stag over => indent => $_[1]->indent, $_[1]->content->present ($_[0]) }
sub view_begin { stag begin => format => $_[1]->format, $_[1]->content->present ($_[0]) }
sub view_verbatim { stag verbatim => PApp::XML::xml_cdata $_[1] }
sub view_textblock { stag para => $_[1] }
sub view_seq_code { stag code => $_[1] }
sub view_seq_bold { stag bold => $_[1] }
sub view_seq_italic { stag italic => $_[1] }
sub view_seq_link { stag link => $_[1] }
sub view_seq_index { stag index => $_[1] }
sub view_seq_file { stag file => $_[1] }
sub view_seq_zero { "" }
sub view_seq_space { PApp::XML::xml_quote $_[1] }
Marco Maisenhelder <marco@nethype.de>,
L<http://www.nethype.de/agni>
=cut
use Getopt::Long;
use PApp;
use PApp::Config ();
use PApp::SQL;
use PApp::XML qw(xml_quote xml_attr xml_tag xml_cdata);
use PApp::Util qw(dumpval); # debug#d#
use PApp::Event ();
use MIME::Base64;
use Convert::Scalar qw(utf8_valid);
use Agni;
my $opt_force;
sub do_some_tests {
my $lg = path_obj_by_gid $path, 5100000420;
my $us = path_obj_by_gid $path, 17180000071;
my $t2 = Time::HiRes::time;
warn $t2-$t1;
}
sub quote_attr($) {
local $_ = $_[0];
s/^/\t/gm;
$_ = "\n$_\n ";
xml_cdata $_;
}
sub print_attr {
my ($fh, $type, $data) = @_;
my $encode = !utf8_valid $data || $data =~ /[\x{0}-\x{8}\x{b}\x{c}\x{e}-\x{1f}]/;
print $fh "\n ",
(xml_tag "a",
type => $type,
" Filenames: *.papp *.pxml *.pxsl
" URL: http://papp.plan9.de/
" You can set the "papp_include_html" variable so that html will be
" rendered as such inside phtml sections (in case you actually put html
" there - papp does not require that). Also, rendering html tends to keep
" the clutter high on the screen - mixing three languages is difficult
" enough(!). PS: it is also slow.
" configurable variables
" let papp_cdata_contains_perl = 1
syntax clear
if exists("b:current_syntax")
finish
endif
let s:papp_cpo_save = &cpo
set cpo&vim
syn case match
syn region xmlComment start=+<!+ end=+>+ contains=xmlCommentPart,xmlCommentError extend
syn match xmlCommentError contained "[^><!]"
syn region xmlCommentPart start=+--+ end=+--+ contained contains=xmlTodo
syn region xmlCdata start=+<!\[CDATA\[+ end=+]]>+ contains=xmlCdataStart,xmlCdataEnd,@xmlCdataHook keepend extend
syn match xmlCdataStart +<!\[CDATA\[+ contained contains=xmlCdataCdata
syn keyword xmlCdataCdata CDATA contained
syn match xmlCdataEnd +]]>+ contained
syn cluster xmlCdataHook contains=@papp
if exists("papp_cdata_contains_perl")
syn cluster xmlCdataHook add=@PAppPerl
endif
" translation entries
syn region papp_gettext start=/__"/ end=/"/ contains=@perlInterpDQ
" embedded perl sections
syn region papp_perl matchgroup=papp_delim start="<[:?]" end="[:]>" keepend contains=papp_reference,papp_cb,@PAppPerl
" preprocessor commands
( run in 0.363 second using v1.01-cache-2.11-cpan-454fe037f31 )