dinkypumpkin at gmail
May 7, 2012, 6:13 AM
Post #2 of 3
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
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."""
html1 = textile.textile(s1)
s2 = re.sub(r'[ \t]*\n[ \t]*(\n?)[ \t]*', r' \1\1', s1, flags=re.MULTILINE)
html2 = textile.textile(s2)