Htmlpp

Htmlpp Documentation

 
 Home 
 Introduction 
 Download 
 Docs 
 Support 
 Examples 
 Add-ons 
v.4.2a Ref v.4.2c Ref FAQ Known Bugs History

Version 4.2c Reference

Description

Htmlpp is a preprocessor for HTML files, and is intended to simplify the task of maintaining large sets of HTML documents. You provide htmlpp with a document that is a mix of HTML-tagged text and htmlpp commands. Htmlpp generates a set of HTML files from that document.

Command-line Syntax

To run htmlpp, use the following syntax:

htmlpp [-option...] filename ...

Where filename is assumed to have an extension '.htp' if necessary. You can use these command-line options:

  • The -debug option causes htmlpp to leave all its intermediate work files lying around. It will also make a backup copy of any database file it modifies, as well as backup copies of internal files connect.def and expires.def unless you redefine standard symbol $(BACKUP). Backup copies have extension '.bak'.
  • The -guru option makes htmlpp work in guru mode, which is explained in the Htmlpp Guru Mode section.
  • The -env option tells htmlpp to include the current environment in the symbol table.
  • The -nofunc option disables checking of intrinsic functions; this can be useful if your input text contains Perl code (which can itself contain lots of functions prefixed by '&'.
  • The -charset option defines the character set used in the source file. This is used to translate accented characters into HTML character entity references. Valid values are 'iso-8859-1' (you can also use 'latin-1', 'unix' and 'win' as synonymous) and 'ms-dos' (use also 'dos' or 'cp850' as synonymous).
  • The -noconnect option deactivates htmlpp storing connections between documents. Connections are explained in the Database Symbols and Connections Between Documents section.
  • The -connect option makes htmlpp automatically process all connected documents when some database symbol changes its value in current document.
  • The -expired option process all documents that have expired. You define a document to expire at a given date using the .expires command.
  • The -page option lets you select one or more pages to generate. If you do not use this option, htmlpp's default action is to generate every page in the document. You can generate the first page only by using this command:
    htmlpp -page 1 x
    
    You can generate a series of specific pages too:
    htmlpp -page 1,9-10,15 x
    
    You can also refer to page file names, instead of page numbers (but not using the 'nn-nn' syntax:
    htmlpp -page justhis.htm,andthat.htm xxxx
    
  • The -set option lets you set values from the command line; these override any default settings or settings made from within the htmlpp input. The syntax of this option is:
    -set name=value
    
    For example,
    htmlpp -set BASE=temp myfile.txt
    
    Under DOS, you must enclose name=value in quotes, e.g.:
    htmlpp -set "BASE=temp" myfile.txt
    

All command line options can be shortened to their significant letters, e.g. '-d' is the same as '-debug'.

Inserting Symbols

Htmlpp replaces symbols in command lines and HTML text. You can specify a symbol in various ways:

$(name)
Inserts the symbol name. If it is not defined and the multilingual symbols option is turned on (see $(USE_LANG) variable below), htmlpp will also search for the symbol name.xx where xx is the current language code (see $(LANG) variable below). name can also be a database symbol (see section on database symbols below). If none of the symbols is defined (see .define command below) you get an error message.
$(name?default)
Inserts the symbol name. If it is not defined and the multilingual symbols option is turned on, it will also search for the symbol name.xx where xx is the current language code. name can also be a database symbol. If none of the symbols is defined, inserts the supplied default value.
$(*name)
Inserts a link for the symbol name. This is shorthand for:
<A HREF="$(name)">name</A>.
If the symbol is not defined and the multilingual symbols option is turned on, it will also search for the symbol name.xx where xx is the current language code. Also, if name already includes a language code (e.g. $(*home.es)) which is different from the current language and the multilingual symbols option is turned on, the HTML 4.0 "hreflang=xx" attribute is automatically added in the <A...> tag.
name can also be a database symbol. If both symbols name and name.$(LANG) have an empty value, the <A...> and </A> tags are left-out - i.e. the link is not active.
$(*name*attributes*)
Inserts a link for the symbol name including attributes within the <A...> tag. It is useful is you are using some of the new attributes in HTML 4.0. This is shorthand for:
<A HREF="$(name)" attributes>name</A>.
If the symbol is not defined and the multilingual symbols option is turned on, it will also search for the symbol name.xx where xx is the current language code. Also, if name already includes a language code (e.g. $(*home.es)) that is different from the current language and the multilingual symbols option is turned on, the HTML 4.0 "hreflang=xx" attribute is automatically added in the <A...> tag.
name can also be a database symbol. If both symbols name and name.$(LANG) have an empty value, the <A...> and </A> tags are left-out.
$(*name=label)
$(*name="label")
Inserts a link for the symbol name, with label as specified. This is shorthand for:
<A HREF="$(name)">label</A>.
If the symbol is not defined and the multilingual symbols option is turned on, it will also search for the symbol name.xx where xx is the current language code. Also, if name already includes a language code (e.g. $(*home.es)) that is different from the current language and the multilingual symbols option is turned on, the HTML 4.0 "hreflang=xx" attribute is automatically added in the <A...> tag.
name can also be a database symbol. If both symbols name and name.$(LANG) have an empty value, the <A...> and </A> tags are left-out. You can use double quotes if the label itself contains ')' or its first character is '*'.
$(*name*attributes*=label)
$(*name*attributes*="label")
Inserts a link for the symbol name, with label as specified, and including attributes within the <A...> tag. This is shorthand for:
<A HREF="$(name)" attributes>label</A>.
If the symbol is not defined and the multilingual symbols option is turned on, it will also search for the symbol name.xx where xx is the current language code. Also, if name already includes a language code (e.g. $(*home.es)) that is different from the current language and the multilingual symbols option is turned on, the HTML 4.0 "hreflang=xx" attribute is automatically added in the <A...> tag.
name can also be a database symbol. If both symbols name and name.$(LANG) have an empty value, the <A...> and </A> tags are left-out. You can use double quotes if the label itself contains ')'.
$(*name=)
Inserts a link for the symbol name, with the full reference as label. This is shorthand for:
<A HREF="$(name)">$(name)</A>.
If the symbol is not defined and the multilingual symbols option is turned on, it will also search for the symbol name.xx where xx is the current language code. Also, if name already includes a language code (e.g. $(*home.es)) that is different from the current language and the multilingual symbols option is turned on, the HTML 4.0 "hreflang=xx" attribute is automatically added in the <A...> tag.
name can also be a database symbol.
$(*name=*attributes*)
Inserts a link for the symbol name, with the full reference as label, and including attributes within the <A...> tag. This is shorthand for:
<A HREF="$(name)" attributes>$(name)</A>.
If the symbol is not defined and the multilingual symbols option is turned on, it will also search for the symbol name.xx where xx is the current language code. Also, if name already includes a language code (e.g. $(*home.es)) that is different from the current language and the multilingual symbols option is turned on, the HTML 4.0 "hreflang=xx" attribute is automatically added in the <A...> tag.
name can also be a database symbol.
&(Perl program fragment)
Replaces the symbol by the output of the specified Perl code. The Perl code is executed using the eval command -- see your Perl documentation if you want to use this feature. This is how to replace the symbol by the output of a Perl program: &(`perl program`). You must enclose the program fragment in double quotes if it contains ( or ), or else escape these characters using '\'.
&name(arguments)
Replaces the symbol by the result of an intrinsic function. These are predefined functions that htmlpp provides for various purposes.
%(variable)
Replaces the symbol by the value of an environment variable. If the variable does not exist, inserts an empty value. For portability, always define environment variables in uppercase.
%(variable?default)
Replaces the symbol by the value of an environment variable. If the variable does not exist, inserts the specified default value. For portability, always define environment variables in uppercase.
\(
Replaces this by "(". This is to 'escape' symbol definitions so that they are not translated.
\.
Replaces this by ".". This is to 'escape' dots so that they are not interpreted as commands, at the start of a line.

You can define symbols in terms of symbols: $($(name)) is quite okay, if you know what you are doing. Htmlpp inserts symbols from right to left in the line.

Types of Symbol

Symbols are of various types

  • htmlpp provides various symbols when building certain blocks like the table of contents;
  • htmlpp provides various symbols containg default values that you can redefine if necessary;
  • you can define symbols using the .define command;
  • you can define symbols using the .build anchor command;
  • you can define database symbols after a .savedb command;
  • symbols can be defined for several languages if you are running a multilingual site.

Standard Symbols

Htmlpp provides these standard symbols for use at any point in the document:

$(DATE)
The date that htmlpp started, formatted as an 8-character string: YY/MM/DD.
$(TIME)
The time that htmlpp started, formatted as an 8-character string: HH:MM:SS.
$(DOCBASE)
The main document filename, without extension.
$(INC)
A counter, which starts at zero and is bumped-up each time you refer to it. I use this to number filenames, in the .page command. The first time you use $(INC), it is empty - i.e. "". The second time it is "1", then "2", "3", "many", "manymany", and "manymanymany" (joke, sorry).
$(PAGE)
After a .page command, this holds the page filename, exactly as specified in the .page command.
$(TITLE)
After a .page command, this holds the page title. It is nice to use this in the header block.
$(PIPE_TITLE)
After a .pipe command, this holds the pipe title. It is nice to use this in the pipe_header block.
$(PASS)
Contains either 0 or 1, depending on whether htmlpp is scanning for titles (0) or building the output files (1).
$(HITS)
The number of rows returned in the last one of any of the following types of .for loops:
   .for name in `command`
   .for name in @filename
   .for name in %filename [...]
It is undefined until the first of any of these .for loopS is used. If you use it after several nested .for loops, it will remember the hits of the outermost loop.
You may want to (re)define some of these symbols:
$(BASE)
Defined as "doc". This is used in .page commands for automatic filename generation.
$(EXT)
Defined as "htm", and commonly-used hot on the heels of a $(BASE).
$(DIR)
Defined as "." and used to prefix the filename for the generated HTML pages.
$(SILENT)
Defined as 0. If you .define this as 1, htmlpp will try to be a bit quieter. When you are generating *lots* of pages, it is easy to lose real warnings and errors amidst the information messages.
$(LINEMAX)
Defined as 79. Htmlpp warns if it finds longer lines. If you don't want to see these warnings, set it to 0.
$(ESC_HYPHEN)
Defined as 0. If you .define this as 1, you are allowed to escape trailing hyphens in Htmlpp commands by preceding them of a backslash - This symbol is new in version 4.2c, and is disactivated by default in order not to break old code, but take into account that escaping trailing hyphens will be the default behavior in future releases.
$(END_MACRO)
Defined as 0. If you .define this as 1, you enable the new command .endmacro to end macro definitions, and you don't need to add trailing hyphens in each continuation line of the macro. This symbol is new in version 4.2c, and is disactivated by default in order not to break old code, but take into account that the .endmacro command will be the default behavior in future releases.
$(DEBUG_MODE)
Has the value 1 when htmlpp is operating in debug mode, and 0 otherwise. To use debug mode, use the -debug command-line option.
$(BACKUP)
If it has value 1, htmlpp will make backup copies of any database it modifies and of internal files connect.def and expires.def, with the extension '.bak'. By default has value 1 in debug mode and 0 otherwise.
$(NO_CONNECT)
Has the value 1 when htmlpp does not store connections between documents, and 0 otherwise (default). To turn on no-connect mode, use the -noconnect command-line option.
$(CONNECT)
Has the value 1 when htmlpp automatically process all connected documents whenever a database symbol is modified in current document, and 0 otherwise (default). To use connect mode, use the -connect command-line option.
$(LANG)
A two-character code for the language that htmlpp will use in the formatting dates subroutines. It will also be used to search for symbols of type name.$(LANG) when multilingual variable search is activated. Its default value is "en" for English. Other supported languages are "es" for Spanish, "da" for Danish, and "fr" for French.
$(USE_LANG)
Defined as 0. If you .define this as 1, htmlpp will search multilingual symbols of type name.$(LANG), and will add the hreflang attribute in <A..> tags when $(*name) already ends up with a .xx language code.
$(USE_RELPATH)
Defined as 0. If you .define this as 1, all $(*name) links whose URL does not start with "http://", "ftp:", "mailto:", "./", or "../" will be considered within-site absolute links and will be made relative.
$(Hn)
Where 'n' is 1 to 9, defines a header level number. You would use this to generate headers like this:
1
1.1
1.2
1.2.1
1.2.2 ... etc.
Htmlpp automatically manages the numbering of header levels. You are, however, limited to the 'dotted number' syntax.
$(DB_DELIM)
The delimiter that separates flat-text database fields used in .for database queries. Takes the value '|' by default.
$(DB_ESC_DELIM)
The string that substitutes the field delimiter in .for database queries if this is found in the data. Takes the value '~p~' by default.
$(DB_ESC_NL)
The string that substitutes new lines in .for database queries if these are found in the data (because each database entry must be in a single row). Takes the value '~nl~' by default.
$(DB_COMMENT)
The string at the beginning of a flat-text database row which denotes that the row should be skipped. Takes the value 'COMMENT:' by default.
$(DB_FIELDS)
The string that, if it appears after $(DB_COMMENT) in a .for database query, denotes that the row contains the field labels for the database. Takes the value 'FIELDS:' by default.
Unless you use .ignore pages, these symbols are available in header and footer blocks (you can use them elsewhere, but you'll get warnings):
$(FIRST_PAGE)
The filename for the first page of the document.
$(LAST_PAGE)
The filename for the last page of the document.
$(NEXT_PAGE)
The filename for the next page of the document.
$(PREV_PAGE)
The filename for the previous page of the document.
$(FIRST_TITLE)
The title for the first page of the document.
$(LAST_TITLE)
The title for the last page of the document.
$(NEXT_TITLE)
The title for the next page of the document.
$(PREV_TITLE)
The title for the previous first page of the document.

In addition, htmlpp will include the current environment symbols if you run it with the -env option. You can use this (although I don't see the utility immediately) to redefine any of the standard symbols such as $(EXT). Remember that you can also access any of the environment symbols using the %(...) syntax; e.g. %(PATH).  

Database Symbols and Connections Between Documents

Database symbols are so called because they are stored in a flat-text database so that they can be accesed from any htmlpp document.

Databases of symbols are composed of rows where each row is an entry. Entries are identified uniquely by a field whose name must be "ID". Fields in each row are separated by a pipe ("|") symbol. If a symbol is stored in the database which itself contains a pipe symbol, it is escaped as "~p~". Because entries must be in a single row, new lines are also escaped as "~nl~". Comment lines may be included writing "COMMENT:" at the beginning. Field names must be defined in a comment line adding "FIELDS:" after the "COMMENT:" string. The line must be composed of pipe delimited field names, and determines the order in which symbols will be stored in the database. Don't forget the required "ID" field. If you include a "Last Modified:" string in a comment line, htmlpp will write the date and time it last updated the database.

To create a database of symbols you must first create a text file that defines the structure of the database, for example:

COMMENT: "pages.db"
COMMENT: Database of pages for Enrique Bengoechea's WEB site.
COMMENT: Last Modified:
COMMENT:
COMMENT: FIELDS: ID|url|title|description|section|subsection|created|modified
COMMENT:
COMMENT: This database is automatically updated by Htmlpp.
COMMENT: If you modify it by hand, don't forget to replace any pipe and new
COMMENT:  line characters in the data by ~p~ and ~nl~ respectively.
COMMENT:

To use database symbol you must first load the database in memory with the .loaddb command, for example:

.loaddb pages /databases/pages.db
(and optionally add query criteria to load only a subset of the database) In this example pages is the database code that will allow you to access the symbols in pages.db. To access the value of field created in entry home (that is, in the row whose first field, the one named "ID", has value home), you would write
$(pages#home#created)
You can also use the symbols in links, for example:
$(*pages#home#url=$(pages#home#title))

If language symbol search is activated by setting variable $(USE_LANG) to 1, you can simplify name.xx to name, where xx is the current value of $(LANG), both for the entry ID and the field name. That is, if entry home.es and field url.es are defined, you can write $(pages#home#url) and it will be interpreted as $(pages#home.es#url.es) if $(LANG)=es.

Because the syntax is a bit long, you have the command .defaultdb to simplify your life. Make

.defaultdb pages
and $(#home#created) will be the same as $(pages#home#created). Make
.defaultdb pages created
and $(pages#home#) will be the same as $(pages#home#created). You can also mix both possibilities.

Remember that you can also access sorted series of database symbols using the .for command to query flat-text databases. This can be useful to create site-wide tables of contents, "What's New in This Site" pages and so on.

To add new entries to the database or modify existing entries, you must first use the command .savedb, for example

.savedb pages /databases/pages.db
Note that the code that identifies the database can be the same than the code you use in a .loaddb command for the same database or a different one. After the .savedb command, you can define database symbol in the same fashion as other symbols:
.define pages#home#created  19981101
You don't have to explicitly define the "ID" field. For example, in previous command htmlpp understands that home is the entry identifier. If it already exists, field created will be modified, and if it doesn't a new entry will be added to the database. If this is the case, a warning message will be issued (just in case you mistyped the entry ID).

Database symbols are also used to define connections between different htmlpp documents. htmlpp remembers all the documents where each database symbol is used by writing them to file connect.def (we highly recommend that you don't modify this file by hand), unless the -noconnect command-line option is activated. Whenever a database symbol is modified in a document, htmlpp will tell you to reprocess all files where the symbol is used, and if the -connect command-line option is turned on, it will process them automatically. This is useful in big and complex sites in which it is hard to remember where a given link, date, etc. is used. For example, if you modify an entry in the database of "What's New in This Site", Htmlpp will reprocess the document that summarizes all novelties and modifications in the site. Or, if a link changes its path, you don't have to remember that the link was used in other 30 documents, Htmlpp will remember it for you and process the 30 documents so that the change is updated throughout the whole site. No more outdated information!

Realize that to use the connections characteristics you must have all the source htmlpp documents that compose the site in a single directory. Note also that if you identify entries in a database by the name of the source document (as you would tipically do in many situations) and you modify the name of that document at any moment, all connections for the old name will be kept, and you must erase them by hand, although a better solution is to erase the file connect.def from time to time and reprocess the whole site. It is important that in general you will have to process the site *TWICE* to get all cross-references solidly updated.

You can define standard symbol $(BACKUP) to 1 in order to htmlpp make a backup copy of any database it modifies, as well as backup copies of internal files connect.def and expires.def, all with extension '.bak'. $(BACKUP) is set to 1 by default in debug mode and to 0 otherwise.

Remember that you can also use the .expires command (possibly in conjunction with database symbols and some date-related intrinsic functions) as another powerful automatic site management tool. A good use of both features will make your site never be outdated.

Htmlpp Commands

A htmlpp command starts with a dot, in column 1, followed by a keyword. You can put spaces between the dot and the keyword. To continue the command line over the next line, end the line with a hyphen (though you need to at least put the dot and the keyword on the same line). If you need your line to end up with an hyphen, you may escape it with a backslash - Commands can be in upper- or lower-case: .endblock and .EndBlock are equivalent.

These are the commands that htmlpp understands:

The .define Command

.define symbol [value]
Define a symbol with the specified value. The symbol name can consist of letters, digits, -, ., and _. The value is everything else up to the end of the line. If you omit the value, the variable is un-defined. You can redefine a variable as often as you like simply by repeating the .define command. Use lowercase for your own symbols. Predefined htmlpp symbols are uppercase. Case is significant. You can assign values to the built-in htmlpp variables like INC if you want to. In some cases this is even useful. If you append .xx to the symbol name, where xx is a two-characters language code, you can afterwards use the variable as $(symbol) without writting the language code, provided $(USE_LANG)=1 and $(LANG)=xx. You should use standardized ISO-639 language codes. You can define database symbols of the form database_code#entry_ID#field_name provided you previously used the .savedb command. All database symbols defined in this way will be stored in the database file. If you add/redefine with a different value a database symbol which is used in other htmlpp documents, htmlpp will also process all those 'connected' documents when the -connect command-line option is activated.

.define symbol = expression
Evaluates the expression and stores the result in symbol. Note that you must use '=' to evaluate an expression. Otherwise the expression is considered as a string and stored as-is in the symbol. Htmlpp passes the expression to Perl for evaluation, so you can use any valid Perl syntax. If you want your htmlpp files to be portable to (future) non-Perl implementations of htmlpp, restrict the expressions to simple arithmetic (+, -, *, /, and parentheses). This is an example:
.define count = 1
.echo $(count)
.define count = $(count) + 1
.echo $(count)
Of course it helps to know that htmlpp will evaluate all variables before passing the expression to Perl to work out. So, the second .define is evaluated as '1 + 1'. If you decide to rely on Perl (a good bet for now), you can use the .define = command to execute shell commands, e.g.:
.if $(PASS)
.  define junk = system "rm *.htm";
.endif
If you append .xx to the symbol name, where xx is a two-characters language code, you can afterwards use the variable as $(symbol) without writting the language code, provided $(USE_LANG)=1 and $(LANG)=xx. You should use standardized ISO-639 language codes. You can define database symbols of the form database_code#entry_ID#field_name provided you previously used the .savedb command. All database symbols defined in this way will be stored in the database. If you add/redefine with a different value a database symbol which is used in other htmlpp documents, htmlpp will also process all those 'connected' documents when the -connect command-line option is activated.

.define symbol++ initial_value
Creates or re-initialises a counter with the initial value. Each time you use the counter symbol, it is incremented. The $(INC) symbol is actually defined internally like this:
.define INC++ ""
Note that the empty string is treated as zero; the next time the symbol will be '1'. You can also use '--' after the symbol name to subtract one from its value each time it is used. You can stick the '++' or '--' before the symbol name: then the symbol is incremented or decremented before its value is taken.
The .define statement is resolved as late as possible: if the statement refers to other variables, these are inserted when the .define'd variable is used, rather than when it is defined. For instance if you refer to a .define'd variable in the page header, it will be re-evaulated each time the page header is output.

The .macro Command

.macro [-nosplit|-noquote] name macro-body
Defines or redefines a macro. The macro body can go over several lines, either continuing each line with '-' or using the .endmacro optional command which is turned on by defining the flag 1 to 1. When htmlpp outputs a macro, it replaces arguments in the body with values you supply at the time. The arguments are $1, $2, and upwards and $*, which work as follows: $1 to $n are the first to n'th argument you supply; $* is the whole string of arguments. If the macro body is "", the macro is given an empty body. Otherwise, any quotes you use will be included in the macro body as-is. If you use the -nosplit option before the macro name, the macro will only ever have one argument, $1. Without this option, macro arguments are split on whitespace, with quotes and apostrophes being used to group arguments. See the section on Htmlpp Macro Processing for details. The -noquote option automatically escapes quotes in the macro arguments.

The .endmacro Command

.endmacro
End the previous .macro. You can end a .macro with an .endmacro or a further .macro command. This command is new in version 4.2b and is disactivated by default (when disactivated you must continue lines in the macro body with a trailing hyphen) not to break old code. But take into account that .endmacro will be the default in future releases. To turn it on, define standard symbol 1 to 1.

The .include Command

.include [-ifexist] filename
Start reading from the specified file. You can nest .include files as much as you like. Htmlpp checks for circular references. If the same file was already included earlier, htmlpp ignores the command, like the Perl 'require' operator. Htmlpp searches along the LIBPATH environment variable for the file. If you specify a filename with a full path, htmlpp won't search the LIBPATH. If htmlpp can't find the document using LIBPATH, it'll search PATH too. If the file is not found, Htmlpp will die unless the -ifexist option is used. Using -ifexist makes Htmlpp show a warning that the file is not found and continue processing.

.include [-ifexist] filename!
Include the file in any case, like a C #include directive. If the file is not found, Htmlpp will die unless the -ifexist option is used. Using -ifexist makes Htmlpp show a warning that the file is not found and continue processing.

.include `command`
Execute 'command' and include the output of the command in the generated HTML text. The command can be any program with arguments; it should respect any operating system conventions or limitations. The output text can contain htmlpp symbols in the normal manner. It cannot contain htmlpp commands.

The .page Command

.page filename = []title[]
Start writing a new HTML file. The title is required. At any point after the .page, you can refer to $(PAGE) and $(TITLE) for the current file name and title. For instance, you'll often see this:
<H1>$(TITLE)</H1>

.page []title[]
Equivalent to .page $(BASE)$(INC).$(EXT) = "title". Just easier.

The .pipe Command

.pipe filename=title
Tells htmlpp to create a secondary file, as specified, and to send output there as well as to the primary file specified by the last .page command. The .pipe command is useful when you want to send part of a HTML page into another file, for instance to generate a small readme.htm file for an installation. The piped file is prefixed by the PIPE_HEADER block and ended with the PIPE_FOOTER block, if these are defined.

The .expires Command

.expires on date
Defines the content of the current document to expire on date date (in YYYYMMDD format). If you invoke htmlpp with the -expired command-line option in that date or later (provided you didn't already processed the document after date by hand) the document will be automatically processed. If you use several '.expires on' commands in your document, only the closest date in time will be saved.

Htmlpp stores all .expires definitions in file expires.def. It is strongly recommended that you don't edit this file by hand. A backup copy of the file with extension '.bak' is created whenever it is modified if standard symbol $(BACKUP) is set to 1 (the default in debug mode). You can mix all the types of .expires command in your document. All criteria are stored, and the document will be reprocessed when you use the -expired switch if any of the criteria holds. You can use the Unix cron utility (or a similar one in other platforms) to call htmlpp with the -expired switch every day/week/... so as to always have your site updated.

.expires after-days days
Defines the content of the current document to expire after days days since it was last processed. If you invoke htmlpp with the -expired command-line after that number of days or later the document will be automatically processed. If you use several '.expires after-days' commands in your document, only the smallest days will be saved.

.expires every-week-day day_of_the_week, ...
Defines the content of the current document to expire every day_of_the_week. day_of_the_week can take the values "monday", "tuesday", ..., "sunday". You can define several days of the week separating them by commas. If you invoke htmlpp with the -expired command-line after that day of the week or later (provided you didn't already do it by hand) the document will be automatically processed. If you use several '.expires every-week-day' commands in your document, only the last one will be saved.

.expires every-month-day day_of_the_month|LAST, ...
Defines the content of the current document to expire every day_of_the_month. day_of_the_month can take values between 1 and 31 or "LAST" for the last day of each month. You can define several days of the month separating them by commas. If you invoke htmlpp with the -expired command-line after that day of the month or later (provided you didn't already do it by hand) the document will be automatically processed. If you use several '.expires every-month-day' commands in your document, only the last one will be saved.

.expires every-month month, ...
Defines the content of the current document to expire every month. month can take values between 1 and 12. You can define several months separating them by commas. If you invoke htmlpp with the -expired command-line after the first day of the supplied month or later (provided you didn't already do it by hand) the document will be automatically processed. If you use several '.expires every-month' commands in your document, only the last one will be saved.

The .ignore Command

.ignore header
Ignore the next header line as far as the table of contents is concerned. This is good for headers like <H2>Table of Contents</H2>.

.ignore header level
Ignores all headers with level greater or equal to level. This is useful if a section has a lot of H3 and H4's that you don't want in the table of contents. Use .ignore header 99 to re include all further headers.

.ignore pages
Ignore all .page commands except to pick-up the page titles. Use this when you want to create a super-document. When you use .ignore pages, htmlpp also ignores the .build toc and .build index commands. So, if you want a table of contents, do the .build toc before you say .ignore pages. You can also use .if commands to skip blocks of text under certain conditions.

.ignore page
Ignore next .page command for any future .build index command. This is the right way of keeping the index page itself out of the index. Note that the index page does take part in the general page-to-page linking scheme provided by $(PREV_PAGE) and such.

The .if Command

.if expression
[.else]
.endif
If the expression returns a false value, htmlpp skips until the .else or .endif line. You can nest .if blocks. An .else is always part of the closest preceding .if. Htmlpp passes the expression to Perl for evaluation, so you can use any valid Perl syntax. If you want your htmlpp files to be portable to (future) non-Perl implementations of htmlpp, restrict your expressions to simple arithmetic and logical tests (<, >, =, etc.). Otherwise, enjoy Perl's vast range of tests. This is quite okay:
.if -f myfile.htm
An .if block must be entirely in one line.
These are some examples of .if expressions:
.if $(number) == 0
.if $(number) != 1
.if $(number) > 2
.if $(string) eq "value"
.if $(string) ne "value"

The .block Command

.block blockname
Define a piece of HTML text to be output as part of a .build command. You can end the .block with an .endblock or another .block. Htmlpp knows about these block names:
header
Output at the start of each new HTML page; i.e. whenever you use a .page command.
footer
Output at the end of each HTML page.
toc_open
Output at the start of a .build toc block (see below), and whenever htmlpp decides to indent a new level.
toc_entry
Output for each entry in the table of contents. Use these symbols: $(TOC_HREF) - the local URL for the file and section; $(TOC_TITLE) - the title for the section, taken from the header line; $(TOC_LEVEL) - the table-of-contents level, 1 and higher.
toc_close
Output whenever htmlpp decides to outdent a level, and at the end of the table of contents.
dir_open
Output at the start of a .build dir block (see below).
dir_entry
Output for each entry in a .build dir block. Use these symbols: $(DIR_HREF) - URL for the file; $(DIR_NAME) - the filename, left-justified; $(DIR_EXT) - the file extension, always put into lowercase; $(DIR_SIZE) - the file size, right-justified; $(DIR_DATE) - the file date; $(DIR_TIME) - the file time. You can also use $(DIR_SIZEK) and $(DIR_SIZEM) to get the file size in Kbytes and Mbytes, and $(DIR_HREFL) to get the URL for the file in lowercase.
dir_close
Output at the end of a .build dir block.
index_open
Output at the start of a .build index block (see below).
index_entry
Output for each entry in a .build index block. Use these symbols: $(INDEX_PAGE) - the filename; $(INDEX_TITLE) - the file title. For compatability with earlier versions, htmlpp also accepts the name 'index'.
index_close
Output at the end of a .build index block.
for_open
Output at the start of any of the following .for commands, displayed only if the loop returns at least one row:
   .for name in `command`
   .for name in @filename
   .for name in %filename [...]
Use the $(HITS) symbol for the number of rows the loop returns. This block clears after it is used, so you have to define it before each .for loop.
for_close
Output at the end of any of the following .for commands, displayed only if the loop returns at least one row:
   .for name in `command`
   .for name in @filename
   .for name in %filename [...]
Use the $(HITS) symbol for the number of rows the loop returns. This block clears after it is used, so you have to define it before each .for loop.
anchor
Output whenever you use a .build anchor. Use this symbol: $(ANCHOR) - name of anchor.

Any other block is treated as a user-defined block and can be output at any point using a matching .build command.

.block blockname local
You can follow the .block command by the keyword local - this defines a block that will be used one time only. The local keyword applies to header, footer, and anchor blocks. Local blocks are used to change the way a single page looks, without disturbing the headers and footers of the whole document. Typically, you would define a general document header at the start of the document, then a local header and footer for a specific .page. Note that you should define the local page footer after the .page command. If you define a local footer block before the first page, htmlpp handles this correctly.

The .endblock Command

.endblock
End the previous .block. You can end a .block with an .endblock or a further .block command. Any other command within a .block is interpreted when the block has been generated.

The .build Command

.build toc
Build table of contents for document. Htmlpp scans the document and all include files once to collect titles (<Hn>...</Hn>) and once to create the HTML pages. Titles (<Hn>...</Hn>) must be entirely on a single line, or htmlpp will not find them. You can manage the contents of the table of contents through the .ignore header command. You will normally use a .build toc at the start of a document.

.build dir directory [filespec...]
Build directory listing as specified. The .build dir command only works if you mirror the server directory on some local disk that htmlpp can access. This is a Good Idea in any case. Before you can use .build dir you must define LOCAL and SERVER. I define these like this:
.define LOCAL   i:/site:
.define SERVER  http://www.imatix.com
The directory must be relative to either of these two. It should start with '/' but not end with '/'. You can specify zero or more filenames or wildcards (htmlpp accepts * and ?, according to UNIX rules). If you specify no filespecs, htmlpp assumes you mean '*'. The filespecs can include PERL regular expressions: place the filespec between double quotes, e.g. to match all files with 'doc' or 'txt' somewhere in the name: .build dir /pub "doc|txt". An example might help:
.define .txt   Text file
.define .htm   HTML document
.define .zip   ZIP archive
.block dir_open
<PRE>
.block dir_entry
$(*DIR_HREF="$(DIR_NAME)") $(DIR_SIZE)  $($(DIR_EXT))
.block dir_close
</PRE>
.endblock
Note the sneaky double-derefencing of $(DIR_EXT) which translates the file extension into a comment like 'Text file'. I usually stick all such .defines in a separate .include file, filetype.def.

.build index
Build file index for document. This is basically a list of all pages in the document with their titles. If you use this, you may want to put an .ignore page before the .page that starts the index page. It may be useful to do a .build index inside the footer of a page -- this is quite okay.

.build anchor anchor-name[=title]
Build an anchor definition. This is useful. Basically you do a '.build anchor somename' in a document, then do a $(*somename) or $(*somename="label") anywhere in any other document. Htmlpp saves anchor symbols in the file anchor.def; otherwise anchor symbols are treated much like normal .define'd symbols. One difference: anchor symbols and normal symbols do not share the same namespace; if you .define a symbol with the same name as the anchor symbol, the .define'd symbol takes precedence. If you undefine the symbol, the anchor symbol reappears by magic. This may or may not be useful, but it is the way it works. If you change the file structure of your document, run everything through htmlpp *TWICE*, so that all anchor references can get really solidly updated. You can delete the anchor.def file at any time; it is just kept to save some context between runs. When you use the form $(*somename) to refer to an anchor, htmlpp will insert the anchor title as the label.

.build [-ifdef] user_block_name
Output the user-defined block specified. This is any amount of text that you do not want to specifically put into a separate file for use with the .include command. You define the block using the .block command. If the block has not been defined, Htmlpp will die unless the -ifdef option is used. Using -ifdef makes Htmlpp show a warning that the block is undefined and continue processing.

The .perl Command

.perl
[Perl program fragment]
.endperl
Replaces the text between .perl and .endperl by the output of the specified Perl code. The Perl code is executed using the eval command -- see your Perl documentation if you want to use this feature: you shouldn't touch what's internal to htmlpp, try to use your own name space, etc. Symbols are expanded before Perl evaluation.

.perl intrinsic_function_name
[Perl program fragment]
.endperl
Defines a new htmlpp intrinsic function. You can redefine existing intrinsic functions, but htmlpp will issue a warning. No htmlpp symbol expansion is performed on the code (all variables should be passed as arguments).

The .echo Command

.echo [-] text
Echoes the text to the console. Strips-off any leading and trailing spaces, but you can enclose the text in single or double quotes if you want leading/trailing spaces. Unless you place a hyphen before the text, htmlpp adds a newline.

The .for Command

.for name in item...
.endfor
Repeats the text between .for and .endfor, where $(name) has the value of each item in the list. The item list is separated by spaces.

.for name in `command`
Repeats the text between .for and .endfor, where $(name) has the value of each line in the output generated by the command. The special variables $(1), $(2), and so on will hold each word in the line, and the variable $(HITS) the total number of lines. You can use blocks for_open and for_close if it is possible that the command returns no lines.

.for name in @filename
Repeats the text between .for and .endfor, where $(name) has the value of each line in the specified file. The special variables $(1), $(2), and so on will hold each word in the line, and the variable $(HITS) the total number of lines. You can use blocks for_open and for_close if it is possible that the command returns no lines.  

.for name in %filename [sort_by] [sort_order] [exact_match] [case_sensitive] [criterion ...]
Repeats the text between .for and .endfor, where $(name) has the value of each row which satisfies the given query in the specified flat-text database file filename. You can define the format of the database by redefining standard symbols $(DB_DELIM), $(DB_ESC_DELIM), $(DB_ESC_NL), $(DB_COMMENT) and $(DB_FIELDS). The special variables $(1), $(2), and so on will hold each field in the line. You can also access fields by their names if the database includes a row with the fields labels, using the special variable $(%name). The variable $(HITS) holds the number of rows resulting from the query. You can use standard blocks 'for_open' and 'for_close' if it is possible that the query returns no hits.

The rows will be sorted according to the values of the field number defined by sort_by (starting at 1). sort_order can take the values "asc" or "desc" that instruct htmlpp to sort the rows resulting from the query in ascending or descending order. If you leave sort_order empty, the default is ascending.

Each query criterion is defined by four pipe-delimited fields. You can use as many criteria as you want. Rows must satisfy all of the supplied criteria. The fields are the

  1. value to be matched
  2. index of field into the database that this criteria applies to (starting at 1)
  3. operator for comparison
    Possible values: >,<,>=,<=,=,!= (not equal), reg (regular expression)
    The operator is compared the following way:

    value OPERATOR database_field_value

    That is, (1) above is the left hand side of the operator and (2) above is the right hand side of the operator, unless the operator is "reg", in which case the value to be matched must be a valid Perl regular expression (you must escape all backslashes with another backslash for it to work. For example, to match an integer number you should use "\\d+").
  4. data type of the field (this determines how the operator in (3) gets applied to the data. It is irrelevant if the operator is "reg")
    The data type can be: date, number, or string
    If the data type is a date, then the operator for comparison is done after the value to be matched. Note that dates must be in YYYYMMDD format.
    If the data type is a number, then the operator for comparison is done based off of numerical if operators (>,<,==, etc.)
    If the data type is a string, then the operator for comparison is done based off of string if operators (gt, lt, eq, ne, etc.) with ONE EXCEPTION.
    If the datatype is a STRING *AND* the operator is =, then the search that is done becomes a more flexible search:
    • All the words in the form variable are split apart and searched as separate keywords in the text of the fields.
    • By default, the search on string = string is a pattern match search and is not case sensitive.
    • If you want this special string,= combination searching to be case sensitive and to match on whole words only, you MUST set case_sensitive and exact_match to on
      If exact_match is on then the combination of string,= in the query criteria array will match on WHOLE WORDS only.
      If case_sensitive is on then the combination of string,= in the query criteria array must have matching case values (upper/lower).
Examples:
  • "20|9|<=|number" "40|9|>=|number": return all rows in the database whose field number 9 value is between 20 and 40.
  • "hello world|1,2,3,4,5|=|string": return all rows in the database that contain the words "hello" and "world" (in that order if exact_match is set to on, otherwise in any order) in any of the fields from 1 to 5.
  • "^.+\\.en$|1|reg|string": return all rows in the database whose first field contains a string that ends up with extension ".en" (this can be a language symbol).
Suggestions:
  • You can use this .for command to access sorted series of database symbols in order to produce site-wide tables of contents, "what's new in this site" pages, and so on.
  • You can use some of the free tools in Internet to generate flat-text databases with and HTML interface, so that even other people can fill the data and your pages will be generated using those data. See for example Selena Sol's Database Manager.
  • By combining the -set command-line option with this .for loop you can automate mass-production of similar pages from a single htmlpp document.
    Imagine you want to make a page for each of the employees in your company. The employees themselves can fill their data through the web with some of the tools mentioned above. You make a htmlpp document with something like:
    .for row in %staff.db "2" "asc" "on" "on" "$(person)|1|=|string"
    .page "$(5)" = "$(2) $(3)'s Homepage"
    <UL>
        <LI>E-mail: <A href="mailto:$(4)">$(4)</A>
        <LI>Office: $(5)
    [...]
    .endfor
    Then calling 'htmlpp -set person=personcode template_file' for each person will produce his/her personal page.
    Htmlpp will be clever and consider as different the same document processed with different values of the person variable when using connections and when verifying expired documents, if you use '.connect symbol person' in the document.

.for name from start to end
Repeats the text between .for and .endfor, where $(name) has a numeric value from start to end inclusive. Htmlpp will count up or down as necessary.

The .loaddb Command

.loaddb database_code database_path [exact_match] [case_sensitive] [query_criterion]...
Loads the flat-text database from file database_path. If you define one or more query_criterion only the entries satisfying the query will be loaded. See the .for command to query flat-text databases for details on how to specify the query criteria, and the section on database symbols for details about the structure flat-text databases must have.
You can access database symbols after a .loaddb command through
$(database_code#entry_ID#field_name)
$(*database_code#entry_ID#field_name)
$(*database_code#entry_ID#field_name="label")
 ...
where entry_ID is the value that identifies uniquely the database entry, and field_name is any of the fields in that entry. You can simplify the way of accessing database symbols using the .defaultdb command.
Unless the no-connect mode is activated, all database symbols used in the document will be stored of file 'connect.def'. This file will be used to reprocess the document whenever other document modifies the values of those database symbols, if the connect mode is turned on.

The .savedb Command

.savedb database_code database_path
Allows to define database symbols that will be stored on file database_path. If by defining a database symbol you modify its previous value, all documents which use the database symbol will be automatically processed if the connect mode is activated. If the connect mode is turned off, htmlpp will issue a warning telling you to reprocess those 'connected' documents, what you should do if you don't want to have outdated information in your site.

The .defaultdb Command

.defaultdb database_code [field_name]
Simplifies the use of database symbols. If the only argument is database_code, whenever you define/use a database symbol without specifying the database code, database_code will be used. For example:
.defaultdb pages
$(#home#url)
is the same as
$(pages#home#url)
If you define both arguments, whenever you define/use a database symbol from database_code without specifying the field name, field_name will be used. For example:
.defaultdb pages url
$(pages#home#)
is the same as
$(pages#home#url)
You can combine both types:
.defaultdb pages
.defaultdb pages url
$(#home#)
is the same as
$(pages#home#url)

The .connect Command

.connect symbol name
Defines symbol name as a symbol whose value modifies crucially the HTML output from current document, so that different values of the symbol produce different HTML pages which use different database symbols. These symbols are tipically set with the -set command-line option. For example, the value of $(LANG) may produce output files in several languages. These symbols are used for connecting documents. If you use this command, htmlpp will consider as different the same document processed with different values of the symbol when storing connections in file 'connect.def' and when storing expire definitions in file 'expires.def', and will preset the value of the symbol when automatically processing the documents.
 

Htmlpp Macro Processing

Macros are a shorthand way to produce HTML tags and other constructs. This is how I define a macro 'H3':

.macro H3 <H3>$*</H3>

I use all uppercase names for macros, but this is just a convention, since the case is not important. We can use a macro like H3 in three ways:

.H2 some text

or

<!--.H2 some text-->

or

<.H2 some text>

The first form is good for titles and other constructs that come naturally on a line by themselves. Since it uses a syntax similar to htmlpp commands, there is a certain danger that a macro will conflict with some future command. This is just too bad; the alternative of inventing yet another syntax for macros was (for me) a worse choice. In any case, htmlpp will warn you if you try to define a macro that already exists as a command. The second form is compatible with HTML editors and some other HTML preprocessors, but is frankly a pain to type. The third form is good for mark-up tags. The second and third forms suffer from one problem: the whole thing has to come on a single line.

When you use a macro like this: <.H2 some text> you are supplying arguments. Here we supply two, 'some' and 'text'. You can refer to these as $1 and $2 inside the macro definition, or together as $*. Htmlpp can handle quotes correctly, so <.H2 "some text"> only supplies one argument, $1.

The $+ symbol expands to anything left over after $1, $2, etc. For instance, if you refer to $1 and $3 in the macro body, $+ refers to $4 and any remaining arguments.

The $# symbol expands to the number of macro arguments.

You can define a macro with a section that repeats for each argument. This is useful if you don't know in advance how many arguments you are going to have. For instance, the standard .THEAD macro generates a table heading for one, two, three, or more columns. You specify the repeating section as {...$n...}. The text between '{' and '}' is repeated for each argument; "$n" (dollar sign, small 'n') is replaced by the argument value.

To use multi-word arguments, enclose them in quotes.

When a macro refers to a variable using $(xxx), this will be expanded as soon as the macro is expanded. Usually this is what you expect, but sometimes you need the variable to be expanded in the next pass, for instance if you generate the .define in the same pass. In this case, escape the variable: $\(xxx).

The file macro.def that comes with htmlpp defines a set of standard macros. You can define multiline macros that include other commands, like .if and .include.

Multilingual support

Support For Accented Characters

You can type accented characters directly, and htmlpp will do its best to convert these into HTML metacharacters. For instance, if your document contains an e-circumflex, htmlpp will replace it by the metacharacter &ecirc;.

Supported character sets are ISO-8859-1 and MS-DOS (codepage 850). In general you can use ISO-8859-1 both for Unix Latin-1 and Windows 1250. You can define the character set through the -charset command-line option or let htmlpp do a little testing of the wind to figure-out if it's running under a Unix or a DOS system (Windows testing not supported). If you use htmlpp on a Mac, or on documents encoded using another character set it won't work. Basically htmlpp handles MS-DOS accents if there is an environment variable 'COMPSPEC' defined, and ISO-8859-1 accents if there is a file called "/etc/passwd" on the system.

If you use any character which is not on ISO-8859-1 or MS-DOS CP850 you will find that it comes-out as '?' (not found). If you have the HTML metachar for the character (which must be a Unicode numeric reference rather than an entity reference if it is outside ISO-8859-1) and the octal ASCII code for the character set you are using, please send it to me.

Dates Formatting

Days of the week and month names in date formatting functions can be written in several languages. Current supported languages are "es" for Spanish, "da" for Danish, and "fr" for French. If no language is specified in the formatting function the value of standard symbol $(LANG) is used, which is "en" by default if it has not been redefined.

Multilingual Variables

Htmlpp allows you to add two-character "extensions" to symbols to denote the language for the symbol value. This way you don't have to remember different symbol names for each alternative language you offer in your site. When you use the symbol you don't have to specify the language if it coincides with the current value of $(LANG). This feature only works when you activate the multiligual variable search option by defining $(USE_LANG) to 1. You can also use multilingual search with database symbols both for the database entry ID and the field name.
Example:
.define USE_LANG 1
.define home.en  "http://www.myserver.com/english/index.html"
.define home.es  "http://www.myserver.com/spanish/index.html"
.define home.fr  "http://www.myserver.com/french/index.html"
Now if you use the symbol $(home), htmlpp will
  1. Look for variable $(home).
  2. Because $(home) does not exist, look for $(home.$(LANG)).

If you want to make a link to a variable which is in a different language than the current one in $(LANG) you can use the full symbol name and Htmlpp will add for you the 'hreflang=xx' attribute:

.define $(LANG)  es
$(*home=Home) -->
     <A href="http://www.myserver.com/spanish/index.html">Home</A>
$(*home.es=Home) -->
     <A href="http://www.myserver.com/spanish/index.html">Home</A>
$(*home.en=Home) -->
     <A href="http://www.myserver.com/english/index.html"
     hreflang=en>Home</A>

Generating Several Language Versions from a Single Source File

You can use the following trick. Write your source file as:

.if ("$(LANG)" eq "en")

  [... version in english ...]

.endif
.if ("$(LANG)" eq "es")

  [... version in spanish ...]

.endif
.if ("$(LANG)" eq "fr")

  [... version in french ...]

.endif
Then to process each language invoke htmlpp as 'htmlpp -set LANG=xx filename'. You can also write a simple shell script to process the three languages at once by calling three times to Htmlpp.

Note that you must use '.connect symbol LANG' in the document for htmlpp to be clever and consider as different the same document processed with different values of the variable $(LANG). This is important both when using connections between documents and when verifying expired documents.  

Htmlpp Guru Mode

Recognising that a True Guru does not have time to painfully mark-up large HTML documents, htmlpp includes a basic text-to-HTML converter. You can invoke this as a preprocessing phase to the normal htmlpp process. Right now, this is an either-or choice; you either use htmlpp commands in a HTML document, or a text document and guru mode, but not a mixture of the two modes. (Release 3.1 of htmlpp tried to make this work, but that did not last long :\ )

You can, usefully, use htmlpp's guru mode to mark-up a document, then fine-tune it by hand.

To use guru mode, run htmlpp with the '-guru' option:

htmlpp -guru filename

Guru mode works by recognising layout, and converting this to HTML. I've tried to keep a balance between features and complexity, to give you something useful without becoming too formal (which is what HTML is for). Basically, guru mode relies on layout rules that also help to make the text readable in any case. For example, blank lines and indentation are significant in most places. One consequence of this is that the plain text file is very readable even before it is HTML'd (assuming you do your bit to help things.)

In guru mode, htmlpp reads an input text file (with any name and extension except '.hpp') and creates an output file with the same name and the extension '.hpp'. It then processes this file as it would any normal input file. The '.hpp' file remains afterwards, so you can use it as the basis for further refinement if wanted. (You should call it something else, to avoid embarrasing mistakes.)

Standard Guru Mode Definitions

The file 'guru.def' is always inserted at the start of the newly-created file. You can modify this file as wanted, to tune the results of guru mode. You cannot choose another name for this file other than by changing htmlpp's source code, which I don't recommend.

Htmlpp looks for a file called 'guru.fmt' which may exist and which may redefine the various HTML tags it uses. A file 'guru_opt.fmt' is supplied in the htmlpp distribution; rename or copy this to 'guru.fmt' and change any values you want to (I'd suggest you remove anything that does not change, just to make things clear). I've made it work in this way so that if you reinstall htmlpp, you don't loose your work.

Chapter and Section Headers

Htmlpp handles three levels of headers, H1, H2, and H3. In the text these look like this:

Chapter Header
**************

Section Header
==============

Subsection Header
-----------------

The line following the header text must start with 3 or more asterisks, equals, or hyphens. There is no way to specify H4 or other headers. I recommend that you start the document with a chapter header.

You can also request a horizontal rule (<HR>) by putting four or more dots on a line by themselves:

....

The header text line must come after a blank line, or at the start of the document.

Table of Contents

If your document contains at least two chapters, htmlpp will insert a table of contents before the second chapter header. This works best if the first chapter is empty or contains a brief text to introduce the document. Htmlpp inserts the table of contents by adding a section header called 'Table of Contents', and then a line '.include contents.def', in the normal manner. You should not call the first chapter 'Table of Contents'.

Pagination

Htmlpp inserts a '.page' command before each chapter header. Therefore, use chapter headers wisely to break the document into usable pages.

Page Headers and Footers

The guru.def file normally includes 'prelude.def', which defines page headers and footers for the document. You will normally tune these for any project -- the supplied files contain references to iMatix URLs that may not be appropriate for your work. I like to use the same headers and footers (the same prelude.def) for all the files in a project, including those I that use guru mode.

Paragraphs

A paragraph is anything following a blank line that does not look like something else. Basically, any plain text following a blank line is given a <P> tag. Note however the exceptions that follow...

Preformatted Text

If a line is indented by 4 or more spaces, or a tab, htmlpp treats the line as 'preformatted' text and inserts a <PRE> tag. You can mix blank lines with preformatted text.

Bulleted and Numbered Lists

A paragraph starting with a hyphen and a space is considered to be a bulleted list item. A paragraph starting with a digit and a dot and optionally a space is considered to be a numbered list item. You can put blank lines between list items, but it's not necessary. Cosmetically, when list items are short, blank lines are disturbing. But when list items are several lines, blank lines make the text more readable. Either way, htmlpp is happy.

Definition Lists

A definition list is a line ending in ':' followed by some lines indented by one or more spaces. For example:

Definition:
 Explanation of definition.

You can put blank lines between definition items, but again, it's a matter of cosmetics. There should be a blank line before the first definition item, however.

Tables

Tables are one of the real pains of HTML markup, in my opinion. Here htmlpp tries to solve the most common case; a two-column table consisting of a term or value in one column, and an explanation in the second column.

A table can start with a header, which is a line like this:

Some column:  Followed by some explanation:

Here, the colons (':') are important. Htmlpp also wants a capital letter at the start of both phrases, and a space after the first colon. The table header is optional; you can start immediately with table items. Either way, htmlpp needs a blank line before the table. A table item looks like this:

Some_word:    Followed by some explanation
               which can come on several lines.

The first column must be a single word - if you want several words, use underlines. Htmlpp replaces these by spaces. The explanation can come on several lines, which must be indented by one or more spaces.

Figures and Images

To insert a figure, use one of these conventions:

[Figure filename: caption]
[Figure "filename": caption]

Htmlpp inserts a figure caption, numbering the figures in a document from 1 upwards. The caption is followed by an <IMG> tag to display the file. You can use a URI (a path) as the filename, or an URL (with a host name specifier); you must put an URL in quotes. My preference is to put image files locally with the HTML files, and use a simple filename without a path. This is just easier to manage and lets you put the HTML files plus images in any directory. If htmlpp can find the image you specify, and it's a .GIF or .JPG file, it will insert the WIDTH= and HEIGHT= tags automatically.

To insert a plain image, omit the 'Figure' keyword. For example, these are all examples of valid images:

[Figure somefile.gif: caption]
[somefile.gif: caption]
[Figure somefile.gif]
[somefile.gif]

Hyperlinks

If you use <[email protected]>, this is converted into a mailto: URL hyperlink. If you use <http://address/document> -- or any other URL -- this is converted into a hyperlink as well. You can follow the URL by ':description' if you like, e.g. <http://www.imatix.com:iMatix Corporation's Site>. You can also refer to local files using the syntax </localfile[:description]>.

Htmlpp does not presently allow links within the document or to other documents.

Special Characters

Since you're not typing HTML, htmlpp replaces <, > and & by HTML metacharacters. < and > are used to indicate hyperlinks.  

Htmlpp Intrinsic Functions

Htmlpp provides a number of intrinsic functions that you can use in your text. The syntax for using an intrinsic function is:

&function-name(arguments)
This function: Does this:
&The &date Function("picture", date) Format specified date using picture
&The &date Function("picture", date, lc) Format specified date using picture and language code.
&The &date Function("picture") Format current date using picture
&The &date Function() Return current date value
&The &time Function() Format current time as hh:mm:ss
&The &week_day Function([date]) Get day of week, 0=Sunday, 6=Saturday
&The &year_week Function([date]) Get week of year, 1 is first full we
&The &julian_date Function([date]) Get Julian date for date
&The &lillian_date Function([date]) Get Lillian date for date
&The &date_to_days Function(date) Convert yyyymmdd to Lillian date
&The &days_to_date Function(days) Convert Lillian date to yyyymmdd
&The &future_date Function(days,[date]) Calculate future date
&The &past_date Function(days,[date]) Calculate past date
&The &date_diff Function(date1,date2) Calculate differences between dates
&The &image_height Function("image.ext")Get image height (GIF, JPEG)
&The &image_width Function("image.ext") Get image width (GIF, JPEG)
&The &file_size Function("filename",arg)Get size of file: optional arg K or M
&The &file_date Function("filename") Get date of file
&The &file_time Function("filename") Get time of file as hh:mm:ss
&The &normalise Function("filename") Normalise filename to UNIX format
&The &system Function("command") Get result of some system utility
&The &upper Function("string") Convert string to uppercase text
&The &lower Function("string") Convert string to lowercase text
&The &pageref Function("page","title") Build link for page index
&The &relpath Function(["from"],"to") Get relative path from->to
 

The &date Function

Syntax:

&date(picture, value)
&date(picture, value, language)
&date(picture)
&date()

Without a picture, returns the current date. With a picture, formats the current date according to a picture that you specify. You can optionally supply a date value in the standard 8-digit format; YYYYMMDD (as returned by &date()), or use 0 to indicate today's date. You can optionally follow the picture and value by a language code; the values currently accepted are "es" for Spanish, "fr" for French, and "da" for Danish. Anything else is taken to mean English. If no language is specified, $(LANG) is used by default. The picture can consist of any mixture of these elements:
cc century 2 digits, 01-99
y day of year, 1-366
yy year 2 digits, 00-99
yyyy year 4 digits, 100-9999
m month, 1-12
mm month, 01-12
mmm month, 3 letters
mmmm month, full name
MMM month, 3 letters, ucase
MMMM month, full name, ucase
d day, 1-31
dd day, 01-31
ddd day of week, Sun-Sat
dddd day of week, Sunday-Saturday
DDD day of week, SUN-SAT
DDDD day of week, SUNDAY-SATURDAY
w day of week, 1-7 (1=Sunday)
ww week of year, 1-53
q year quarter, 1-4
\x literal character x
otherliteral character

Examples:

.echo &date()             --> Nov 13, 99
.echo &date('mm d, yy')   --> Dec 2, 98
.echo &date('d mmm, yy')  --> 2 Dec, 98
.echo &date("yymd")       --> 9812 2
.echo &date("yyyymmdd")   --> 19981202
.echo &date("d \de mmmm \de yyyy", 0, "es")  --> today's date in Spanish
 

The &time Function

Syntax:

&time()

Formats the current time in the same way as the $(TIME) symbol. The difference is that $(TIME) is set when htmlpp starts working; &time() reflects the current time.  

The &week_day Function

Syntax:

&week_day()
&week_day(date)

Returns the day of the week for the specified date, or for the current date if no argument is given. Day 0 is Sunday; day 6 is Saturday.  

The &year_week Function

Syntax:

&year_week()
&year_week(date)

Returns the week of the year for the specified date, or for the current date if no argument is given. Week 1 is the first full week, starting with a Sunday.  

The &julian_date Function

Syntax:

&julian_date()
&julian_date(date)

Returns the Julian date for the specified date, or for the current date if no argument is given. Day 1 is January 1.  

The &lillian_date Function

Syntax:

&lillian_date()
&lillian_date(date)

Returns the Lillian date for the specified date, or for the current date if no argument is given. This is the number of days since a starting (but unspecified) epoch (which in fact is around 1582).  

The &date_to_days Function

Syntax:

&date_to_days(date)

Returns the Lillian date for the specified date. This function is really a the same as &lillian_date() except that you must supply a date argument. It's provided for orthogonality with &days_to_date().  

The &days_to_date Function

Syntax:

&days_to_date(days)

Converts a Lillian date back into a normal date in the form yyyymmdd. You can use this function (in combination with the reverse function, &date_to_days()) to calculate past and future dates.  

The &future_date Function

Syntax:

&future_date(days)
&future_date(days,date)

Calculates a date at some point in the future. For instance, 19991217 will produce tomorrow's date. If the date argument is not provided, calculates from today.  

The &past_date Function

Syntax:

&past_date(days)
&past_date(days,date)

Calculates a date at some point in the past. For instance, 19991215 will produce yesterday's date. If the date argument is not provided, calculates from today.  

The &date_diff Function

Syntax:

&date_diff(date)
&date_diff(date1,date2)

Calculates the difference between two dates, in days. The calculation is date1 - date2. If date2 is not supplied, calculates using today, and will therefore return a positive value if date is in the future, and a negative value if date is in the past.  

The &image_width Function

Syntax:

&image_width(filename)

Returns the width of the specified image, which can be a GIF or JPEG file, in any of the common formats (including progressive encoding). The width is returned in pixels.  

The &image_height Function

Syntax:

&image_height(filename)

Returns the height of the specified image, which can be a GIF or JPEG file, in any of the common formats (including progressive encoding). The height is returned in pixels.  

The &file_size Function

Syntax:

&file_size(filename)
&file_size(filename, K)
&file_size(filename, M)

Returns the size of the specified file. If the second argument is K or M, calculates the size in Kb or Mb as appropriate. Always returns an integer value.  

The &file_date Function

Syntax:

&file_date(filename)

Returns the date of the specified file, as an 8-digit value, YYYYMMDD.  

The &file_time Function

Syntax:

&file_time(filename)

Returns the time of the specified file, as a string, HH:MM:SS.  

The &normalise Function

Syntax:

&normalise(filepath)

Returns the filepath in a UNIX-style format. You can use this, for instance, under MS-DOS, when filenames taken from (e.g.) the environment contain back slashes which can cause problems. Replaces \ by / and spaces by underlines.  

The &system Function

Syntax:

&system(string)

Returns the result of some system utility. For instance:

.define SERVER  http://&system("hostname")
 

The &upper Function

Syntax:

&upper(string)

Returns the string in uppercase letters.  

The &lower Function

Syntax:

&lower(string)

Returns the string in lowercase letters.  

The &pageref Function

Syntax:

&pageref("page","title")
Does the same as this htmlpp code: .if "name" eq "docs/develop.html" title .else <A HREF="page">title</A> .endif

This function strips-off any HTML tags that you put around the title text when it uses it to build a link. So, you can do this kind of thing, which I often use to build an index in the page footer: .block index_entry &pageref("$(INDEX_PAGE)","<EM>$(INDEX_TITLE)</EM>") .endblock  

The &relpath Function

Syntax:

&relpath(["from"], "to")

Returns the relative path from 'from' to 'to'. If only one argument is specified, the current HTML page is used as 'from'. For example:

&relpath("john/peter/david/me.html","john/henry/you.html")
would return "../../henry/you.html". You can use this to create a web site with pure relative references to other pages. Remember that you don't need to use this function with $(*name) links if $(USE_RELPATH) is set to 1. Note that if you use relative references you can test and use the HTML pages on a local hard disk as well as on the server without changes.

Multipass Processing

Since version 2.00, htmlpp uses a multipass technique to allow embedded blocks. For example, you can place .include actions in the header or footer blocks, or define your own blocks that have .define, .page, and other actions.

Htmlpp handles this using the following rules:

  1. .include actions are executed immediately.
  2. .block actions are executed immediately.
  3. .build actions are executed as soon as possible after the first pass. This allows htmlpp time to collect the document titles, which it needs to build the table of contents.
  4. .if ... .else ... .endif actions are handled at once.
  5. .page commands are handled in two stages; headers and footers are built in the second pass, and individual page files are built during the last pass.
  6. Htmlpp will process the document (actually a temporary copy) as many times as necessary, until all actions have been processed.

One consequence of this is that htmlpp needs a minimum of 3 passes to fully process a document, one to collect all the titles; one to insert page headers and footers, and a last one to break the text into individual pages. If any genius can help me reduce this to two (or one!) pass, go ahead.

The upside is that you can do really funky stuff in headers and footers: for instance, the htmlpp pages build a document index in the footer, switching hyperlinks on and off to indicate the current page in the index.

Multipass Debugging

To see what htmlpp is doing with its passes, use the -debug option, like this:

htmlpp -debug filename
This leaves a number of .wrk files lying around; these contain the result of each pass.

Other Things to Know

  • If you end a line with '\', it will be output to the final HTML file without a trailing newline (and without the '\').
iMatix
 
Copyright © 1996-99 iMatix Corporation.
Hosted by OpenAvenue.com. Made with Htmlpp. Powered by Xitami.
 
Updated: October 20, 1999
Feedback