views:

74

answers:

1

I'm using python Textile to store markup in the database. I would like to yield the following HTML snippet:

(<em>asdf</em>)

The obvious doesn't get encoded:

(_asdf_)   ->   <p>(_asdf_)</p>

The following works, but yields an ugly space:

( _asdf_)   ->   <p>( <em>asdf</em>)

Am I missing something obvious or is this just not possible using python Textile?

+1  A: 

It's hard to say if this is a bug or not; in the form on the Textile website, (_foo_) works as you want, but in the downloadable PHP implementation, it doesn't.

You should be able to do this:

([_asdf_])  ->  <p>(<em>asdf</em>)</p>

However, this doesn't work, which is a bug in py-textile. You either need to use this:

(]_asdf_])

or patch textile.py by changing line 918 (in the Textile.span() method) to:

            (?:^|(?<=[\s>%(pnct)s])|([{[]))

(the difference is in the final group; the brackets are incorrectly reversed.)

You could also change the line to:

            (?:^|(?<=[\s>(%(pnct)s])|([{[]))

(note the added parenthesis) to get the behavior you desire for (_foo_), but I'm not sure if that would break anything else.


Follow up: the latest version of the PHP Textile class does indeed make a similar change to the one I suggested.

Miles
Very complete answer. Thanks!
scompt.com