diff options
author | Karl Berry <karl@freefriends.org> | 2012-11-20 18:08:54 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2012-11-20 18:08:54 +0000 |
commit | c5add2ea5067382269ae6f19e345fda0b9a7bd21 (patch) | |
tree | 02f512fda46d93079c9dc59c0d76f0e398150f83 /Master/tlpkg/tlperl/lib/Pod/Simple/XHTML.pm | |
parent | 6c35e87bdc5a3f64833dbbc42e7d42e683db9d5b (diff) |
perl 5.16.2, compiled without optimization for Windows (from siep)
git-svn-id: svn://tug.org/texlive/trunk@28315 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/tlpkg/tlperl/lib/Pod/Simple/XHTML.pm')
-rw-r--r-- | Master/tlpkg/tlperl/lib/Pod/Simple/XHTML.pm | 68 |
1 files changed, 51 insertions, 17 deletions
diff --git a/Master/tlpkg/tlperl/lib/Pod/Simple/XHTML.pm b/Master/tlpkg/tlperl/lib/Pod/Simple/XHTML.pm index ef05ddb6ea5..9d31db0badd 100644 --- a/Master/tlpkg/tlperl/lib/Pod/Simple/XHTML.pm +++ b/Master/tlpkg/tlperl/lib/Pod/Simple/XHTML.pm @@ -45,7 +45,7 @@ declare the output character set as UTF-8 before parsing, like so: package Pod::Simple::XHTML; use strict; use vars qw( $VERSION @ISA $HAS_HTML_ENTITIES ); -$VERSION = '3.16'; +$VERSION = '3.20'; use Pod::Simple::Methody (); @ISA = ('Pod::Simple::Methody'); @@ -194,6 +194,16 @@ to the empty string. Whether to add a table-of-contents at the top of each page (called an index for the sake of tradition). +=head2 anchor_items + +Whether to anchor every definition C<=item> directive. This needs to be +enabled if you want to be able to link to specific C<=item> directives, which +are output as C<< <dt> >> elements. Disabled by default. + +=head2 backlink + +Whether to turn every =head1 directive into a link pointing to the top +of the page (specifically, the opening body tag). =cut @@ -215,6 +225,8 @@ __PACKAGE__->_accessorize( 'html_header', 'html_footer', 'index', + 'anchor_items', + 'backlink', 'batch_mode', # whether we're in batch mode 'batch_mode_current_level', # When in batch mode, how deep the current module is: 1 for "LWP", @@ -244,7 +256,7 @@ sub new { $new->{'to_index'} = []; $new->{'output'} = []; $new->{'saved'} = []; - $new->{'ids'} = {}; + $new->{'ids'} = { '_podtop_' => 1 }; # used in <body> $new->{'in_li'} = []; $new->{'__region_targets'} = []; @@ -273,7 +285,7 @@ want to override this if you are adding a custom element type that does more than just display formatted text. Perhaps adding a way to generate HTML tables from an extended version of POD. -So, let's say you want add a custom element called 'foo'. In your +So, let's say you want to add a custom element called 'foo'. In your subclass's C<new> method, after calling C<SUPER::new> you'd call: $new->accept_targets_as_text( 'foo' ); @@ -342,11 +354,7 @@ sub start_item_bullet { } sub start_item_text { - if ($_[0]{'in_dd'}[ $_[0]{'dl_level'} ]) { - $_[0]{'scratch'} = "</dd>\n"; - $_[0]{'in_dd'}[ $_[0]{'dl_level'} ] = 0; - } - $_[0]{'scratch'} .= '<dt>'; + # see end_item_text } sub start_over_bullet { $_[0]{'scratch'} = '<ul>'; push @{$_[0]{'in_li'}}, 0; $_[0]->emit } @@ -402,7 +410,10 @@ sub _end_head { my $id = $_[0]->idify($_[0]{scratch}); my $text = $_[0]{scratch}; - $_[0]{'scratch'} = qq{<h$h id="$id">$text</h$h>}; + $_[0]{'scratch'} = $_[0]->backlink && ($h - $add == 0) + # backlinks enabled && =head1 + ? qq{<a href="#_podtop_"><h$h id="$id">$text</h$h></a>} + : qq{<h$h id="$id">$text</h$h>}; $_[0]->emit; push @{ $_[0]{'to_index'} }, [$h, $id, $text]; } @@ -416,7 +427,21 @@ sub end_item_bullet { $_[0]{'scratch'} .= '</p>'; $_[0]->emit } sub end_item_number { $_[0]{'scratch'} .= '</p>'; $_[0]->emit } sub end_item_text { - $_[0]{'scratch'} .= "</dt>\n<dd>"; + # idify and anchor =item content if wanted + my $dt_id = $_[0]{'anchor_items'} + ? ' id="'. $_[0]->idify($_[0]{'scratch'}) .'"' + : ''; + + # reset scratch + my $text = $_[0]{scratch}; + $_[0]{'scratch'} = ''; + + if ($_[0]{'in_dd'}[ $_[0]{'dl_level'} ]) { + $_[0]{'scratch'} = "</dd>\n"; + $_[0]{'in_dd'}[ $_[0]{'dl_level'} ] = 0; + } + + $_[0]{'scratch'} .= qq{<dt$dt_id>$text</dt>\n<dd>}; $_[0]{'in_dd'}[ $_[0]{'dl_level'} ] = 1; $_[0]->emit; } @@ -451,18 +476,23 @@ sub start_Document { $self->{'scratch'} .= $self->html_header; $self->emit unless $self->html_header eq ""; } else { - my ($doctype, $title, $metatags); + my ($doctype, $title, $metatags, $bodyid); $doctype = $self->html_doctype || ''; $title = $self->force_title || $self->title || $self->default_title || ''; $metatags = $self->html_header_tags || ''; - if ($self->html_css) { - $metatags .= "\n<link rel='stylesheet' href='" . - $self->html_css . "' type='text/css' />"; + if (my $css = $self->html_css) { + $metatags .= $css; + if ($css !~ /<link/) { + # this is required to be compatible with Pod::Simple::BatchHTML + $metatags .= '<link rel="stylesheet" href="' + . $self->encode_entities($css) . '" type="text/css" />'; + } } if ($self->html_javascript) { - $metatags .= "\n<script type='text/javascript' src='" . + $metatags .= qq{\n<script type="text/javascript" src="} . $self->html_javascript . "'></script>"; } + $bodyid = $self->backlink ? ' id="_podtop_"' : ''; $self->{'scratch'} .= <<"HTML"; $doctype <html> @@ -470,7 +500,7 @@ $doctype <title>$title</title> $metatags </head> -<body> +<body$bodyid> HTML $self->emit; } @@ -599,7 +629,7 @@ sub resolve_pod_page_link { my ($self, $to, $section) = @_; return undef unless defined $to || defined $section; if (defined $section) { - $section = '#' . $self->idify($section, 1); + $section = '#' . $self->idify($self->encode_entities($section), 1); return $section unless defined $to; } else { $section = '' @@ -708,6 +738,10 @@ sub batch_mode_page_object_init { return $self; } +sub html_header_after_title { +} + + 1; __END__ |