<%namespace name="conf_general" module="conf.general" inheritable="True"/>
<%namespace name="entries_index" module="content.entries_index"/>
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
...
</channel>
</rss>
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
...
</channel>
</rss>
Note
the whitespace in the head of the document. Usually with HTML it
doesn't really matter, but with RSS (And some other XML things) it does
matter.<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<%namespace name="conf_general" module="conf.general" inheritable="True"/>
<%namespace name="entries_index" module="content.entries_index"/>
<channel>
...
</channel>
</rss>
On Nov 25, 2014, at 11:25 AM, realcr <rea...@gmail.com> wrote:Hi,
I have an issue with whitespace added by Mako. I was wondering what could be done about it, and if I want to contribute, where should I begin.
Let me show demonstrate the issue.
I have this template:<%namespace name="conf_general" module="conf.general" inheritable="True"/>
<%namespace name="entries_index" module="content.entries_index"/>
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
...
</channel>
</rss>
Which is a template for generating RSS feeds.
It turns out that the output is something like this:
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
...
</channel>
</rss>
<%namespace name="conf_general" module="conf.general" inheritable="True”/>\n
<%namespace name="entries_index" module="content.entries_index”/>\n
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
...
</channel>
</rss>
<%namespace name="conf_general" module="conf.general" inheritable="True”/>\
<%namespace name="entries_index" module="content.entries_index”/>\
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
...
</channel>
</rss>
Note the whitespace in the head of the document. Usually with HTML it doesn't really matter, but with RSS (And some other XML things) it does matter.
In fact, this RSS is considered to be invalid. It will not work in Firefox, for example.
I wonder if there is a simple solution to this problem.
One workaround I use myself is doing this:
<?xml version="1.0" encoding="UTF-8" ?>
<%namespace name="conf_general" module="conf.general" inheritable="True"/>
<rss version="2.0">
<%namespace name="entries_index" module="content.entries_index"/>
<channel>
...
</channel>
</rss>
What do you think?
Regards,
real.
--
You received this message because you are subscribed to the Google Groups "Mako Templates for Python" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mako-discuss...@googlegroups.com.
To post to this group, send email to mako-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/mako-discuss.
For more options, visit https://groups.google.com/d/optout.
On Nov 25, 2014, at 11:34 AM, Michael Bayer <mik...@zzzcomputing.com> wrote:here is a demo:classics-MacBook-Pro-2:mako classic$ cat test.pyfrom mako.template import Templatet = Template("""\<%namespace name="conf_general" module="conf.general" inheritable="True"/>\<%namespace name="entries_index" module="content.entries_index"/>\<?xml version="1.0" encoding="UTF-8" ?><rss version="2.0"><channel>...</channel></rss>""")print t.render()classics-MacBook-Pro-2:mako classic$ python test.py<?xml version="1.0" encoding="UTF-8" ?><rss version="2.0"><channel>...</channel></rss>
On Nov 27, 2014, at 7:27 AM, realcr <rea...@gmail.com> wrote:Hi Michael,
Thank you for your response. It does solve my problem. I will use it with my templates.I have to add some questions about the design though. Please don't take them as some kind of criticism. I use Mako for
a few static websites I own, and it made my life much easier. I just want to understand some choices that were made.
First regarding the whitespaces. I had an idea that every % based tag will automatically remove the new line that comes after it.
Are there cases where this is expected to cause problems?
In the first few times I used Mako I was really surprised to see that there lots of whitespace in my templates.
It's like people
get some kind of metadata about how much code was inside my template originally when they view the source in the browser.
Second, about the backslash. I find it very reasonable that the backslash will escape new lines inside <% > constructs.
I even find it more reasonable that the backslash will escape new lines inside python code (This is the way python works).
However it always surprises me that the backslash works outside of those constructs too.
It happened to me more than once that I had to use
the <%text> tag to be able to show some example code (In python for example). I find it unexpected that Mako's engine interferes with content
that I put outside of Mako blocks and tags.
Are there any special use cases for this behaviour, besides dealing withthe whitespaces problem?
Here is an example from a static website engine I wrote. I have to admit that it uses Mako in a bit of twisted way,
but maybe it still serves my point. It shows an example blog post, where I want to present some bash code,
but I have to wrap it inside <%text>:
https://github.com/xorpd/static_weber/blob/master/content/blog/vim_python3_install.mako