I'm having an issue which is proving very hard to solve, and I can't find a solution anywhere. I'm SURE that someone must have had this issue before:
For example, if the break comes after a <strong> tag and before the closing </strong>, the whole rest of the page will appear bold. I need some way to count the opening tags and their position and make sure there is a matching close tag for each, excluding self-closing tags like <img />, and writing in required close tags - in the correct position. This is the example HTML I'm using, it could be chopped off at any point:
<div class="outerHolder"> <h3>Test <a>heading</a></h3> <p>This is a paragraph, with a <strong>bold</strong> word in. </p> <ul> <li>list item 1</li> <li>list item 2</li> <li>list item 3</li> </ul> <table> <tr> <td>tablecell1</td> <td>tablecell2</td> <td>tablecell3</td> </tr> </table> </div>
I'm sure the solution is somewhere along the lines of building an array of open tags and then an array of close tags, and then comparing them somehow. I just can't see a way to get the positions correct.
My approach would be to just remove all the mark-up from the intro. Sometimes I've had a requirement that the intro text is actually a completely different bit of data from the main article, and the intro text is text-only. Perhaps I'd at least default the intro to be the first n characters of the mark-up-stripped main article, but always give the user an option to write their own intros.