next up previous
Next: General Structures Up: Using the Package Previous: Using the Package

Predicates for Generating HTML Documents

output_html(F)
Accepts in F an HTML term (or a list of HTML terms) and sends to the standard output the text which is the rendering of the term(s) in HTML format.

html_term(F,L,T)
Accepts in F an HTML term and produces in L a list of atoms which are the rendering of the term in HTML format. T is the tail of this list and is usually []. Used by output_html/2.

An HTML term is a Prolog term in which certain atoms and structures represent special functionality at the HTML level. It can be recursively a list of HTML terms. The following are legal HTML terms:

hello
[hello, world]
['This is an ', em('HTML'), ' term']

html_term/3 in general leaves atoms in HTML terms unchanged, but translates structures into the corresponding format in HTML, applying then html_term/2 recursively to their arguments.  For example, given the following code:

:- ['/usr/local/lib/prolog/html.pl'].

main :- 
  tell('html_simple.html'),
  icon_address(clip,ClipLogo),
  output_html([
    start,
    title('Simple HTML document generated from Prolog'),
    image(ClipLogo), nl,
    heading(1,'Simple HTML document'),
    'This document was produced with the ',tt('html.pl'),' library.', \\,
    'It has facilities for:',
    itemize([
      [em('Generating'),' HTML documents (including forms).'],
      [em('Parsing'),' input from HTML forms.'],
      [em('Producing'),' stand-alone forms handlers.'],
      etc
      ]),
    --,
    address('clip@dia.fi.upm.es'),
    end
  ]),
  told.
Loading this code and calling main/0 produces the file html_simple.html, the contents of which are:
<html><title>Simple HTML document generated from Prolog</title>
<img src="http://www.clip.dia.fi.upm.es/images/clip.gif">
<h1>Simple HTML document</h1>
This document was produced with the <tt>html.pl</tt> library.<br>
It has facilities for:<ul>
<li> <em>Generating</em> HTML documents (including forms).
<li> <em>Parsing</em> input from HTML forms.
<li> <em>Producing</em> stand-alone forms handlers.
<li> etc
</ul>
<hr>
<address>clip@dia.fi.upm.es</address></html>

As was shown with the previous example, HTML terms may contain logic variables, provided they are instantiated before the term is translated or output. This allows creating documents piecemeal, backpatching of references in documents, etc.

In the following sections we list the meaning of the various Prolog structures that represent special functionality at the HTML level. Any atom not included here is assumed to be normal text and will be passed through to the HTML document. These sections are included for reference, but in any case the source file is clear enough (perhaps more than this description). You can also examine the example files.





Mon Mar 18 21:38:39 MET 1996 <clip@dia.fi.upm.es>