Re: Can't Insert A Single Hash Character

Fred Ludlow <[email protected]> Tue, 15 Sep 2015 15:18:37 +0100
Newsgroups gmane.comp.python.cheetah
Message-ID <CAAgz+WLxYUa1cb+jRM2fU94zzDSf9WQ-pFEwosPqAweYd583DA@mail.gmail.com>
--===============1133366668773191022==
Content-Type: multipart/alternative; boundary=089e0141aa22ceec74051fc9dc5b

--089e0141aa22ceec74051fc9dc5b
Content-Type: text/plain; charset=UTF-8

Section 5 of the user guide says:
"Placeholders and directives can be escaped by putting a backslash before
them. \$var and \#if will be output as literal text"
But obviously just putting \# doesn't work (see OP)

This does work:
s = """a
\##

b
"""
print Template(s)
a
#
b

i.e. \## and an extra  blank line

However, I'm guessing this isn't intended behaviour, so maybe don't rely on
it!

I've not looked at the source and don't know how Cheetah does it's parsing
but I wonder if it's something to do with the precedence of one-line #if
then else# statements, ##comments and escaped \#directives? That might be a
red herring...

Fred


On 14 September 2015 at 20:59, Williams, James P2 <
[email protected]> wrote:
>
> > If you want just the hash use the #raw function
>
> >
>
> > #raw
>
> > #
>
> > #end raw
>
> >
>
> > you'll get your hash this way.
>
>
>
> Excellent.  I had forgotten about #raw.  Thanks.
>
>
>
> Jim
>
>
>
>
>
------------------------------------------------------------------------------
>
> _______________________________________________
> Cheetahtemplate-discuss mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
>

--089e0141aa22ceec74051fc9dc5b
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Section 5 of the user guide says:<br>&quot;Placeholders an=
d directives can be escaped by putting a backslash before them. \$var and \=
#if will be output as literal text&quot;=C2=A0<div>But obviously just putti=
ng \# doesn&#39;t work (see OP)<br><br>This does work:<br>s =3D &quot;&quot=
;&quot;a<br>\##<br><br>b<br>&quot;&quot;&quot;<br>print Template(s)<br>a<br=
>#<br>b<br><br></div><div>i.e. \## and an extra =C2=A0blank line<br></div><=
div><br>However, I&#39;m guessing this isn&#39;t intended behaviour, so may=
be don&#39;t rely on it!<br><br>I&#39;ve not looked at the source and don&#=
39;t know how Cheetah does it&#39;s parsing but I wonder if it&#39;s someth=
ing to do with the precedence of one-line #if then else# statements, ##comm=
ents and escaped \#directives? That might be a red herring...<br><br>Fred<b=
r><br><br>On 14 September 2015 at 20:59, Williams, James P2 &lt;<a href=3D"=
mailto:[email protected]">[email protected]</a>&gt; wrote=
:<br>&gt;<br>&gt; &gt; If you want just the hash use the #raw function<br>&=
gt;<br>&gt; &gt;<br>&gt;<br>&gt; &gt; #raw<br>&gt;<br>&gt; &gt; #<br>&gt;<b=
r>&gt; &gt; #end raw<br>&gt;<br>&gt; &gt;<br>&gt;<br>&gt; &gt; you&#39;ll g=
et your hash this way.<br>&gt;<br>&gt; =C2=A0<br>&gt;<br>&gt; Excellent.=C2=
=A0 I had forgotten about #raw.=C2=A0 Thanks.<br>&gt;<br>&gt; =C2=A0<br>&gt=
;<br>&gt; Jim<br>&gt;<br>&gt; =C2=A0<br>&gt;<br>&gt;<br>&gt; --------------=
----------------------------------------------------------------<br>&gt;<br=
>&gt; _______________________________________________<br>&gt; Cheetahtempla=
te-discuss mailing list<br>&gt; <a href=3D"mailto:Cheetahtemplate-discuss@l=
ists.sourceforge.net">[email protected]</a><br>=
&gt; <a href=3D"https://lists.sourceforge.net/lists/listinfo/cheetahtemplat=
e-discuss">https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-dis=
cuss</a><br>&gt;<br></div></div>

--089e0141aa22ceec74051fc9dc5b--


--===============1133366668773191022==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

------------------------------------------------------------------------------

--===============1133366668773191022==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Cheetahtemplate-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss

--===============1133366668773191022==--