views:

70

answers:

2

hi i have a html text like this:

aaa dafjsld dslajfk òsal asfòljd <a href="ciao.com">aa aa</a> adsfsadfsadfs

i want to split it in 2 paragraphs. but i don't want to generate this situation:

<p>aaa dafjsld dslajfk òsal asfòljd <a href="ciao.com">aa</p><p> aa</a> adsfsadfsadfs</p>

how can i check if the split involves any tags and avoid it?

thanks

+2  A: 

You could use simple_format for this, assuming your text is formatted correctly. Your link text should end inside the paragraph, not on the next one, so I've modified it slightly:

 aaa dafjsld dslajfk òsal asfòljd <a href='ciao.com'>aa</a>

 aa adsfsadfsadfs

This will output:

<p>aaa dafjsld dslajfk òsal asfòljd <a href='ciao.com'>aa</a></p><p>aa adsfsadfsadfs</p> or something to that effect if you pass it to simple_format.

Ryan Bigg
I think he wanted to wrap text, not do something similar to Markdown, but thanks for telling me about `simple_format`.
Tim Snowhite
+1 for making me read the documentation of `simple_format`.
KandadaBoggu
Ah yes, documentation. I should link to that.
Ryan Bigg
A: 

Without knowing more about the problem, the most general solution will probably involve Hpricot or REXML. That'll make sure that any nested tags are handled correctly. You can walk the node list and decide where to create paragraphs.

Tim Snowhite