Is there a way to split a long HTML string after N words? Obviously, I could use:
' '.join(foo.split(' ')[:n])
to get the first n words of a simple text string, but it can split in the middle of the html tag and will not produce a valid html because it does not close the tags that were open.
I need to do this on the zope / plone website - if there is something standard in those products that can do this, it will be perfect.
For example, let's say I have text:
<p>This is some text with a <a href="http://www.example.com/" title="Example link"> bit of linked text in it </a>. </p>
And I ask him to be divided into 5 words, he should return:
<p>This is some text with</p>
7 words:
<p>This is some text with a <a href="http://www.example.com/" title="Example link"> bit </a> </p>
python html zope plone
rjmunro
source share