[ANNOUNCE] PyHTML 0.5 -- Indentation-structured HTML generator

Jeff Epler jepler at inetnebr.com
Mon Dec 11 08:30:35 EST 2000


PyHTML Indentation-structured HTML generator with all the power of Python
                                   Version 0.5, released 10 December 2000
					 Jeff Epler <jepler at inetnebr.com>


PyHTML is an extension of the Python grammar, plus a modified compiler
which permits the use of HTML-style tags as Python blocks, and which makes
these tags and expression-statements write their values as output, 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.  As updated versions
become available, they will be placed at
	http://incolor.inetnebr.com/jepler/pyhtml/

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 the author of SPARK, John Aycock.  His parser toolkit and Python
grammar relieved me of the need to modify core Python to parse pyhtml's
extended syntax.  (However, making SPARK emit asts that could be understood
by the compiler was still a bit of work!  And it still speaks only the
Python 1.5 dialect)

Thanks to everyone who has been involved with the development of Python,
it's the most pleasant language I work in.


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 &.
#
# execute as follows:
#   python pyhtml.py example1.pyh > example1.html
# and then load example1.html in your browser
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 ----

History:
0.5  10 December, 2000
  SPARK version of Python grammar (Python 1.5 subset) completed and
  included.
  PyHTML requires no modifications to the core Python grammar, and
  all external code is included (from SPARK, Quixote, and Tools/compiler) 

0.1  6 December, 2000
  First version publicly released

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

How it works:
The grammar for Python is modified to include a "tag statement" which is
valid in all the same places as a 'for' statement (compound_stmt).  
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