PyHTML -- Indentation-structured HTML generator
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
#---- 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
<TITLE> "PyHTML Makes It Easy"
for i in open("README").readlines():
print str(__output) # Current cruft necessary to see output
#---- example1.pyh ends ----
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:
for i in range(10):
would output something like
More information about the Python-list