What would be the best solution for creating method that would take string containing HTML and would chop off the last lets say 10% of the string but without breaking any HTML tags.
The body and header tags are not part of the HTML string.
Also the rounding should happen upwards so lats say that if the last 10% would shrink to 5% if HTML should remain in untouched than the methods should rather cut the begging of HTML and perform 15% cut which would be the begging of the tag.
I’m thinking of using Jsoup for this. The problem is that the string might not be enclosed by HTML elements. It just might be a text with couple of links in it.
I think Jsoup is just the right way, remove the elements from the bottom of the page and check its string length in every step until you reach a satisfying number.
For removing the elements one by one you could use the remove method then compare the original string length with the current string length of the HTML document. I do not see any efficiency problem there.