[Twisted-Python] Woven-generated html needs newlines and whitespace

Donovan Preston dp at twistedmatrix.com
Thu Jun 5 13:33:04 EDT 2003


On Thursday, June 5, 2003, at 09:46 AM, Patrick K. O'Brien wrote:

> I'm still learning Woven, but I noticed that the html files generated 
> by the
> example programs are mostly devoid of newlines and other whitespace, 
> making
> the html pretty hard to read.  Is there an easy way to enable 
> newlines?  I
> see hints in microdom, but don't understand it well enough yet.

Indeed -- the ugly state of woven's output is something that irritates 
me quite a bit. My current solution is to copy and paste the output 
into BBEdit, and use the Formatting command, but that's only an option 
if you are on Mac OS X.

> Here is a specific example - the calendar example listed in the docs:
>
> http://www.twistedmatrix.com/documents/howto/viewindepth#auto4
>
> I typed in that example and ran it.  The html it generated could 
> really use
> some well-placed newlines.  Indentation wouldn't hurt either.  How 
> would I
> modify that example to add newlines and indentation to the html?

There is a reason the output looks like that, specifically buggy 
browsers. Browsers claim to be whitespace agnostic but appear to format 
certain things, such as tables with images in the cells, differently if 
there is any whitespace in the cell. This was the reason I was told 
woven couldn't output pretty-printed xml; I have not been able to 
reproduce this behavior however. Can someone who has experienced this 
problem (mesozoic, glyph?) please email me an example of the 
problematic HTML?

Anyway, here is a quick fix to the problem:

Edit twisted/web/woven/utils.py

Change this line in doSendPage:

     page = str(d.toxml())

to this:

     page = str(d.toprettyxml())

And if it doesn't cause any problems for you WRT the formatting of your 
pages in the browser, then you should be happy.

I think that I am going to add an option to Page which will allow you 
to turn on and off prettyprinting on a per-page basis. Another thing 
for my todo-in-my-sparetime list :(

dp





More information about the Twisted-Python mailing list