Shopify/liquid — pull request #243 by nickpearson (2013-08-20 15:58:13+00:00)
Title: Add truncate_html and truncatewords_html filters.

Intelligently handle truncation of strings that contain HTML (to avoid leaving opening HTML tags unclosed after truncation).

Truncating HTML with the standard `truncate` filter is not a good idea, since it can leave HTML tags unclosed (if a closing tag is cut off during truncation). For example, truncating `Read more about us` at 15 characters would result in `Read more ab...`, where the visible text is 15 characters (and the length of the HTML code is much longer). Perhaps worse, truncating that same string at 20 characters results in `Read`, which leaves the `` tag open, turning everything after it into a link.

The new `truncate_html` and `truncatewords_html` filters allow truncation of HTML while leaving the HTML intact and closing any tags that were opened before the truncation and closed after it (where the closing tags were cut off). Truncating the string from above at 15 characters using `truncate_html` results in `Read more ab...`.

Resolves #38. @fw42 please review.