PerlPoint-XML-XHTML
view release on metacpan or search on metacpan
lib/PerlPoint/Generator/XML/XHTML.pm view on Meta::CPAN
confess "[BUG] Missing object parameter.\n" unless $me;
confess "[BUG] Object parameter is no ", __PACKAGE__, " object.\n" unless ref $me and $me->isa(__PACKAGE__);
# don't forget the base class
$me->SUPER::initBackend;
}
# headline formatter
sub formatHeadline
{
# get and check parameters
((my __PACKAGE__ $me), my ($page, $item))=@_;
confess "[BUG] Missing object parameter.\n" unless $me;
confess "[BUG] Object parameter is no ", __PACKAGE__, " object.\n" unless ref $me and $me->isa(__PACKAGE__);
confess "[BUG] Missing page data parameter.\n" unless $page;
confess "[BUG] Missing item parameter.\n" unless defined $item;
# build the tag name and a path
my $tag="h$item->{cfg}{data}{level}";
my $path=$page->path(type=>'fpath', mode=>'full', delimiter=>'|');
# build the headline, store it with anchors (anchors as MD 5 checksums)
(
$me->{xml}->a({id=>$me->buildAnchorId($item->{cfg}{data}{full})}),
$path ? $me->{xml}->a({id=>$me->buildAnchorId(join('|', $path, $item->{cfg}{data}{full}))}) : (),
$me->{xml}->$tag(@{$item->{parts}}),
)
}
# tag formatter
sub formatTag
{
# get and check parameters
((my __PACKAGE__ $me), my ($page, $item))=@_;
confess "[BUG] Missing object parameter.\n" unless $me;
confess "[BUG] Object parameter is no ", __PACKAGE__, " object.\n" unless ref $me and $me->isa(__PACKAGE__);
confess "[BUG] Missing page data parameter.\n" unless $page;
confess "[BUG] Missing item parameter.\n" unless defined $item;
# declarations
my ($directive, $xmltag, @results)=('');
# handle the various tags
if ($item->{cfg}{data}{name} eq 'A')
{
# anchor: build result string
push(
@results,
$me->{$me->{xmlmode}}->a(
{
# this is the difference to the XML generator handling:
# valid XHTML tag names are required to be very simple strings,
# so we use *checksums*
id => $me->buildAnchorId($item->{cfg}{data}{options}{name}),
},
@{$item->{parts}},
)
);
}
elsif ($item->{cfg}{data}{name} eq 'EMBED')
{
# embedded (X)HTML
if ($item->{cfg}{data}{options}{lang}=~/^X?HTML$/i)
{
# just pass parts through (supplying them via XML::Generator object, not as string)
push(@results, $me->string2XMLObject(@{$item->{parts}}));
}
}
elsif ($item->{cfg}{data}{name} eq 'F')
{
# the FONT tag is deprecated, use inlined CSS instead
my $style;
# faces
$style.="font-family:$item->{cfg}{data}{options}{face};"
if (exists $item->{cfg}{data}{options}{face});
# size
if (exists $item->{cfg}{data}{options}{size})
{
# get original setting
my $size=$item->{cfg}{data}{options}{size};
# translate old fashioned fuzzy setups, if necessary
if ($size=~/^[-+]?\d+$/)
{
{
# for recalculation, keep in mind that size "3" is the standard
# size in HTML's deprecated FONT tag
# (ugly do {} only used to avoid noisy "= instead == in condition"
# warnings in perl 5.8.x)
do {$size='medium'} and last if $size=~/^[-+]0$/ or $size==3;
do {$size='smaller'} and last if $size==-1 or $size==2;
do {$size='small'} and last if $size==-2 or $size==1;
do {$size='x-small'} and last if $size==-3 or $size eq '0';
do {$size='xx-small'} and last if $size<-4;
do {$size='larger'} and last if $size eq '+1' or $size==4;
do {$size='large'} and last if $size eq '+2' or $size==5;
do {$size='x-large'} and last if $size eq '+3' or $size==6;
do {$size='xx-large'} and last if $size=~/^\+[456]$/ or $size>6;
}
}
$style.="font-size:$size;";
}
# color
$style.="color:$item->{cfg}{data}{options}{color};"
if (exists $item->{cfg}{data}{options}{color});
# provide results
push(@results, $me->{$me->{xmlmode}}->span({$style ? (style => $style) : ()}, @{$item->{parts}}));
}
elsif ($item->{cfg}{data}{name} eq 'INDEX')
{
# scopies
my (%index, %anchors);
( run in 0.732 second using v1.01-cache-2.11-cpan-71847e10f99 )