how to unescape/escape from turbogears/genshi?

31 views
Skip to first unread message

Thang Nguyen

unread,
Dec 29, 2009, 1:45:08 PM12/29/09
to turbo...@googlegroups.com
Hi,

I am running into a problem with escape/unescape with TG/genshi
template. I've put together a simple code below (very easy to
reproduce) to illustrate the problem.

Below is my test.html resides in the /templates directory. I expect
to see a border around the element "two", but looks like something is
not quite correct with the statement ("div > p") when using with
genshi template, I suspect it has something to do with escape/unescape
of ">", but not quite sure what must be done here. Any suggestion to
make this work is really appreciated. Thanks much in advance.

tpn


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:py="http://genshi.edgewall.org/"
xmlns:xi="http://www.w3.org/2001/XInclude">

<head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type"
py:replace="''"/>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("div > p").css("border", "1px solid gray");

});
</script>
</head>
<body>
<p>one</p>
<div>
<p>two</p>
</div>
<p>three</p>
</body>
</html>

Christopher Arndt

unread,
Dec 29, 2009, 2:12:43 PM12/29/09
to turbo...@googlegroups.com
Thang Nguyen schrieb:

> I suspect it has something to do with escape/unescape
> of ">", but not quite sure what must be done here. Any suggestion to
> make this work is really appreciated. Thanks much in advance.

Write the "greater than" sign as "&gt;" as it is appropriate in an XML
document?

Remember, Genshi templates must be valid XML.

Chris

Uwe Schroeder

unread,
Dec 29, 2009, 2:34:19 PM12/29/09
to turbo...@googlegroups.com, Thang Nguyen

On Tuesday 29 December 2009 10:45:08 am Thang Nguyen wrote:

> $(document).ready(function(){
> $("div > p").css("border", "1px solid gray");
>
> });

Either write the > as &gt; or put a CDATA block around the $(document).ready
function.

Thang Nguyen

unread,
Dec 29, 2009, 3:55:02 PM12/29/09
to turbo...@googlegroups.com
---------- Forwarded message ----------
From: Thang Nguyen <thang.p...@gmail.com>
Date: Tue, Dec 29, 2009 at 12:53 PM
Subject: Re: [TurboGears] how to unescape/escape from turbogears/genshi?
To: Uwe Schroeder <u...@oss4u.com>


Hi all,

I got it to work the way I wanted using CDATA method.   Thanks to all
for your suggestions.  If anyone is looking for the answer, below is
the code:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
     xmlns:py="http://genshi.edgewall.org/"
     xmlns:xi="http://www.w3.org/2001/XInclude">

<head>


 <script src="http://code.jquery.com/jquery-latest.js"></script>

 <script type="text/javascript"> /* <![CDATA[*/


       $(document).ready(function(){
               $("div > p").css("border", "1px solid gray");

       });
  /*]]>*/</script>


</head>
<body>
   <p>one</p>
       <div>
           <p>two</p>
       </div>
   <p>three</p>
</body>
</html>

=========================

On Tue, Dec 29, 2009 at 12:15 PM, Thang Nguyen
<thang.p...@gmail.com> wrote:
> Thanks for all your suggestions, but let me clarify the situation a
> bit, maybe I was not clear at first.
>
> What I would like to see if there is a way to make the greater sign
> ">" remains as it is, not converted to "&gt;".   TG/Genshi seems to
> take ">" and convert it to "&gt;" by default.   Would CDATA method
> allow me to keep the greater sign as ">" when viewed under a browser ?
>  I will give it a try and see if that works.
>
> tpn

Thang Nguyen

unread,
Dec 29, 2009, 4:01:56 PM12/29/09
to turbo...@googlegroups.com
forwarded message.

On Tue, Dec 29, 2009 at 12:53 PM, Thang Nguyen
<thang.p...@gmail.com> wrote:
> Hi all,
>
> I got it to work the way I wanted using CDATA method.   Thanks to all
> for your suggestions.  If anyone is looking for the answer, below is
> the code:
>
>

> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
>                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml"
>      xmlns:py="http://genshi.edgewall.org/"
>      xmlns:xi="http://www.w3.org/2001/XInclude">
>
> <head>

>  <script src="http://code.jquery.com/jquery-latest.js"></script>

>  <script type="text/javascript"> /* <![CDATA[*/


>        $(document).ready(function(){
>                $("div > p").css("border", "1px solid gray");
>
>        });

>   /*]]>*/</script>


> </head>
> <body>
>    <p>one</p>
>        <div>
>            <p>two</p>
>        </div>
>    <p>three</p>
> </body>
> </html>
>

> =========================
>
>
>
> On Tue, Dec 29, 2009 at 12:15 PM, Thang Nguyen
> <thang.p...@gmail.com> wrote:
>> Thanks for all your suggestions, but let me clarify the situation a
>> bit, maybe I was not clear at first.
>>
>> What I would like to see if there is a way to make the greater sign
>> ">" remains as it is, not converted to "&gt;".   TG/Genshi seems to
>> take ">" and convert it to "&gt;" by default.   Would CDATA method
>> allow me to keep the greater sign as ">" when viewed under a browser ?
>>  I will give it a try and see if that works.
>>
>> tpn
>>
>> On Tue, Dec 29, 2009 at 11:34 AM, Uwe Schroeder <u...@oss4u.com> wrote:
>>>

Reply all
Reply to author
Forward
0 new messages