NAME

notes2html - Converts annotated Perl code to HTML with popup notes or footnotes


SYNOPSIS

notes2html [options] [file]

Options:

    --popups, -p        display notes as popup windows
    --footnotes, -f     display notes as footnotes at end of document
    --line-numbers, -l  print line numbers for each line of code
    --fold=n            fold code lines longer than n columns (n >= 24)
    --title, -t         specify title for HTML document and popup notes
    --outfile=file      specify output file (otherwise stdout)
    --help, -?          brief help message
    --man, -m           documentation
    --version, -V       print program version


OPTIONS

--popups, -p
Display notes as popup windows. This option may not be specified together with --footnotes.

--footnotes, -f
Display notes as footnotes at the end of the HTML document. This option may not be specified together with --popups.

--line-numbers, -l
Print a line number at the beginning of each line of code.

--fold=n,
Fold code lines that are longer than n columns and print them on multiple lines of not more than n columns each, breaking at space characters where possible. Note that line numbers are not included in the folding calculations, so code lines will fold the same way whether you use the --line-numbers option or not.

--title=string, -t=string
Specifies a string to be used for the HTML document's <TITLE> and <H1> header; the string is also used in constructing the title and header for popup notes. If this option is not specified then the input file's filename will be used in titles and headers.

--outfile=file, -o=file
Specifies a file to which the HTML document will be written. If this option is not specified then the HTML document will be written to standard output.

--help, -?
Print a brief help message and exits.

--man, -m
Prints the program's documentation and exits.

--version, -V
Prints the program's version information and exits.


DESCRIPTION

notes2html will read a Perl program annotated with inline notes and will create an HTML document that will display the original code with added note references that link to the notes themselves. The notes can be displayed either in separate popup windows or as footnotes at the end of the HTML document.

The syntax of the inline notes is intended to be reasonably simple yet allow for special features where desired. It is also designed to be unobtrusive: if you'd like you can leave the inline notes in the program and they won't affect its execution; otherwise you can use grep -v '^##' to produce a version of the program without the notes. Here are some example inline notes to illustrate the syntax:

  ## This is an inline note referring to the Perl code line below
  ## that opens a file; inline notes are just Perl comments starting
  ## with two or more '#' characters and followed by at least one space.
  ## (You can also add an inline note to normal Perl comments as well.)
    open ($ifh, $input_fn) or die "$cmd: cannot open $input_fn: $!";
  ## You can also provide more than one note reference for a given
  ## line of code.
  ### All you have to do is change the number of initial '#' characters.
    while (<$ifh>) {
  ## Text paragraphs in notes are processed using Textile, so you can
  ## use simple markup, e.g., to emphasize *important things* or to
  ## cite documents like ??Programming in Perl??, or full HTML markup
  ## for such things as Perl expressions (like <code>$foo + 2</code>).
  ## A text paragraph is concluded with a "blank" comment as follows
  ## (or by a code line).
  ##
  ## You can also include preformatted text to refer to one or more
  ## lines of Perl code (or other content intended to be included
  ## verbatim) as part of the inline note; as with Pod, preformatted
  ## text is marked by indenting it more than a regular text paragraph.
  ##
  ##   $str =~ s/($escape_re)/$escape{$1}/g;
  ##
  ## You can include URLs in the preformatted text and they will be
  ## automatically converted to links; for example, see
  ##
  ##   http://www.example.com/an-example.html
  ##   ftp://ftp.example.com/pub/foo.tar.gz
  ##
  ## You can also include HTML links in regular text paragraphs,
  ## either by using the standard HTML <A> tag or by using the
  ## Textile syntax "text of link":http://www.example.com/foo.html.
  ##
  ## You can include bulleted lists or numbered lists using
  ## the standard Textile markup conventions:
  ##
  ## * Bulleted list items start with '*'.
  ## * Don't indent them, or they'll be taken as preformatted text!
  ## ** You can have sublists...
  ## *** ...or even sub-sublists
  ##
  ## # Mark numbered list items with an initial '#'.
  ## # Textile will add numbers automatically.
  ##
  ## h3. A Final Note
  ##
  ## Last but not least, you can use "h3.", "h4.", etc., to provide
  ## a header for the beginning of an inline note and subheaders
  ## within it.

The inline notes do not appear as part of the Perl code in the generated HTML. Instead each code line with an inline note (or notes) preceding it is displayed with a righthand Perl comment including note references in the form '[123]'; the note number is either an internal link pointing to a footnote at the end of the document, or a link to display a popup window containing the note.

The generated HTML document and the popup note windows contain only standard HTML, and should properly validate unless you've included non-standard HTML markup in your inline notes. In particular, the main HTML document should validate as HTML 4.01 Strict, while the popup notes should validate as HTML 4.01 Transitional. (In popup notes we use the TARGET attribute of the <A> tag, which is not permitted under the HTML 4.01 Strict DTD.)

One common problem for HTML validation is including something in a text paragraph that looks like an HTML tag, e.g., referring to a filehandle <FOO>; in cases like that you'll need to use the HTML character entities &lt; and &gt;, e.g., write &lt;FOO&gt; instead. (Note that this is not a problem in preformatted text, where the escaping of HTML special characters is done automatically.)


IMPLEMENTATION NOTES

We employ two separate approaches to storing note-related information and generating HTML for notes. When notes are to be displayed as footnotes (i.e., at the end of the HTML document) the approach is straightforward: save all notes in a Perl array as we encounter them in the input, and then iterate over the array to generate HTML for the notes after we have generated HTML for all the code lines.

The approach for handling popup notes is more complicated: As notes are encountered we do not save them in Perl; rather we generate JavaScript code to save the HTML for the notes in a JavaScript array in the context of the HTML document itself. That array can then be referenced in a JavaScript function popup_note invoked by the onClick handler for the links associated with note references.

Another possible approach would be to pass the HTML for the note as a JavaScript string literal directly to the popup_note function. This would eliminate the need to use a JavaScript array but would introduce a great deal of complexity in terms of how to properly escape characters in the string literal, since the string literal would be interpreted in a mixed HTML/JavaScript context (i.e., the onClick attribute of an <A> tag). Using a JavaScript variable reduces the complexity, since the literal is interpreted in more of a pure JavaScript context (i.e., within an HTML comment between <SCRIPT> and </SCRIPT> tags).


BUGS

The content of popup notes does not display when using Microsoft Internet Explorer for Mac OS X. (Instead the word ``undefined'' is displayed where the note contents should be.)

It is not possible to specify the --fold option and let the number of columns default to some reasonable value (e.g., to 80 columns); you must always explicitly specify the number of columns. (This is due to the limitations of the Getopt::Long module.)

The code to recognize URLs in the preformatted parts of inline notes will not recognize URLs with embedded whitespace. Also, the code recognizes only a limited subset of the URI schemes recognized by the IANA (see http://www.iana.org/assignments/uri-schemes).

If a note is included at the very end of the program (i.e., there are no program lines after the note) then a reference to the note will never be printed. The workaround is to put a standard comment after the note.

For consistency of style notes2html generates an initial header for each popup note using an <H2> tag, not an <H1> tag, to match the <H2> tag used to introduce a footnote. (An <H1> header is generated as a title for the code itself.) Using the Textile markup h1. or h2. within inline notes will produce headers which look odd and don't properly reflect structural markup within the generated HTML; you should use only h3. (or higher) headers within inline notes.

The interpolate subroutine within notes2html does not check to see whether interpolated variables in the HTML template strings are defined or not. This is an issue only if you modify notes2html to change the template strings.

In several places (e.g., the folding algorithm) the code is somewhat kludgy and doesn't necessarily evince proper Perl style. Suggestions for improvement are welcome.


TO DO

Here are some ideas for ways in which this program could be enhanced and extended:

Allow more control over popup note size and placement, either at the time the HTML document is generated or (ideally) at runtime. For example, the size and placement of the popup window could be computed taking into account the size of the user's screen and the size and placement of the main document window; if there's enough room the popup window should go to the immediate right of the note reference in the main window, placed far enough over so as not to obscure the code in the main window. It would be even nicer to let users move and resize a popup note to their liking, and then to reuse that size and placement for subsequent popup notes.

Allow a note to refer to another note using a symbolic name that would be converted to a note number in the generated HTML. Such references should also produce properly behaving links; i.e., a link in a footnote to another note should be an internal link, while a link in a popup note to another note should pop up a new window. In the meantime you can use the --line-numbers option and have a note refer to, e.g., the note for line 123.

Support other languages by changing the particular comment markers that are recognized and the comments for note references that are generated. In the meantime you can annotate Unix shell scripts and other files that use '#' to mark comments.

Support multiple files as input, producing a single file as output, including appropriate HTML headers to separate the code for the various files. In the meantime you can cat the files together before processing them with notes2html, adding some intermediate files that contain blank lines and comments to provide spacing between the code files.

Support specifying your own CSS styles for the generated HTML document and/or for popup note windows. (At present the CSS styles are hard-coded in the HTML template strings; the styles are loosely based on the styles used on the Perl documentation website.)

Support marking up inline notes using Pod instead of Textile. Note that this would not be the same as using Pod in the standard way, i.e., including Pod commands within the source file and then using a converter like pod2html to process the entire file as a whole. Rather this refers to using notes2html to recognize inline notes as described above, with each inline note (after stripping the initial '#' characters) containing a section of Pod markup to be processed independently of the Pod markup in any other note.


SEE ALSO

For more information on Textile markup see

  http://www.textism.com/tools/textile

Note that Text::Textile does not implement the full Textile specification; for example, it does not support using Textile markup for mailto: URLs.


VERSION

Version 0.94 (June 27, 2004).


AUTHOR

Created by Frank Hecker <hecker@hecker.org>. A few bits of code were inspired by and/or adapted from Rael Dornfest's Blosxom code.


COPYRIGHT AND LICENSE

Copyright 2004 Frank Hecker

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.