Format of HTML Source Output

Christopher Browne cbbrowne at
Sat Apr 1 06:53:47 CEST 2000

Centuries ago, Nostradamus foresaw a time when Joseph C. Kopec would say:
>I have been sucessfully using Python cgi scripts to generate HTML
>pages.  When I use a text editor to pull up the HTML source, however,
>all the source is on one or a few lines, making it difficult to review. 
>Are there any techniques people typically use with Python cgi scripts to
>produce HTML output that not only is good HTML when viewed through a
>browser, but produces nicely formatted HTML source?  Would outputting \n
>and other escaped characters work without disrupting the browser-viewed
>HTML document?  Thanks in advance.

Yes, it would make a Whole Lot Of Sense to insert \n here and there.

An (admittedly extreme) option would be to open a pipe to Dave
Raggett's "tidy" utility, and transform the output into not merely
line-broken HTML, but possibly even Well-Styled HTML.

That obviously comes at some cost, and you may be reluctant to pay the
cost "in production."  

On the other hand, it would be Tremendously Valuable to run the output
through a filter in development that would do some degree of
validation, perhaps providing you with feedback concerning the use of
pathologically horrid HTML constructs.  To which end "tidy" would be
*rather* a useful option, as it does quite a lot of validation.

Resulting approach:

--> Whilst developing, drop output to a stream that forwards the data
    through "tidy," and which perhaps logs the file as well, so that
    you can see exactly what was produced.

--> When deploying, you might want to use a Different Transformation
    Stream that takes out redundant stuff so that outsiders might get
    smaller, faster-to-transfer documents.
SIGTHTBABW: a signal sent from Unix to its programmers at random
intervals to make them remember that There Has To Be A Better Way.
-- Erik Naggum
cbbrowne at <>

More information about the Python-list mailing list