NAME
Perl6::Pod::Parser::AddIds - generate attribute id for elements
SYNOPSIS
#make filter with namespace for generated id
my
$add_ids_ns
= new Perl6::Pod::Parser::AddIds::
ns
=>
"namespace"
;
my
$add_ids_ns_file
= new Perl6::Pod::Parser::AddIds::
ns
=>
"test.pod"
;
#leave empty namespace
my
$add_ids
= new Perl6::Pod::Parser::AddIds::;
my
$out
=
''
;
my
$to_mem
= new Perl6::Pod::To::XML::
out_put
=> \
$out
;
#make pipe for process pod
my
$p
= create_pipe(
'Perl6::Pod::Parser'
,
$add_ids_ns
,
$to_mem
);
$p
->parse( \
$pod_text
);
$out
DESCRIPTION
Perl6::Pod::Parser::AddIds - add id attribute to processed pods elements.
my
$add_ids
= new Perl6::Pod::Parser::AddIds::
ns
=>
"namespace"
;
For Pod:
=begin pod
=head1 test
tst2
=end pod
XML is:
<pod pod:type=
'block'
<head1 pod:type=
'block'
pod:id=
'namespace:test_tst2'
>test
tst2
</head1>
</pod>
Added atribute pod:id :
pod:id=
'namespace:test_tst2'
_make_id($text[, $base_id])
Function will construct an element id string. Id string is composed of join (':', $base_id || $parser->{base_id} , $text)
, where $text
in most cases is the pod heading text.
The xml id string has strict format. Checkout "cleanup_id" function for specification.
_make_uniq_id($text)
Calls $parser->make_id($text)
and checks if such id was already generated. If so, generates new one by adding _i1 (or _i2, i3, ...) to the id string. Return value is new uniq id string.
_cleanup_id($id_string)
This function is used internally to remove/change any illegal characters from the elements id string. (see http://www.w3.org/TR/2000/REC-xml-20001006#NT-Name for the id string specification)
$id_string
=~ s/<!\[CDATA\[(.+?)\]\]>/$1/g;
# keep just inside of CDATA
$id_string
=~ s/<.+?>//g;
# remove tags
$id_string
=~ s/^\s*//;
# ltrim spaces
$id_string
=~ s/\s*$//;
# rtrim spaces
$id_string
=~
tr
{/ }{._};
# replace / with . and spaces with _
$id_string
=~ s/[^\-_a-zA-Z0-9\.: ]//g;
# closed set of characters allowed in id string
In the worst case when the $id_string
after clean up will not conform with the specification, warning will be printed out and random number with leading colon will be used.