[Zope-dev] HTML rendering
Toby Dickenson
tdickenson@geminidataloggers.com
Wed, 8 Dec 1999 07:07:09 -0000
Arrange for the module below to be imported, and you have an extra tag that
does what you want. It removes spaces very agressively, possibly in some
places that it shouldnt. Use it in dtml as:
<dtml-unitws>Kill these spaces</dtml-unitws>
from string import split, strip, join
import DocumentTemplate.DT_Util
from DocumentTemplate.DT_String import String
class UnitWhitespaceTag:
"""
Removes redundant whitespace (not very conservatively)
"""
name='unitws'
blockContinuations=()
def __init__(self, blocks):
tname, args, section = blocks[0]
args = DocumentTemplate.DT_Util.parse_params(args)
self.blocks = section.blocks
def render(self,md):
a = []
for line in
split(DocumentTemplate.DT_Util.render_blocks(self.blocks, md),'\n'):
line = strip(line)
if line:
b = []
for word in split(line,' '):
b.append(strip(word))
a.append(join(b,' '))
return join(a,'\n')
__call__=render
String.commands['unitws']=UnitWhitespaceTag