[mod_python] [ANN] markup.py - 1.1 - an HTML/XML generator

Daniel Nogradi nogradi at gmail.com
Sun Mar 26 21:00:35 EST 2006


The 1.1 release of markup.py -- an intuitive, light-weight,
customizable and pythonic HTML/XML generator -- is available together
with documentation at

http://markup.sourceforge.net

The emphasis is on being light-weight; markup.py is not a web
framework or full blown templating engine or parser, it is actually a
single file with only three classes plus exceptions. And its only
purpose in life is to generate HTML/XML without cluttering your Python
code with tags.

The code is in the public domain.

Example:

import markup

    items = ( "Item one", "Item two", "Item three", "Item four" )
    paras = ( "This was a fantastic list.", "And now for something
completely different." )

    page = markup.page( )
    page.init( title="My title",
               css=( 'one.css', 'two.css' ),
               header="Something at the top",
               footer="The bitter end." )

    page.ul.open( klass='mylist' )
    page.li( items, klass='myitem' )
    page.ul.close( )

    page.p( paras )
    page.img( width=100, height=300, alt="Check this out", src="myfile.jpg" )

    print page

the above will output

        <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>
        <html lang='en'>
        <head>
        <link href='one.css' type='text/css' rel='stylesheet' />
        <link href='two.css' type='text/css' rel='stylesheet' />
        <title>My title</title>
        </head>
        <body>
        Something at the top
        <ul class='mylist'>
        <li class='myitem'>Item one</li>
        <li class='myitem'>Item two</li>
        <li class='myitem'>Item three</li>
        <li class='myitem'>Item four</li>
        </ul>
        <p>This was a fantastic list.</p>
        <p>And now for something completely different.</p>
        <img src='myfile.jpg' alt='Check this out' height='300' width='100' />
        The bitter end.
        </body>
        </html>



More information about the Mod_python mailing list