Ian Bicking wrote:
> Are there any opinions on the best HTML/XML generation libraries out there?
>
> For example, HTMLGen being the original (but too eclectic). Stan is
> often also sited (http://divmod.org/projects/nevow#stan). I have an
> extension of ElementTree along these lines in FormEncode
> (http://svn.formencode.org/FormEncode/trunk/formencode/htmlgen.py). I
> noticed http://markup.sourceforge.net/ today, which allows you to open a
> tag and close it later, which can be nice.
>
> I'd like to put a Best Possible library in WebHelpers
> (http://pylonshq.com/WebHelpers/), that's both simple and easy to work
> with. I would be nice if the same API could be used to generate both
> ElementTree nodes and strings; ElementTree itself can be a little picky,
> so *only* using ElementTree as the internal/intermediate representation
> (like formencode.htmlgen does) might be going too far. HTML/XHTML
> validation might be interesting. Smart indentation would be nice, at
> least optionally (i.e., indentation, but nothing that breaks the layout).
>
> While the library would ideally have some (optional) knowledge of HTML,
> it would be out of scope to have it be a general page-builder (like
> HTMLGen, and a bit like markup.sf.net). I'm more interested in just
> using it to build fragments.
>
> Opinions?
>
This is my humble offering:
http://gflanagan.net/site/python/htmlbuilder/htmlbuilder.py
It uses the SimpleXmlWriter from the ElementTree package, but doesn't
use Elements as such. A simple utility that suits my needs.
('css', 'cssClass', 'class_', or 'klass' can be used)
Gerard
eg. usage:
-------------------------------------------------------------------------
from myutils.htmlbuilder import HtmlBuilder
html = HtmlBuilder( doctype='strict')
page = html.page('The Website at The End of The Universe')
page.comment('Begin Header')
page.template('HEADER')
page.comment('Begin Content')
page.template('CONTENT')
page.comment('Begin Footer')
page.template('FOOTER')
header = html.include(
'C:\\DEVELOPMENT\\python\\htmlbuilder\\test\\header.html' )
header.script('')
content = html.div(id='content', css='main')
content.h3('Welcome ').template('USER').literal('!!')
links = content.ul(css='navbar')
links.li.a( 'Home', href='/home.html' )
links.li.a( 'Find Page', href='/FindPage.html' )
links.li.a( 'Recent Changes', href='/RecentChanges.html' )
footer = html.div(id='footer')
footer.cheetah('Cheetah says the date is $DATE')
content %= [{ 'USER': 'Arthur Dent' }]
footer %= [{ 'DATE': '10/3/06' }]
page %= [{ 'HEADER': header, 'CONTENT': content, 'FOOTER': footer
}]
print
print page
---------------------------------------------------------------------------------------------
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/pylons-discuss
-~----------~----~----~----~------~----~------~--~---