On Wed, Feb 3, 2010 at 5:31 PM, Akademy <[email protected]> wrote:
> Hi. > > I like to have whitespace (newlines, spaces, etc) in my template to > seperate html and web.py code, but this white space, specifically new > lines, also outputs to html. This is mostly just annoying but > occasionaly causes a problem as below: > > I have a template that starts thus: > $def with (search="", tabs_list="", people="", dept="", funder="", > pub="", ra="", numFound="") > > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "xhtml1- > transitional.dtd"> > <html xmlns="http://www.w3.org/1999/xhtml"> > <head> > ...etc... > > The problem here is that the newline after the initial $def gets > output to the html but the html specification states that the !DOCTYPE > must be on the first line. I'd be happy to add a comment mark at the > start of this line (as below) but this also causes the newline to be > output. > $def with (search="", tabs_list="", people="", dept="", funder="", > pub="", ra="", numFound="") > $# > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "xhtml1- > transitional.dtd"> > > Is there a way to supress this line somehow? (I also tried adding the > '\' character but I guess it just assumes this is part of the comment) > Why don't you strip the output? Here is a hack for doing it seamlessly. Class StripRender: def __init__(self, render): self.render = render def __getattr__(self, name): return StripRender(getattr(self.render, name)) def __call__(self, *a, **kw): out = self.render(*a, **kw) return web.safestr(out).strip() render = StripRender(render) -- You received this message because you are subscribed to the Google Groups "web.py" 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/webpy?hl=en.
