mako strips first line in templates if it starts with single #

42 views
Skip to first unread message

xrot...@googlemail.com

unread,
Apr 11, 2013, 8:39:33 AM4/11/13
to mako-d...@googlegroups.com
Hi group,
I think I found a bug in mako (just confirmed with mako 0.8 as well):
When the first line in a template starts with '#' (not '##'!), the line will be stripped from the rendered output (see below).
I encountered this behaviour when trying to add a
# coding=utf8
line to script.py.mako in an alembic configuration.

Python 2.7.3 (default, Aug  1 2012, 05:14:39)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from mako.template import Template
>>> t = Template('# coding=utf8\n"""\nstuff\n"""')
>>> t.render()
u'"""\nstuff\n"""'
>>> t = Template('\n# coding=utf8\n"""\nstuff\n"""')
>>> t.render()
u'\n# coding=utf8\n"""\nstuff\n"""'

best
robert

Michael Bayer

unread,
Apr 11, 2013, 9:58:05 AM4/11/13
to mako-d...@googlegroups.com
yeah that's actually by design, we support being able to put the "## coding" directive directly in a template to specify the template's encoding, but as you note, it does it for "#" as well - which is because in the early days, we used "#" for comments, not "##", and in the case of the coding directive we left the old behavior in place.
Anyway, you can always subvert mako's lexer using the <%text> tag:

"""<%text># coding: utf-8</%text>

stuff

"""




--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages