Plain Old Documentation, or just POD, is a simple documentation format used mainly among users of the Perl programming language. Most part of Perl's related documentation is written using POD.
Despite POD have been designed in a way a POD file could be read without the help of a formatting tool, most of time the POD file is translated to a language like HTML or TeX.
LuaPOD is a tool that allows to translate a POD file into HTML using Lua and the LPeg library.
LuaPOD is based on the POD specification available at http://search.cpan.org/~nwclark/perl-5.8.8/pod/perlpodspec.pod, however, there are some differences between the specification and the LuaPOD implementation:
LuaPOD considers that a POD file should be delimited by tags =pod
and =cut
, the
last one is optional and can be omitted.
Opposed to the POD specification, LuaPOD expects that you put a corresponding =back
at the end of each =over
region.
The =encoding
command is not supported.
The implementation treats an escape formatting code as an HTML entity reference, then
E<foo>
is translated to &foo;
.
The resolution of L codes depends of a base url that should be supplied.
If you want to know more about POD, a good place to go is http://search.cpan.org/~nwclark/perl-5.8.8/pod/perlpod.pod.
LuaPOD uses LPeg, a new pattern-matching library for Lua that is based on Parsing Expression Grammars (PEGs).
LuaPOD has a PEG grammar describing the expected general structure of a POD file, but this grammar will not deal with formatting codes. Because of this, LuaPOD parsers a POD file in two steps.
In a general way, each production of the PEG grammar has an associated function, which does some
actions and calls a function responsible by the output. The output function by turn will call,
if the POD formatting codes are being currently applied, the parsing
function to
resolve the formatting codes appropriately.
The functions responsible to deal with each formatting code are described in the
table tags
and should not be difficult to modify them.
As formatting codes can be nested, each time the parsing
function is called it tries
to find a set of characters indicating the beginning or the ending of a formatting code. If it finds
a sequence indicating a beginning, the correspondent sequence will be saved in the table formatTable
.
If a ending sequence is found, it is checked if it matches the last formatting code opened. In the end,
all formatting codes which were not matched will be closed.
To use LuaPOD inside your Lua program, the first thing to do is require ("pod")
. After this,
you can use the functions parser
and parserToBuffer
, which are described below:
parser (input, url, embedded, output): uses input as the input file, url as the base url when resolving
L codes, and output as the output file. If output is nil
, the output file will have
the extension .html and a name based on the name of the input file. If the base url supplied was
http://www.lua.org/, the L code L<name>
would produce a link to http://www.lua.org/name.
The embedded parameter, is a boolean indicating if the file generated by LuaPOD will be embedded into another
file, if this is the case, some tags like <head> and <body> will not be generated.
Example: pod.parser ("file.pod", "http://www.lua.org/", false, "file.html")
parserToBuffer (text, url, embedded): parsers text, using url as the base url when resolving L codes, and returns the result. The embedded parameter, is a boolean indicating if the output generated by LuaPOD will be inserted into another file, if this is the case, some tags like <head> and <body> will not be generated.
Example: local html = pod.parserToBuffer ("=pod\n=cut", "http://www.lua.org/", true)
If the structure of the POD file is not according LuaPOD's PEG grammar, the output file will be empty.
As LPeg is not part of the standard Lua distribution, you should download and install LPeg before start using LuaPOD. Follow this link to downlaod LPeg.
Click here to download LuaPOD from LuaForge.
You can also get LuaPOD from Google Code typing the following command line:
svn checkout http://luapod.googlecode.com/svn/trunk/ luapod
LuaPOD was developed by Sérgio Medeiros and is free software. If you have any comments or doubts, please send me an e-mail (smedeiros at inf dot puc-rio dot br).
Copyright © 2007 Sérgio Medeiros.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.