[Tutor] Re: handling string!!

Andrei project5 at redrival.net
Fri Oct 24 05:32:40 EDT 2003


Daniel Ehrenberg wrote:
<snip>

>>Perhaps you 
>>should look at its code.
> 
> 
> It uses completely different markup. And anyway, it
> didn't work.

I'm afraid I sent you the wrong links. Here's the correct one:

http://www.tinylist.org/cgi-bin/wikinehesa.py/SandBox

At the bottom, I've pasted this code:
`````b & i''' i''
`````b & i'' i'''

The HTML produced:

<b><i> b &amp; i</i></b><i> i </i>
<b><i> b &amp; i </i> i</b>

Looks correct to me. Perhaps it breaks in other cases though, I have no idea.

<snip>

> Well, then I'd have to write the code completely
> differently than I wrote it on the previous letter.
> How do you think I could go about writing the actual
> code using that method?

The code you mention in your previous letter would work with nested tags 
too, you just wouldn't get valid XHTML (you'd get <b><i></b></i>). You 
could fix it by running Tidy on it (I think there's a Python binding for it 
somewhere). But I think that if you want valid XHTML, string splitting 
won't get you that unless you use some kind of lookahead mechanism to find 
out which is closed first and hence must be opened last - not that fun IMO. 
Given the options, I'd rather take the simple finite state machine route 
with the list. It's not particularly hard to code.

> Kirk's wiki uses different things for opening quotes
> and closing quotes.

True, but I'm not sure how much of a difference that makes. He still has to 
close the right one at the right time. Anyway, I just looked at the code of 
the 1.2.0 tarball and I find it puzzling:

   line=string.replace(line,"```",'<b>')	# Start a BOLD block
   line=string.replace(line,"'''",'</b>')# end a BOLD block
   line=string.replace(line,"``",'<i> ')	# start an italic block
   line=string.replace(line,"''",' </i>')# end an italic block

I don't understand how this makes:

    `````b & i''' i''

into:

    <b><i> b &amp; i</i></b><i> i </i>

In an interactive session we'd get the expected invalid HTML with that code:

 >>> t = "`````b & i''' i''"
 >>> t = t.replace("```",'<b>')
 >>> t = t.replace("'''",'</b>')
 >>> t = t.replace("``",'<i> ')
 >>> t = t.replace("''",' </i>')
 >>> t
'<b><i> b & i</b> i </i>'


-- 
Yours,

Andrei

=====
Mail address in header catches spam. Real contact info (decode with rot13):
cebwrpg5 at bcrenznvy.pbz. Fcnz-serr! Cyrnfr qb abg hfr va choyvp cbfgf. V 
ernq gur yvfg, fb gurer'f ab arrq gb PP.





More information about the Tutor mailing list