Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

PyTextile Question

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


Joshua.R.English at gmail

May 3, 2012, 8:39 PM

Post #1 of 3 (275 views)
Permalink
PyTextile Question

I am working with an XML database and have large chunks of text in certain child and grandchildren nodes.

Because I consider well-formed XML to wrap at 70 characters and indent children, I end up with a lot of extra white space in the node.text string. (I parse with ElementTree.)

I thought about using pytextile to convert this text to HTML for a nicer display option, using a wx.HTMLWindow (I don't need much in the way of fancy HTML for this application.)

However, when I convert my multiple-paragraph text object with textile, my original line breaks are preserved. Since I'm going to HTML, I d'nt want my line breaks preserved.

Example (may be munged, formatting-wise):
<pre>
<action>
<description>This is a long multi-line description
with several paragraphs and hopefully, eventually,
proper HTML P-tags.

This is a new paragraph. It should be surrounded
by its own P-tag.

Hopefully (again), I won't have a bunch of unwanted
BR tags thrown in.
</description>
</action>
</pre>

I've tried several ways of pre-processing the text in the node, but pytextile still gives me line breaks.

Any suggestions? Is there a good tutorial for PyTextile that I haven't found?

Thanks.

Josh

--
http://mail.python.org/mailman/listinfo/python-list


dinkypumpkin at gmail

May 7, 2012, 6:13 AM

Post #2 of 3 (261 views)
Permalink
Re: PyTextile Question [In reply to]

On Friday, 4 May 2012 04:39:47 UTC+1, Josh English wrote:
> However, when I convert my multiple-paragraph text object with textile, my original line breaks are preserved. Since I'm going to HTML, I d'nt want my line breaks preserved.

I think any Textile implementation will preserve line breaks within a paragraph by converting them to BR tags. Both RedCloth and PyTextile do, anyway.

> I've tried several ways of pre-processing the text in the node, but pytextile still gives me line breaks.

Below is a test script that shows one way I've dealt with this issue in the past by reformatting paragraphs to remove embedded line breaks. YMMV.

import re, textile
print "INPUT1:"
s1 = """This is a long multi-line description
with several paragraphs and hopefully, eventually,
proper HTML P-tags.

This is a new paragraph. It should be surrounded
by its own P-tag.

Hopefully (again), I won't have a bunch of unwanted
BR tags thrown in."""
print(s1)
print "OUTPUT1:"
html1 = textile.textile(s1)
print(html1)
print "INPUT2:"
s2 = re.sub(r'[ \t]*\n[ \t]*(\n?)[ \t]*', r' \1\1', s1, flags=re.MULTILINE)
print(s2)
print "OUTPUT2:"
html2 = textile.textile(s2)
print(html2)

--
http://mail.python.org/mailman/listinfo/python-list


Joshua.R.English at gmail

May 9, 2012, 3:04 PM

Post #3 of 3 (250 views)
Permalink
Re: PyTextile Question [In reply to]

On Monday, May 7, 2012 6:13:28 AM UTC-7, dinkyp...@gmail.com wrote:
>
> Below is a test script that shows one way I've dealt with this issue in the past by reformatting paragraphs to remove embedded line breaks. YMMV.
>
> import re, textile
> ...

Wow. Thank you. This works. I'm trying to figure what that regular expression does, but I swear it's copying the lines twice. (Clearly, I don't speak re.)

Josh
--
http://mail.python.org/mailman/listinfo/python-list

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.