Convert pod data to docbook sgml
use Pod::2::DocBook; my $parser = Pod::2::DocBook->new( title => 'My Article', doctype => 'article', base_id => 'article42' fix_double_quotes => 1, spaces => 3, id_version => 2, ); $parser->parse_from_file ('my_article.pod', 'my_article.sgml');
Pod::2::DocBook is a module for translating Pod-formatted documents to DocBook 4.2 \s-1SGML\s0 (see <http://www.docbook.org/>). It is primarily a back end for pod2docbook, but, as a Pod::Parser subclass, it can be used on its own. The only public extensions to the Pod::Parser interface are options available to \*(C`new()\*(C':
This option sets the output document's doctype. The currently supported types are article, chapter, refentry and section. Special processing is performed when the doctype is set to refentry (see \*(L"Document Types\*(R"). You must set this option in order to get valid DocBook output.
If this option is set to a true value, pairs of double quote characters ('"') in ordinary paragraphs will be replaced with <quote> and </quote>. See \*(L"Ordinary Paragraphs\*(R" for details.
If this option is set to a true value, Pod::2::DocBook will emit a \s-1DOCTYPE\s0 as the first line of output.
Pod::2::DocBook produces pretty-printed output. This option sets the number of spaces per level of indentation in the output.
This option sets the output document's title.
The rest of this document only describes issues specific to Pod::2::DocBook; for details on invoking the parser, specifically the \*(C`new()\*(C', \*(C`parse_from_file()\*(C' and \*(C`parse_from_filehandle()\*(C' methods, see Pod::Parser.
use base 'Pod::Parser';
Initialize parser.
Output docbook header stuff.
Output docbook footer. Will print also errors if any in a comment block. Process \s-1POD\s0 commands. Process text block. Process verbatim text block. Process formatting commands.
Returns parser error message(s) if any occured.
default id format -
Function will construct an element id string. Id string is composed of \*(C`join (':', $parser->{base_id}, $text)\*(C', where $text in most cases is the pod heading text.
version 2 id format -
having ':' in id was not a best choice. (Xerces complains - Attribute value \*(L"lib.Moose.Manual.pod:NAME\*(R" of type \s-1ID\s0 must be an NCName when namespaces are enabled.) To not break backwards compatibity switch with <id_version = 2>> in constructor for using '-' instead.
The xml id string has strict format. Checkout \*(L"cleanup_id\*(R" function for specification.
Calls \*(C`$parser->make_id($text)\*(C' 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.
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.
Pod is a deceptively simple format; it is easy to learn and very straightforward to use, but it is suprisingly expressive. Nevertheless, it is not nearly as expressive or complex as DocBook. In most cases, given some Pod, the analogous DocBook markup is obvious, but not always. This section describes how Pod::2::DocBook treats Pod input so that Pod authors may make informed choices. In every case, Pod::2::DocBook strives to make easy things easy and hard things possible.
The primary motivation behind Pod::2::DocBook is to facilitate single-source publishing. That is, you should be able to generate man pages, web pages, \s-1PDF\s0 and PostScript documents, or any other format your \s-1SGML\s0 and/or Pod tools can produce, from the same Pod source, without the need for hand-editing any intermediate files. This may not always be possible, or you may simply choose to render Pod to DocBook and use that as your single source. To satisfy the first requirement, Pod::2::DocBook always processes the entire Pod source and tries very hard to produce valid DocBook markup, even in the presence of malformed Pod (see \*(L"\s-1DIAGNOSTICS\s0\*(R"). To satisfy the second requirement (and to be a little nifty), Pod::2::DocBook pretty-prints its output. If you're curious about what specific output to expect, read on.
DocBook's structure is very modular; many of its document types can be embedded directly into other documents. Accordingly, Pod::2::DocBook will generate four different document types: article, chapter, refentry, and section. This makes it easy, for instance, to write all the chapters of a book in separate Pod documents, translate them into DocBook markup and later glue them together before processing the entire book. You could do the same with each section in an article, or you could write the entire article in a single Pod document. Other document types, such as book and set, do not map easily from Pod, because they require structure for which there is no Pod equivalent. But given sections and chapters, making larger documents becomes much simpler.
The refentry document type is a little different from the others. Sections, articles, and chapters are essentially composed of nested sections. But a refentry has specialized elements for the \s-1NAME\s0 and \s-1SYNOPSIS\s0 sections. To accommodate this, Pod::2::DocBook performs extra processing on the Pod source when the doctype is set to refentry. You probably don't have to do anything to your document to assist the processing; typical man page conventions cover the requirements. Just make sure that the \s-1NAME\s0 and \s-1SYNOPSIS\s0 headers are both =head1s, that \*(L"\s-1NAME\s0\*(R" and \*(L"\s-1SYNOPSIS\s0\*(R" are both uppercase, and that =head1 \s-1NAME\s0 is the first line of Pod source.
Ordinary paragraphs in a Pod document translate naturally to DocBook paragraphs. Specifically, after any formatting codes are processed, the characters \*(C`<\*(C', \*(C`>\*(C' and \*(C`&\*(C' are translated to their respective \s-1SGML\s0 character entities, and the paragraph is wrapped in <para> and </para>.
For example, given this Pod paragraph:
Here is some text with I<italics> & an ampersand.
Pod::2::DocBook would produce DocBook markup similar to this:
<para> Here is some text with <emphasis role="italic">italics</emphasis> & an ampersand. </para>
Depending on your final output format, you may sometimes want double quotes in ordinary paragraphs to show up ultimately as \*(L"smart quotes\*(R" (little 66s and 99s). Pod::2::DocBook offers a convenient mechanism for handling double quotes in ordinary paragraphs and letting your \s-1SGML\s0 toolchain manage their presentation: the fix_double_quotes option to \*(C`new()\*(C'. If this option is set to a true value, Pod::2::DocBook will replace pairs of double quotes in ordinary paragraphs (and only in ordinary paragraphs) with <quote> and </quote>.
For example, given this Pod paragraph:
Here is some text with I<italics> & an "ampersand".
Pod::2::DocBook, with fix_double_quotes set, would produce DocBook markup similar to this:
<para> Here is some text with <emphasis role="italic">italics</emphasis> & an <quote>ampersand</quote>. </para>
If you have a paragraph with an odd number of double quotes, the last one will be left untouched, which may or may not be what you want. If you have such a document, replace the unpaired double quote character with E<quot>, and Pod::2::DocBook should be able to give you the output you expect. Also, if you have any =begin docbook ... =end docbook regions (see \*(L"Embedded DocBook Markup\*(R") in your Pod, you are responsible for managing your own quotes in those regions.
Verbatim paragraphs translate even more naturally; perlpodspec mandates that absolutely no processing should be performed on them. So Pod::2::DocBook simply marks them as \s-1CDATA\s0 and wraps them in <screen> and </screen>. They are not indented the way ordinary paragraphs are, because they treat whitespace as significant.
For example, given this verbatim paragraph (imagine there's leading whitespace in the source):
my $i = 10; while (<> && $i--) { print "$i: $_"; }
Pod::2::DocBook would produce DocBook markup similar to this:
<screen><![CDATA[my $i = 10; while (<> && $i--) { print "$i: $_"; }]] ></screen>
Multiple contiguous verbatim paragraphs are treated as a single screen element, with blank lines separating the paragraphs, as dictated by perlpodspec.
All of the Pod heading commands produce DocBook section elements, with the heading text as titles. Pod::2::DocBook (perlpod) only allows for 4 heading levels, but DocBook allows arbitrary nesting; see \*(L"Embedded DocBook Markup\*(R" if you need more than 4 levels. Pod::2::DocBook only looks at relative heading levels to determine nesting. For example, this bit of Pod: =head1 1
Contents of section 1
=head2 1.1
Contents of section 1.1 and this bit of Pod: =head1 1
Contents of section 1
=head3 1.1
Contents of section 1.1 both produce the same DocBook markup, which will look something like this: <section id="article-My-Article-1"><title>1</title> <para> Contents of section 1 </para> <section id="article-My-Article-1-1"><title>1.1</title> <para> Contents of section 1.1 </para> </section> </section> Note that Pod::2::DocBook automatically generates section identifiers from your doctype, document title and section title. It does the same when you make internal links (see \*(L"Formatting Codes\*(R", ensuring that if you supply the same link text as you did for the section title, the resulting identifiers will be the same. \*(C`=over\*(C' ... \*(C`=back\*(C' regions are somewhat complex, in that they can lead to a variety of DocBook constructs. In every case, indentlevel is ignored by Pod::2::DocBook, since that's best left to your stylesheets. An \*(C`=over\*(C' ... \*(C`=back\*(C' region with no \*(C`=item\*(C's represents indented text and maps directly to a DocBook blockquote element. Given this source: =over 4
This text should be indented.
=back Pod::2::DocBook will produce DocBook markup similar to this: <blockquote> <para> This text should be indented. </para> </blockquote> Inside an \*(C`=over\*(C' ... \*(C`=back\*(C' region, \*(C`=item\*(C' commands generate lists. The text that follows the first \*(C`=item\*(C' determines the type of list that will be output:
\*(L"*\*(R" (an asterisk) produces <itemizedlist>
\*(L"1\*(R" or \*(L"1.\*(R" produces <orderedlist numeration=\*(L"arabic\*(R">
\*(L"a\*(R" or \*(L"a.\*(R" produces <orderedlist numeration=\*(L"loweralpha\*(R">
\*(L"A\*(R" or \*(L"A.\*(R" produces <orderedlist numeration=\*(L"upperalpha\*(R">
\*(L"i\*(R" or \*(L"i.\*(R" produces <orderedlist numeration=\*(L"lowerroman\*(R">
\*(L"I\*(R" or \*(L"I.\*(R" produces <orderedlist numeration=\*(L"upperroman\*(R">
anything else produces <variablelist>
Since the output from each of these is relatively verbose, the best way to see examples is to actually render some Pod into DocBook.
Pod::Parser recognizes these commands, and, therefore, so does Pod::2::DocBook, but they don't produce any output. Pod::2::DocBook supports two formats: docbook, explained in \*(L"Embedded DocBook Markup\*(R", and table, explained in \*(L"Simple Tables\*(R". This command is currently not supported. If Pod::2::DocBook encounters a document that contains \*(C`=encoding\*(C', it will ignore the command and report an error (\*(L"unknown command `%s' at line %d in file %s\*(R").
Embedded DocBook Markup
There are a wide range of DocBook structures for which there is no Pod equivalent. For these, you will have to provide your own markup using =begin docbook ... =end docbook or =for docbook .... Pod::2::DocBook will directly output whatever text you provide, unprocessed, so it's up to you to ensure that it's valid DocBook.
Images, footnotes and many inline elements are obvious candidates for embedded markup. Another possible use is nesting sections more than four-deep. For example, given this source:
=head1 1
This is Section 1
=head2 1.1
This is Section 1.1
=head3 1.1.1
This is Section 1.1.1
=head4 1.1.1.1
This is Section 1.1.1.1
=begin docbook
<section> <title>1.1.1.1.1</title> <para>This is Section 1.1.1.1.1</para> </section>
=end docbook
Pod::2::DocBook will generate DocBook markup similar to this:
<section id="article-My-Article-1"><title>1</title> <para> This is Section 1 </para> <section id="article-My-Article-1-1"><title>1.1</title> <para> This is Section 1.1 </para> <section id="article-My-Article-1-1-1"><title>1.1.1</title> <para> This is Section 1.1.1 </para> <section id="article-My-Article-1-1-1-1"><title>1.1.1.1</title> <para> This is Section 1.1.1.1 </para> <section> <title>1.1.1.1.1</title> <para>This is Section 1.1.1.1.1</para> </section> </section> </section> </section> </section>
Simple Tables
Pod::2::DocBook also provides a mechanism for generating basic tables with =begin table and =end docbook. If you have simple tabular data or a \s-1CSV\s0 file exported from some application, Pod::2::DocBook makes it easy to generate a table from your data. The syntax is intended to be simple, so DocBook's entire table feature set is not represented, but even if you do need more complex table markup than Pod::2::DocBook produces, you can rapidly produce some markup which you can hand-edit and then embed directly in your Pod with =begin docbook ... =end docbook. Each table definition spans multiple lines, so there is no equivalent =for table command.
The first line of a table definition gives the table's title. The second line gives a list of comma-separated column specifications (really just column alignments), each of which can be left, center or right. The third line is a list of comma-separated column headings, and every subsequent line consists of comma-separated row data. If any of your data actually contain commas, you can enclose them in double quotes; if they also contain double quotes, you must escape the inner quotes with backslashes (typical \s-1CSV\s0 stuff).
Here's an example:
=begin table
Sample Table left,center,right Powers of Ten,Planets,Dollars 10,Earth,$1 100,Mercury,$5 1000,Mars,$10 10000,Venus,$20 100000,"Jupiter, Saturn",$50
=end table
And here's what Pod::2::DocBook would do with it:
<table> <title>Sample Table</title> <tgroup cols="3"> <colspec align="left"> <colspec align="center"> <colspec align="right"> <thead> <row> <entry>Powers of Ten</entry> <entry>Planets</entry> <entry>Dollars</entry> </row> </thead> <tbody> <row> <entry>10</entry> <entry>Earth</entry> <entry>$1</entry> </row> <row> <entry>100</entry> <entry>Mercury</entry> <entry>$5</entry> </row> <row> <entry>1000</entry> <entry>Mars</entry> <entry>$10</entry> </row> <row> <entry>10000</entry> <entry>Venus</entry> <entry>$20</entry> </row> <row> <entry>100000</entry> <entry>Jupiter, Saturn</entry> <entry>$50</entry> </row> </tbody> </tgroup> </table>
Pod formatting codes render directly into DocBook as inline elements:
\*(C`I<text>\*(C' <emphasis role="italic">text</emphasis>
\*(C`B<text>\*(C' <emphasis role="bold">text</emphasis>
\*(C`C<code>\*(C' <literal role="code"><![CDATA[code]] ></literal>
\*(C`L<name>\*(C' <citerefentry><refentrytitle>name</refentrytitle></citerefentry>
\*(C`L<name(n)>\*(C' <citerefentry><refentrytitle>name</refentrytitle> <manvolnum>n</manvolnum></citerefentry>
\*(C`L<name/"sec">\*(C' or \*(C`L<name/sec>\*(C' <quote>sec</quote> in <citerefentry> <refentrytitle>name</refentrytitle></citerefentry>
\*(C`L<name(n)/"sec">\*(C' or \*(C`L<name(n)/sec>\*(C' <quote>sec</quote> in <citerefentry> <refentrytitle>name</refentrytitle><manvolnum>n</manvolnum> </citerefentry>
\*(C`L</"sec">\*(C' or \*(C`L</sec>\*(C' or \*(C`L<"sec">\*(C' <link linkend="article-My-Article-sec"><quote>sec</quote></link>
\*(C`L<text|name>\*(C' text
\*(C`L<text|name/"sec">\*(C' or \*(C`L<text|name/sec>\*(C' text
\*(C`L<text|/"sec">\*(C' or \*(C`L<text|/sec>\*(C' or \*(C`L<text|"sec">\*(C' <link linkend="article-My-Article-sec"><quote>text</quote></link>
\*(C`L<scheme:...>\*(C' <ulink url="scheme:...">scheme:...</ulink>
\*(C`E<verbar>\*(C' |
\*(C`E<sol>\*(C' /
\*(C`E<number>\*(C' number;
any other \*(C`E<escape>\*(C' &escape;
\*(C`F<filename>\*(C' <filename>filename</filename>
\*(C`S<text with spaces>\*(C' text with spaces
\*(C`X<topic name>\*(C' <indexterm><primary>topic name</primary></indexterm>
Pod::2::DocBook makes every possible effort to produce valid DocBook markup, even with malformed \s-1POD\s0 source. Any processing errors will be noted in comments at the end of the output document. Even when errors occur, Pod::2::DocBook always reads the entire input document and never exits with a non-zero status. See \*(L"Command Paragraph\*(R" in perlpod for a list of valid commands. The command referenced in the error message was ignored. See \*(L"Formatting Codes\*(R" in perlpod for details on which formatting codes can be nested. The offending code was translated into the output document as the raw text inside its angle brackets. The input contained a formatting code not listed in perlpod; it was translated into the output document as the raw text inside the angle brackets. Self-explanatory. Self-explanatory; it was translated into the output document as the raw text inside the angle brackets. Self-explanatory. The `=item' referenced in the error was ignored. The closest `=end' command to the referenced `=begin' didn't match; processing continued as if the mismatched `=end' wasn't there. Pod::2::DocBook reached the end of its input without finding an `=end' command to match the `=begin' referenced in the error; end-of-file processing continued. See \*(L"Simple Tables\*(R" for a list of supported column specifications.
The state referred to is an internal variable used to properly manage nested DocBook structures. You should indeed never see this message, but if you do, you should contact the module's author.
pod2docbook, perlpod, Pod::DocBook, \s-1SVN\s0 repo - https://cle.sk/repos/pub/cpan/Pod-2-DocBook/ <https://cle.sk/repos/pub/cpan/Pod-2-DocBook/>, http://www.ohloh.net/projects/pod-2-docbook <http://www.ohloh.net/projects/pod-2-docbook>, doc/ + examples/pod2docbook-docbook/ for Pod::2::DocBook DocBook documentation
DocBook related links: <http://www.docbook.org/>, <http://www.sagehill.net/docbookxsl/>, http://developers.cogentrts.com/cogent/prepdoc/pd-axfrequentlyuseddocbooktags.html <http://developers.cogentrts.com/cogent/prepdoc/pd-axfrequentlyuseddocbooktags.html>
Alligator Descartes <[email protected]> wrote a module called Pod::2::DocBook, which was later maintained by Jan Iven <[email protected]>. That module was based on the original pod2html by Tom Christiansen <[email protected]>.
Nandu Shah <[email protected]> wrote Pod::DocBook, which is unrelated to the previous module (even though they both perform the same function). (http://search.cpan.org/~nandu/Pod-DocBook-1.2/ <http://search.cpan.org/~nandu/Pod-DocBook-1.2/>)
Jozef Kutej <[email protected]> renamed the module to Pod::2::DocBook because Nandus version was buried in the \s-1CPAN\s0 archive as an \*(L"\s-1UNAUTHORIZED\s0 \s-1RELEASE\s0\*(R".
Copyright 2004, Nandu Shah <[email protected]>
Copyright 2008, Jozef Kutej <[email protected]>
This library is free software; you may redistribute it and/or modify it under the same terms as Perl itself