Copy paste code from StackOverflow to 'fix' <br> issue

So I debugged this a bit, and have narrowed down the issue. Simple attempts to fix the recursion in traverseTextNodes didn't work for me, so I just found code and used that. Obviously that isn't production quality, but at least a starting point of sorts.

Any particular reason why it is throwing an exception to abort, rather than just regular recursion-with-a-base-case type recursion?