Blog Index » Code Challenge: HTML length triming

Code Challenge: HTML length triming

Here's a challenge for you: Take an arbitrary-length string of (valid) HTML code and trim it to n (visible) characters max-length while keeping the resulting HTML valid and removing unnecessary tags. I'll also put another input constraint: no layout, images, or script; you can assume that table, img, and script tags will all be stripped out first.


So, say that we have:
<p>Hola mi amigo! <i>como estas?</i></p>
(you can forgive my poor spanish, I'm writing this in an airport in Brazil)

Now, take that sting and trim it to 20 characters, then the result should be:
<p>Hola mi amigo! <i>como </i></p>



Easy enough right? But trimming it to 15 characters should result in:
<p>Hola mi amigo! </p>



Now what do you think about it?

Labels: , ,

0 Comments:

Post a Comment