Question

When writing perlpod documentation that will be exported to HTML, can I embed the title of the resulting HTML file in the POD directives?

I want to be able to convert multiple POD text files to HTML with the pod2html command, and don't want to have to give the --title="My Title" parameter on the command-line.

For example, here is a text file with perlpod formatting:

=pod

=head1 This is a heading

This is some text. I'd like to set the title of this document in the resulting HTML file.

=cut

When I convert it to HTML, pod2html gives a warning about there being no title:

$ pod2html test.txt > test.html
/usr/bin/pod2html: no title for test.txt

In the resulting HTML file, the title is set to the filename (test.txt):

<?xml version="1.0" ?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>test.txt</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:root@localhost" />
</head>

<body style="background-color: white">

<p><a name="__index__"></a></p>
<!-- INDEX BEGIN -->

<ul>

        <li><a href="#this_is_a_heading_">This is a heading.</a></li>
</ul>
<!-- INDEX END -->

<hr />
<p>
</p>
<hr />
<h1><a name="this_is_a_heading_">This is a heading.</a></h1>
<p>This is some text. I'd like to set the title of this document.</p>

</body>

</html>

I'd like to find a way to have the title given in the perpod document, perhaps with a directive like this:

=title This is my custom title

In the Perl documentation, I see that the document titles are set nicely. Is this all done without having the document title in the pod document itself?

Was it helpful?

Solution 2

No.

POD exists mainly¹ to write Perl module documentation², and therefore doesn't have many fancy features. Also, the primary output medium for POD is the terminal, where no such thing as a title exists conceptially³. It is, after all, just Plain and Old documentation.
    1. Suprisingly many Perl books are written in POD.
    2. The location of the POD document coincides with the thing discussed in the text.
    3. The ps name / $0 variable comes close, but is useless here.

This is also a technical problem: pod2html uses Pod::Html, which parses the command line, and wraps itself around Pod::Simple::XHTML or something, without doing, or interfering with, the actual parsing. However, it already supplies a header and a footer, which sensibly overrides any default headers that might be emitted.

There are two interesting options how your problem can be solved:

  1. You write a postprocessor that puts the value of the first h1 into the title. This should be <10 lines in a parser with XPath-support. Then you write a little script that ties these together, and can be invoked instead of pod2html.

  2. You take the existing wealth of POD parsers (and source code), and whip up your own HTML from POD generator. If all you are actually doing is a small fork, you could try to offer the modification to the original module.

OTHER TIPS

There is nothing in the Pod documentation that controls the title of the document. This up to the program that converts the Pod documentation to the format you want. Most of the pod2doc programs that you use to generate the documentation will have a module like Pod::Text or Pod::Html. These do most of the grunt work in converting.

pod2html takes a --title parameter. However, what you want is for pod2html to do it without you having to specify it. What you can do is roll your own version of pod2html. Let's look at pod2html script itself, and maybe you can figure out what you can do to get what you want.

Removing all the POD document, I see::

use Pod::Html
pod2html @ARGV

That's the entire program.

It looks like you could make a pod2steve program to do what you want. You want to take the last parameter (which I assume is what you want the title to be), and simply pass it through the pod2html subroutine. Your pod2steve would look something like this:

use strict;
use warnings;

use Pod::Html
my $program_name = $ARGV[$#ARGV];
pod2html --title=$program_name @ARGV

That should work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top