From 03c389c1b844c9c5cc9148f4a1b28d5d62f99c1e Mon Sep 17 00:00:00 2001 From: Scott Baker Date: Mon, 20 Jul 2020 14:37:58 -0700 Subject: [PATCH 01/13] Output HTML5 intead of XHTML for pod2man Adds a --xhtml to use output XHTML instead --- ext/Pod-Html/lib/Pod/Html.pm | 95 ++++++++++++++++++++++++++---------- 1 file changed, 68 insertions(+), 27 deletions(-) diff --git a/ext/Pod-Html/lib/Pod/Html.pm b/ext/Pod-Html/lib/Pod/Html.pm index 71555e723ca9..6a5838a22b02 100644 --- a/ext/Pod-Html/lib/Pod/Html.pm +++ b/ext/Pod-Html/lib/Pod/Html.pm @@ -95,7 +95,7 @@ Displays the usage message. Sets the directory to which all cross references in the resulting html file will be relative. Not passing this causes all links to be -absolute since this is the value that tells Pod::Html the root of the +absolute since this is the value that tells Pod::Html the root of the documentation tree. Do not use this and --htmlroot in the same call to pod2html; they are @@ -140,7 +140,7 @@ is specified. --poderrors --nopoderrors -Include a "POD ERRORS" section in the outfile if there were any POD +Include a "POD ERRORS" section in the outfile if there were any POD errors in the infile. This section is included by default. =item podpath @@ -209,7 +209,7 @@ Uses C<$Config{pod2html}> to setup default options. =head1 AUTHOR -Marc Green, Emarcgreen@cpan.orgE. +Marc Green, Emarcgreen@cpan.orgE. Original version by Tom Christiansen, Etchrist@perl.comE. @@ -236,7 +236,7 @@ sub feed_tree_to_parser { } } -my $Cachedir; +my $Cachedir; my $Dircache; my($Htmlroot, $Htmldir, $Htmlfile, $Htmlfileurl); my($Podfile, @Podpath, $Podroot); @@ -245,6 +245,7 @@ my $Css; my $Recurse; my $Quiet; +my $OutputMode; my $Verbose; my $Doindex; @@ -288,6 +289,7 @@ sub init_globals { $Backlink = 0; # no backlinks added by default $Header = 0; # produce block header/footer $Title = undef; # title to give the pod(s) + $OutputMode = "html" # OutputMode is either HTML or XHTML } sub pod2html { @@ -320,7 +322,7 @@ sub pod2html { unless (get_cache($Dircache, \@Podpath, $Podroot, $Recurse)) { # generate %Pages my $pwd = getcwd(); - chdir($Podroot) || + chdir($Podroot) || die "$0: error changing to directory $Podroot: $!\n"; # find all pod modules/pages in podpath, store in %Pages @@ -432,26 +434,11 @@ sub pod2html { END_OF_BLOCK # create own header/footer because of --header - $parser->html_header(<<"HTMLHEAD"); - - - - -$Title$csslink - - - - - -$block -HTMLHEAD + my $head = get_header($OutputMode, $Title, $csslink, $bodyid, $block); + $parser->html_header($head); - $parser->html_footer(<<"HTMLFOOT"); -$block - - - -HTMLFOOT + my $foot = get_footer($OutputMode, $Title, $csslink, $bodyid, $block); + $parser->html_footer($foot); feed_tree_to_parser($parser, $podtree); @@ -501,7 +488,7 @@ Usage: $0 --help --htmldir= --htmlroot= by default). --outfile - filename for the resulting html file (output sent to stdout by default). - --[no]poderrors - include a POD ERRORS section in the output if there were + --[no]poderrors - include a POD ERRORS section in the output if there were any POD errors in the input (default behavior). --podpath - colon-separated list of directories containing library pods (empty by default). @@ -521,7 +508,7 @@ sub parse_command_line { my ($opt_backlink,$opt_cachedir,$opt_css,$opt_flush,$opt_header, $opt_help,$opt_htmldir,$opt_htmlroot,$opt_index,$opt_infile, $opt_outfile,$opt_poderrors,$opt_podpath,$opt_podroot, - $opt_quiet,$opt_recurse,$opt_title,$opt_verbose); + $opt_quiet,$opt_recurse,$opt_title,$opt_verbose,$opt_xhtml); unshift @ARGV, split ' ', $Config{pod2html} if $Config{pod2html}; my $result = GetOptions( @@ -543,6 +530,7 @@ sub parse_command_line { 'recurse!' => \$opt_recurse, 'title=s' => \$opt_title, 'verbose!' => \$opt_verbose, + 'xhtml' => \$opt_xhtml, ); usage("-", "invalid parameters") if not $result; @@ -567,6 +555,10 @@ sub parse_command_line { $Title = $opt_title if defined $opt_title; $Verbose = $opt_verbose if defined $opt_verbose; + if ($opt_xhtml) { + $OutputMode = "xhtml"; + } + warn "Flushing directory caches\n" if $opt_verbose && defined $opt_flush; $Dircache = "$Cachedir/pod2htmd.tmp"; @@ -770,7 +762,7 @@ sub resolve_pod_page_link { my $modloc = File::Spec->catfile(split(/::/, $to)); if ($#matches == -1) { - warn "Cannot find file \"$modloc.*\" directly under podpath, " . + warn "Cannot find file \"$modloc.*\" directly under podpath, " . "cannot find suitable replacement: link remains unresolved.\n" if $self->verbose; return ''; @@ -842,4 +834,53 @@ sub relativize_url { return $rel_path; } +sub get_header { + my $mode = shift() // "html"; + my ($title, $csslink, $bodyid, $block) = @_; + + my $ret = ""; + + if ($mode eq "xhtml") { + $ret = qq( + + + $title$csslink + + + + +$block); + } elsif ($mode eq 'html') { + $ret = qq( + + + + + + $title$csslink + + + +$block); + } + + return $ret; +} + +sub get_footer { + my $mode = shift() // "html"; + my ($title, $csslink, $bodyid, $block) = @_; + + my $ret = ""; + + # Modes are the same (for now) for footer stuff + if ($mode eq "xhtml") { + $ret = "$block\n\n\n"; + } elsif ($mode eq 'html') { + $ret = "$block\n\n\n"; + } + + return $ret; +} + 1; From 4c7c8075e20fb81a91a15d748ede1996f4918382 Mon Sep 17 00:00:00 2001 From: Scott Baker Date: Mon, 20 Jul 2020 14:47:11 -0700 Subject: [PATCH 02/13] Modernize HTML output with font-stack heirarchy and colors References: https://design.max.gov/ui-typography.html https://www.smashingmagazine.com/2015/11/using-system-ui-fonts-practical-guide/ --- ext/Pod-Html/lib/Pod/Html.pm | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ext/Pod-Html/lib/Pod/Html.pm b/ext/Pod-Html/lib/Pod/Html.pm index 6a5838a22b02..ab7a2138beda 100644 --- a/ext/Pod-Html/lib/Pod/Html.pm +++ b/ext/Pod-Html/lib/Pod/Html.pm @@ -857,6 +857,13 @@ $block); + + $title$csslink From 52dc20198a41c7df279a1477bc07188bc583d52b Mon Sep 17 00:00:00 2001 From: Scott Baker Date: Mon, 20 Jul 2020 14:37:58 -0700 Subject: [PATCH 03/13] Output HTML5 intead of XHTML for pod2man Adds a --xhtml to use output XHTML instead --- ext/Pod-Html/lib/Pod/Html.pm | 95 ++++++++++++++++++++++++++---------- 1 file changed, 68 insertions(+), 27 deletions(-) diff --git a/ext/Pod-Html/lib/Pod/Html.pm b/ext/Pod-Html/lib/Pod/Html.pm index 71555e723ca9..6a5838a22b02 100644 --- a/ext/Pod-Html/lib/Pod/Html.pm +++ b/ext/Pod-Html/lib/Pod/Html.pm @@ -95,7 +95,7 @@ Displays the usage message. Sets the directory to which all cross references in the resulting html file will be relative. Not passing this causes all links to be -absolute since this is the value that tells Pod::Html the root of the +absolute since this is the value that tells Pod::Html the root of the documentation tree. Do not use this and --htmlroot in the same call to pod2html; they are @@ -140,7 +140,7 @@ is specified. --poderrors --nopoderrors -Include a "POD ERRORS" section in the outfile if there were any POD +Include a "POD ERRORS" section in the outfile if there were any POD errors in the infile. This section is included by default. =item podpath @@ -209,7 +209,7 @@ Uses C<$Config{pod2html}> to setup default options. =head1 AUTHOR -Marc Green, Emarcgreen@cpan.orgE. +Marc Green, Emarcgreen@cpan.orgE. Original version by Tom Christiansen, Etchrist@perl.comE. @@ -236,7 +236,7 @@ sub feed_tree_to_parser { } } -my $Cachedir; +my $Cachedir; my $Dircache; my($Htmlroot, $Htmldir, $Htmlfile, $Htmlfileurl); my($Podfile, @Podpath, $Podroot); @@ -245,6 +245,7 @@ my $Css; my $Recurse; my $Quiet; +my $OutputMode; my $Verbose; my $Doindex; @@ -288,6 +289,7 @@ sub init_globals { $Backlink = 0; # no backlinks added by default $Header = 0; # produce block header/footer $Title = undef; # title to give the pod(s) + $OutputMode = "html" # OutputMode is either HTML or XHTML } sub pod2html { @@ -320,7 +322,7 @@ sub pod2html { unless (get_cache($Dircache, \@Podpath, $Podroot, $Recurse)) { # generate %Pages my $pwd = getcwd(); - chdir($Podroot) || + chdir($Podroot) || die "$0: error changing to directory $Podroot: $!\n"; # find all pod modules/pages in podpath, store in %Pages @@ -432,26 +434,11 @@ sub pod2html { END_OF_BLOCK # create own header/footer because of --header - $parser->html_header(<<"HTMLHEAD"); - - - - -$Title$csslink - - - - - -$block -HTMLHEAD + my $head = get_header($OutputMode, $Title, $csslink, $bodyid, $block); + $parser->html_header($head); - $parser->html_footer(<<"HTMLFOOT"); -$block - - - -HTMLFOOT + my $foot = get_footer($OutputMode, $Title, $csslink, $bodyid, $block); + $parser->html_footer($foot); feed_tree_to_parser($parser, $podtree); @@ -501,7 +488,7 @@ Usage: $0 --help --htmldir= --htmlroot= by default). --outfile - filename for the resulting html file (output sent to stdout by default). - --[no]poderrors - include a POD ERRORS section in the output if there were + --[no]poderrors - include a POD ERRORS section in the output if there were any POD errors in the input (default behavior). --podpath - colon-separated list of directories containing library pods (empty by default). @@ -521,7 +508,7 @@ sub parse_command_line { my ($opt_backlink,$opt_cachedir,$opt_css,$opt_flush,$opt_header, $opt_help,$opt_htmldir,$opt_htmlroot,$opt_index,$opt_infile, $opt_outfile,$opt_poderrors,$opt_podpath,$opt_podroot, - $opt_quiet,$opt_recurse,$opt_title,$opt_verbose); + $opt_quiet,$opt_recurse,$opt_title,$opt_verbose,$opt_xhtml); unshift @ARGV, split ' ', $Config{pod2html} if $Config{pod2html}; my $result = GetOptions( @@ -543,6 +530,7 @@ sub parse_command_line { 'recurse!' => \$opt_recurse, 'title=s' => \$opt_title, 'verbose!' => \$opt_verbose, + 'xhtml' => \$opt_xhtml, ); usage("-", "invalid parameters") if not $result; @@ -567,6 +555,10 @@ sub parse_command_line { $Title = $opt_title if defined $opt_title; $Verbose = $opt_verbose if defined $opt_verbose; + if ($opt_xhtml) { + $OutputMode = "xhtml"; + } + warn "Flushing directory caches\n" if $opt_verbose && defined $opt_flush; $Dircache = "$Cachedir/pod2htmd.tmp"; @@ -770,7 +762,7 @@ sub resolve_pod_page_link { my $modloc = File::Spec->catfile(split(/::/, $to)); if ($#matches == -1) { - warn "Cannot find file \"$modloc.*\" directly under podpath, " . + warn "Cannot find file \"$modloc.*\" directly under podpath, " . "cannot find suitable replacement: link remains unresolved.\n" if $self->verbose; return ''; @@ -842,4 +834,53 @@ sub relativize_url { return $rel_path; } +sub get_header { + my $mode = shift() // "html"; + my ($title, $csslink, $bodyid, $block) = @_; + + my $ret = ""; + + if ($mode eq "xhtml") { + $ret = qq( + + + $title$csslink + + + + +$block); + } elsif ($mode eq 'html') { + $ret = qq( + + + + + + $title$csslink + + + +$block); + } + + return $ret; +} + +sub get_footer { + my $mode = shift() // "html"; + my ($title, $csslink, $bodyid, $block) = @_; + + my $ret = ""; + + # Modes are the same (for now) for footer stuff + if ($mode eq "xhtml") { + $ret = "$block\n\n\n"; + } elsif ($mode eq 'html') { + $ret = "$block\n\n\n"; + } + + return $ret; +} + 1; From 4e2207f66df6b0be6fe1b3a387a69ed0a42a80e5 Mon Sep 17 00:00:00 2001 From: Scott Baker Date: Mon, 20 Jul 2020 14:47:11 -0700 Subject: [PATCH 04/13] Modernize HTML output with font-stack heirarchy and colors References: https://design.max.gov/ui-typography.html https://www.smashingmagazine.com/2015/11/using-system-ui-fonts-practical-guide/ --- ext/Pod-Html/lib/Pod/Html.pm | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ext/Pod-Html/lib/Pod/Html.pm b/ext/Pod-Html/lib/Pod/Html.pm index 6a5838a22b02..ab7a2138beda 100644 --- a/ext/Pod-Html/lib/Pod/Html.pm +++ b/ext/Pod-Html/lib/Pod/Html.pm @@ -857,6 +857,13 @@ $block); + + $title$csslink From 0506c19c67a38ed9cae066c75af3a348b9d39a53 Mon Sep 17 00:00:00 2001 From: Scott Baker Date: Mon, 20 Jul 2020 15:06:56 -0700 Subject: [PATCH 05/13] Normalize all the indentations, and add a vim modeline to keep it clean --- ext/Pod-Html/lib/Pod/Html.pm | 114 ++++++++++++++++++----------------- 1 file changed, 58 insertions(+), 56 deletions(-) diff --git a/ext/Pod-Html/lib/Pod/Html.pm b/ext/Pod-Html/lib/Pod/Html.pm index ab7a2138beda..7988f2a24069 100644 --- a/ext/Pod-Html/lib/Pod/Html.pm +++ b/ext/Pod-Html/lib/Pod/Html.pm @@ -228,11 +228,11 @@ This program is distributed under the Artistic License. sub feed_tree_to_parser { my($parser, $tree) = @_; if(ref($tree) eq "") { - $parser->_handle_text($tree); + $parser->_handle_text($tree); } elsif(!($tree->[0] eq "X" && $parser->nix_X_codes)) { - $parser->_handle_element_start($tree->[0], $tree->[1]); - feed_tree_to_parser($parser, $_) foreach @{$tree}[2..$#$tree]; - $parser->_handle_element_end($tree->[0]); + $parser->_handle_element_start($tree->[0], $tree->[1]); + feed_tree_to_parser($parser, $_) foreach @{$tree}[2..$#$tree]; + $parser->_handle_element_end($tree->[0]); } } @@ -289,7 +289,7 @@ sub init_globals { $Backlink = 0; # no backlinks added by default $Header = 0; # produce block header/footer $Title = undef; # title to give the pod(s) - $OutputMode = "html" # OutputMode is either HTML or XHTML + $OutputMode = "html" # OutputMode is either HTML or XHTML } sub pod2html { @@ -377,18 +377,18 @@ sub pod2html { my $podtree = $parser->parse_file($input)->root; unless(defined $Title) { - if($podtree->[0] eq "Document" && ref($podtree->[2]) eq "ARRAY" && - $podtree->[2]->[0] eq "head1" && @{$podtree->[2]} == 3 && - ref($podtree->[2]->[2]) eq "" && $podtree->[2]->[2] eq "NAME" && - ref($podtree->[3]) eq "ARRAY" && $podtree->[3]->[0] eq "Para" && - @{$podtree->[3]} >= 3 && - !(grep { ref($_) ne "" } - @{$podtree->[3]}[2..$#{$podtree->[3]}]) && - (@$podtree == 4 || - (ref($podtree->[4]) eq "ARRAY" && - $podtree->[4]->[0] eq "head1"))) { - $Title = join("", @{$podtree->[3]}[2..$#{$podtree->[3]}]); - } + if($podtree->[0] eq "Document" && ref($podtree->[2]) eq "ARRAY" && + $podtree->[2]->[0] eq "head1" && @{$podtree->[2]} == 3 && + ref($podtree->[2]->[2]) eq "" && $podtree->[2]->[2] eq "NAME" && + ref($podtree->[3]) eq "ARRAY" && $podtree->[3]->[0] eq "Para" && + @{$podtree->[3]} >= 3 && + !(grep { ref($_) ne "" } + @{$podtree->[3]}[2..$#{$podtree->[3]}]) && + (@$podtree == 4 || + (ref($podtree->[4]) eq "ARRAY" && + $podtree->[4]->[0] eq "head1"))) { + $Title = join("", @{$podtree->[3]}[2..$#{$podtree->[3]}]); + } } $Title //= ""; @@ -434,10 +434,10 @@ sub pod2html { END_OF_BLOCK # create own header/footer because of --header - my $head = get_header($OutputMode, $Title, $csslink, $bodyid, $block); + my $head = get_header($OutputMode, $Title, $csslink, $bodyid, $block); $parser->html_header($head); - my $foot = get_footer($OutputMode, $Title, $csslink, $bodyid, $block); + my $foot = get_footer($OutputMode, $Title, $csslink, $bodyid, $block); $parser->html_footer($foot); feed_tree_to_parser($parser, $podtree); @@ -555,9 +555,9 @@ sub parse_command_line { $Title = $opt_title if defined $opt_title; $Verbose = $opt_verbose if defined $opt_verbose; - if ($opt_xhtml) { - $OutputMode = "xhtml"; - } + if ($opt_xhtml) { + $OutputMode = "xhtml"; + } warn "Flushing directory caches\n" if $opt_verbose && defined $opt_flush; @@ -835,59 +835,61 @@ sub relativize_url { } sub get_header { - my $mode = shift() // "html"; - my ($title, $csslink, $bodyid, $block) = @_; + my $mode = shift() // "html"; + my ($title, $csslink, $bodyid, $block) = @_; - my $ret = ""; + my $ret = ""; - if ($mode eq "xhtml") { - $ret = qq( + if ($mode eq "xhtml") { + $ret = qq( - - $title$csslink - - + + $title$csslink + + $block); - } elsif ($mode eq 'html') { - $ret = qq( + } elsif ($mode eq 'html') { + $ret = qq( - - - + + + - + - $title$csslink - + $title$csslink + $block); - } + } - return $ret; + return $ret; } sub get_footer { - my $mode = shift() // "html"; - my ($title, $csslink, $bodyid, $block) = @_; + my $mode = shift() // "html"; + my ($title, $csslink, $bodyid, $block) = @_; - my $ret = ""; + my $ret = ""; - # Modes are the same (for now) for footer stuff - if ($mode eq "xhtml") { - $ret = "$block\n\n\n"; - } elsif ($mode eq 'html') { - $ret = "$block\n\n\n"; - } + # Modes are the same (for now) for footer stuff + if ($mode eq "xhtml") { + $ret = "$block\n\n\n"; + } elsif ($mode eq 'html') { + $ret = "$block\n\n\n"; + } - return $ret; + return $ret; } 1; + +# vim: tabstop=4 shiftwidth=4 expandtab autoindent softtabstop=4 From c17e42341b9c57c71b8a961eefd3d3457d030870 Mon Sep 17 00:00:00 2001 From: Scott Baker Date: Mon, 3 Aug 2020 10:18:05 -0700 Subject: [PATCH 06/13] Further basic CSS updates --- ext/Pod-Html/lib/Pod/Html.pm | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/ext/Pod-Html/lib/Pod/Html.pm b/ext/Pod-Html/lib/Pod/Html.pm index 7988f2a24069..3d9bf4333c42 100644 --- a/ext/Pod-Html/lib/Pod/Html.pm +++ b/ext/Pod-Html/lib/Pod/Html.pm @@ -857,12 +857,22 @@ $block); - + $title$csslink From 1174130bc5b38776d2aa15a5ae50c523b7ac5890 Mon Sep 17 00:00:00 2001 From: Scott Baker Date: Mon, 5 Oct 2020 08:40:05 -0700 Subject: [PATCH 07/13] One big param string for consistency --- ext/Pod-Html/lib/Pod/Html.pm | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ext/Pod-Html/lib/Pod/Html.pm b/ext/Pod-Html/lib/Pod/Html.pm index 3d9bf4333c42..b5576ce78fa2 100644 --- a/ext/Pod-Html/lib/Pod/Html.pm +++ b/ext/Pod-Html/lib/Pod/Html.pm @@ -835,8 +835,7 @@ sub relativize_url { } sub get_header { - my $mode = shift() // "html"; - my ($title, $csslink, $bodyid, $block) = @_; + my ($mode, $title, $csslink, $bodyid, $block) = @_; my $ret = ""; From 6e62191d346f8932af6f8127aaac4970c7bdcfed Mon Sep 17 00:00:00 2001 From: Scott Baker Date: Mon, 5 Oct 2020 08:46:56 -0700 Subject: [PATCH 08/13] For simplicity we're going to merge these two conditionals --- ext/Pod-Html/lib/Pod/Html.pm | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ext/Pod-Html/lib/Pod/Html.pm b/ext/Pod-Html/lib/Pod/Html.pm index b5576ce78fa2..f6f14ababb34 100644 --- a/ext/Pod-Html/lib/Pod/Html.pm +++ b/ext/Pod-Html/lib/Pod/Html.pm @@ -890,9 +890,7 @@ sub get_footer { my $ret = ""; # Modes are the same (for now) for footer stuff - if ($mode eq "xhtml") { - $ret = "$block\n\n\n"; - } elsif ($mode eq 'html') { + if ($mode eq "xhtml" || $mode eq 'html') { $ret = "$block\n\n\n"; } From fa5d7a52bcb6e3fea23ba0f3d9b9746cfc823e79 Mon Sep 17 00:00:00 2001 From: Scott Baker Date: Mon, 20 Jul 2020 15:06:56 -0700 Subject: [PATCH 09/13] Normalize all the indentations, and add a vim modeline to keep it clean --- ext/Pod-Html/lib/Pod/Html.pm | 137 ++++++++++++++++++++++++----------- 1 file changed, 93 insertions(+), 44 deletions(-) diff --git a/ext/Pod-Html/lib/Pod/Html.pm b/ext/Pod-Html/lib/Pod/Html.pm index b825acadca9a..6e84aa6725bc 100644 --- a/ext/Pod-Html/lib/Pod/Html.pm +++ b/ext/Pod-Html/lib/Pod/Html.pm @@ -96,7 +96,7 @@ Displays the usage message. Sets the directory to which all cross references in the resulting html file will be relative. Not passing this causes all links to be -absolute since this is the value that tells Pod::Html the root of the +absolute since this is the value that tells Pod::Html the root of the documentation tree. Do not use this and --htmlroot in the same call to pod2html; they are @@ -141,7 +141,7 @@ is specified. --poderrors --nopoderrors -Include a "POD ERRORS" section in the outfile if there were any POD +Include a "POD ERRORS" section in the outfile if there were any POD errors in the infile. This section is included by default. =item podpath @@ -210,7 +210,7 @@ Uses C<$Config{pod2html}> to setup default options. =head1 AUTHOR -Marc Green, Emarcgreen@cpan.orgE. +Marc Green, Emarcgreen@cpan.orgE. Original version by Tom Christiansen, Etchrist@perl.comE. @@ -229,15 +229,15 @@ This program is distributed under the Artistic License. sub feed_tree_to_parser { my($parser, $tree) = @_; if(ref($tree) eq "") { - $parser->_handle_text($tree); + $parser->_handle_text($tree); } elsif(!($tree->[0] eq "X" && $parser->nix_X_codes)) { - $parser->_handle_element_start($tree->[0], $tree->[1]); - feed_tree_to_parser($parser, $_) foreach @{$tree}[2..$#$tree]; - $parser->_handle_element_end($tree->[0]); + $parser->_handle_element_start($tree->[0], $tree->[1]); + feed_tree_to_parser($parser, $_) foreach @{$tree}[2..$#$tree]; + $parser->_handle_element_end($tree->[0]); } } -my $Cachedir; +my $Cachedir; my $Dircache; my($Htmlroot, $Htmldir, $Htmlfile, $Htmlfileurl); my($Podfile, @Podpath, $Podroot); @@ -251,7 +251,7 @@ my $Doindex; my $Backlink; -my($Title, $Header); +my($Title, $Header, $OutputMode); my %Pages = (); # associative array used to find the location # of pages referenced by L<> links. @@ -289,6 +289,7 @@ sub init_globals { $Backlink = 0; # no backlinks added by default $Header = 0; # produce block header/footer $Title = undef; # title to give the pod(s) + $OutputMode = "html" # OutputMode is either HTML or XHTML } sub pod2html { @@ -321,7 +322,7 @@ sub pod2html { unless (get_cache($Dircache, \@Podpath, $Podroot, $Recurse)) { # generate %Pages my $pwd = getcwd(); - chdir($Podroot) || + chdir($Podroot) || die "$0: error changing to directory $Podroot: $!\n"; # find all pod modules/pages in podpath, store in %Pages @@ -379,18 +380,18 @@ sub pod2html { my $podtree = $parser->parse_file($input)->root; unless(defined $Title) { - if($podtree->[0] eq "Document" && ref($podtree->[2]) eq "ARRAY" && - $podtree->[2]->[0] eq "head1" && @{$podtree->[2]} == 3 && - ref($podtree->[2]->[2]) eq "" && $podtree->[2]->[2] eq "NAME" && - ref($podtree->[3]) eq "ARRAY" && $podtree->[3]->[0] eq "Para" && - @{$podtree->[3]} >= 3 && - !(grep { ref($_) ne "" } - @{$podtree->[3]}[2..$#{$podtree->[3]}]) && - (@$podtree == 4 || - (ref($podtree->[4]) eq "ARRAY" && - $podtree->[4]->[0] eq "head1"))) { - $Title = join("", @{$podtree->[3]}[2..$#{$podtree->[3]}]); - } + if($podtree->[0] eq "Document" && ref($podtree->[2]) eq "ARRAY" && + $podtree->[2]->[0] eq "head1" && @{$podtree->[2]} == 3 && + ref($podtree->[2]->[2]) eq "" && $podtree->[2]->[2] eq "NAME" && + ref($podtree->[3]) eq "ARRAY" && $podtree->[3]->[0] eq "Para" && + @{$podtree->[3]} >= 3 && + !(grep { ref($_) ne "" } + @{$podtree->[3]}[2..$#{$podtree->[3]}]) && + (@$podtree == 4 || + (ref($podtree->[4]) eq "ARRAY" && + $podtree->[4]->[0] eq "head1"))) { + $Title = join("", @{$podtree->[3]}[2..$#{$podtree->[3]}]); + } } $Title //= ""; @@ -436,26 +437,11 @@ sub pod2html { END_OF_BLOCK # create own header/footer because of --header - $parser->html_header(<<"HTMLHEAD"); - - - - -$Title$csslink - - - - - -$block -HTMLHEAD + my $head = get_header($OutputMode, $Title, $csslink, $bodyid, $block); + $parser->html_header($head); - $parser->html_footer(<<"HTMLFOOT"); -$block - - - -HTMLFOOT + my $foot = get_footer($OutputMode, $Title, $csslink, $bodyid, $block); + $parser->html_footer($foot); feed_tree_to_parser($parser, $podtree); @@ -505,7 +491,7 @@ Usage: $0 --help --htmldir= --htmlroot= by default). --outfile - filename for the resulting html file (output sent to stdout by default). - --[no]poderrors - include a POD ERRORS section in the output if there were + --[no]poderrors - include a POD ERRORS section in the output if there were any POD errors in the input (default behavior). --podpath - colon-separated list of directories containing library pods (empty by default). @@ -525,7 +511,7 @@ sub parse_command_line { my ($opt_backlink,$opt_cachedir,$opt_css,$opt_flush,$opt_header, $opt_help,$opt_htmldir,$opt_htmlroot,$opt_index,$opt_infile, $opt_outfile,$opt_poderrors,$opt_podpath,$opt_podroot, - $opt_quiet,$opt_recurse,$opt_title,$opt_verbose); + $opt_quiet,$opt_recurse,$opt_title,$opt_verbose,$opt_xhtml); unshift @ARGV, split ' ', $Config{pod2html} if $Config{pod2html}; my $result = GetOptions( @@ -547,6 +533,7 @@ sub parse_command_line { 'recurse!' => \$opt_recurse, 'title=s' => \$opt_title, 'verbose!' => \$opt_verbose, + 'xhtml' => \$opt_xhtml, ); usage("-", "invalid parameters") if not $result; @@ -571,6 +558,10 @@ sub parse_command_line { $Title = $opt_title if defined $opt_title; $Verbose = $opt_verbose if defined $opt_verbose; + if ($opt_xhtml) { + $OutputMode = "xhtml"; + } + warn "Flushing directory caches\n" if $opt_verbose && defined $opt_flush; $Dircache = "$Cachedir/pod2htmd.tmp"; @@ -774,7 +765,7 @@ sub resolve_pod_page_link { my $modloc = File::Spec->catfile(split(/::/, $to)); if ($#matches == -1) { - warn "Cannot find file \"$modloc.*\" directly under podpath, " . + warn "Cannot find file \"$modloc.*\" directly under podpath, " . "cannot find suitable replacement: link remains unresolved.\n" if $self->verbose; return ''; @@ -866,4 +857,62 @@ sub trim_leading_whitespace { return; } +sub get_header { + my $mode = shift() // "html"; + my ($title, $csslink, $bodyid, $block) = @_; + + my $ret = ""; + + if ($mode eq "xhtml") { + $ret = qq( + + + $title$csslink + + + + +$block); + } elsif ($mode eq 'html') { + $ret = qq( + + + + + + + + $title$csslink + + + +$block); + } + + return $ret; +} + +sub get_footer { + my $mode = shift() // "html"; + my ($title, $csslink, $bodyid, $block) = @_; + + my $ret = ""; + + # Modes are the same (for now) for footer stuff + if ($mode eq "xhtml") { + $ret = "$block\n\n\n"; + } elsif ($mode eq 'html') { + $ret = "$block\n\n\n"; + } + + return $ret; +} + 1; + +# vim: tabstop=4 shiftwidth=4 expandtab autoindent softtabstop=4 From ce3829eb5af5a0836a12c08b0b8b02720f00be5c Mon Sep 17 00:00:00 2001 From: Scott Baker Date: Mon, 3 Aug 2020 10:18:05 -0700 Subject: [PATCH 10/13] Further basic CSS updates --- ext/Pod-Html/lib/Pod/Html.pm | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/ext/Pod-Html/lib/Pod/Html.pm b/ext/Pod-Html/lib/Pod/Html.pm index 6e84aa6725bc..fe2651317b2a 100644 --- a/ext/Pod-Html/lib/Pod/Html.pm +++ b/ext/Pod-Html/lib/Pod/Html.pm @@ -880,12 +880,22 @@ $block); - + $title$csslink From f50b90826f09f7e3d71b7ff155a5fefc8c3ce83d Mon Sep 17 00:00:00 2001 From: Scott Baker Date: Mon, 5 Oct 2020 08:40:05 -0700 Subject: [PATCH 11/13] One big param string for consistency --- ext/Pod-Html/lib/Pod/Html.pm | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ext/Pod-Html/lib/Pod/Html.pm b/ext/Pod-Html/lib/Pod/Html.pm index fe2651317b2a..c4ecc92171a1 100644 --- a/ext/Pod-Html/lib/Pod/Html.pm +++ b/ext/Pod-Html/lib/Pod/Html.pm @@ -858,8 +858,7 @@ sub trim_leading_whitespace { } sub get_header { - my $mode = shift() // "html"; - my ($title, $csslink, $bodyid, $block) = @_; + my ($mode, $title, $csslink, $bodyid, $block) = @_; my $ret = ""; From 568921daf1faa2a616e08a80d3d99173ea69f71d Mon Sep 17 00:00:00 2001 From: Scott Baker Date: Mon, 5 Oct 2020 08:46:56 -0700 Subject: [PATCH 12/13] For simplicity we're going to merge these two conditionals --- ext/Pod-Html/lib/Pod/Html.pm | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ext/Pod-Html/lib/Pod/Html.pm b/ext/Pod-Html/lib/Pod/Html.pm index c4ecc92171a1..14fdec888634 100644 --- a/ext/Pod-Html/lib/Pod/Html.pm +++ b/ext/Pod-Html/lib/Pod/Html.pm @@ -913,9 +913,7 @@ sub get_footer { my $ret = ""; # Modes are the same (for now) for footer stuff - if ($mode eq "xhtml") { - $ret = "$block\n\n\n"; - } elsif ($mode eq 'html') { + if ($mode eq "xhtml" || $mode eq 'html') { $ret = "$block\n\n\n"; } From e7e9b97fe983e864785d13dbfecf8fd5990403aa Mon Sep 17 00:00:00 2001 From: Scott Baker Date: Wed, 4 Nov 2020 10:49:33 -0800 Subject: [PATCH 13/13] Don't redeclare a variable --- ext/Pod-Html/lib/Pod/Html.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/Pod-Html/lib/Pod/Html.pm b/ext/Pod-Html/lib/Pod/Html.pm index 1dfb7bb53733..5213ed6af7de 100644 --- a/ext/Pod-Html/lib/Pod/Html.pm +++ b/ext/Pod-Html/lib/Pod/Html.pm @@ -252,7 +252,7 @@ my $Doindex; my $Backlink; -my($Title, $Header, $OutputMode); +my($Title, $Header); my %Pages = (); # associative array used to find the location # of pages referenced by L<> links.