PyHTML -- Indentation-structured HTML generator

Jeff Epler jepler at inetnebr.com
Thu Dec 7 15:09:43 CET 2000


PyHTML -- Indentation-structured HTML generator with all the power of Python
					    Jeff Epler <jepler at inetnebr.com>
							     6 December 2000

PyHTML is an extension of the Python grammar, plus a modified compiler
which permits the use of HTML-style tags as Python blocks, making it easy
to write HTML document generators with the block-indentation style of Python.

This is a rough-cut version of pyhtml, intended to get a reaction from
the Python community.  Please let me know your thoughts, either in the
comp.lang.python newsgroup or via direct mail.  See INSTALL for instructions
on getting PyHTML running.

Thanks to the authors of Quixote: A.M. Kuchling, Neil Schemenauer,
and Greg Ward for both the inspiration of an augmented Python language
for HTML generation and for some of the code in that fine package.

Thanks to everyone who has been involved with the development of Python.

You can download pyhtml or browse its source at
	http://incolor.inetnebr.com/jepler/pyhtml/

Example:
#---- cut here for example1.pyh ----
# This program writes out the lines in README in preformatted HTML,
# calling the htmlesc() function to prevent interpretation of any
# special characters, such as <, >, and &.
from htmlesc import htmlesc

<HTML>
  <HEAD>
    <TITLE> "PyHTML Makes It Easy"
  <BODY>
    <PRE>
      for i in open("README").readlines():
        htmlesc(i)
print str(__output) # Current cruft necessary to see output
#---- example1.pyh ends ----

Syntax:
compound_stmt: ... | tag_stmt
tag_stmt: '<' NAME [tag_args] '>' suite
tag_args: NAME '=' expr (',' NAME '=' expr)* [',']

How it works:
The C parser for Python is modified to include a "tag statement" which is
valid in all the same places as a for statement (compound_stmt).  The builtin
modules symbol and ast are extended to be able to understand these nodes.
The compiler is extended to emit code both for the tags (my work) and for
expression-statements (Taken from Quixote) to write output to a special object.
The following code:
	<UL>
		for i in range(10):
		<LI> str(i)
would output something like
<UL><LI>0</LI><LI>2</LI>....<LI>9</LI></UL>





More information about the Python-list mailing list