Re: [Twisted-web] [Nevow] how to generate XHMTL without whitespaces
At 04:56 PM 9/26/2006, you wrote:
Phil Mayers ha scritto:
Manlio Perillo wrote:
this template:
<label>label: <select name="a_name" n:render="sequence" n:data="a_list"> <option n:pattern="item"> <n:invisible n:render="string" n:data="0" /> <n:attr name="label" n:render="string" n:data="1" /> </option> </select> </label>
gives a:
<label>label: <select name="a_name"><option label="a_label">
1
</option><option label="another_label">
Erm - yes. Because your template has whitespace in it. Remove it and it should work - that is:
<label>label:<select name="a_name" n:render="sequence" n:data="a_list"><option n:pattern="item">...
Ok, but I would like to have a readable template... This is the reason why I'm asking if it is possible to remove extra
Maybe do a simple regex cleanup before you use the template. Something like the following, which removes whitespace between
and <, if the whitespace begins with a newline:
import re ... RE_removeFreeWhitespace = re.compile( r'>[\n\r]+\s*<' ) def removeFreeWhitespace( S ): return RE_removeFreeWhitespace.sub( r'><', S ) ... templateString = removeFreeWhitespace( templateString ) - Sam
Also, only *some* of the whitespace is significant. The whitespace inside <> is not. That leaves open the possibility of something like this: <foo bar="1">< baz bam="2' />< /foo> Which at least has the virtue of wrapping ln less than 80 columns. I frequently format things this way, but I'm sure not everyone will agree that that is more readable. C On 9/27/06, Samuel Reynolds <sam@spinwardstars.com> wrote:
At 04:56 PM 9/26/2006, you wrote:
Phil Mayers ha scritto:
Manlio Perillo wrote:
this template:
<label>label: <select name="a_name" n:render="sequence" n:data="a_list"> <option n:pattern="item"> <n:invisible n:render="string" n:data="0" /> <n:attr name="label" n:render="string" n:data="1" /> </option> </select> </label>
gives a:
<label>label: <select name="a_name"><option label="a_label">
1
</option><option label="another_label">
Erm - yes. Because your template has whitespace in it. Remove it and it should work - that is:
<label>label:<select name="a_name" n:render="sequence" n:data="a_list"><option n:pattern="item">...
Ok, but I would like to have a readable template... This is the reason why I'm asking if it is possible to remove extra
Maybe do a simple regex cleanup before you use the template. Something like the following, which removes whitespace between
and <, if the whitespace begins with a newline:
import re ... RE_removeFreeWhitespace = re.compile( r'>[\n\r]+\s*<' ) def removeFreeWhitespace( S ): return RE_removeFreeWhitespace.sub( r'><', S ) ... templateString = removeFreeWhitespace( templateString )
- Sam
_______________________________________________ Twisted-web mailing list Twisted-web@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
participants (2)
-
Cory Dodt
-
Samuel Reynolds