License: Freeware
Version: 2
Last update: 2009-12-09
See also: EE 1.6.x version

TruncHTML

This plugin is used for limiting text to a specified length. Much like the Character Limiter-Plugin that comes with ExpressionEngine.

The difference is, that TruncHTML is HTML-aware, so you can use it to shorten HTML-formatted text and keep the markup without being afraid of breaking it.

Unlike the standard limiter-plugins it does not count characters that belong to HTML-tags and does not cut-off in the middle of tags.

Example:
Limit the following text to 16 characters:

Take a look <a href="ref.html"><img src="arrow.gif" /></aat this page

Using standard char_limit will result in:

Take a look <a href="ref.html"><img&#8230; 

Using TruncHTML will result in:

Take a look <a href="ref.html"><img src="arrow.gif" /></aat 


Furthermore it tries its best to close all tags that remain open after the text has been limited.


So if you limit the following text to 80 chars…

<class="quote"><b>Never let your sense of morals get in the way of doing whats right.<br />
<
em>Isaac Asimov</em></b></p

the result will be ...

<class="quote"><b>Never let your sense of morals get in the way of doing whats right.<br />
<
em>Isaac</em></b></p

instead of ...

<class="quote"><b>Never let your sense of morals get in the way of doing whats 

... which would probably screw the rest of the page due to the missing </b>- and </p>-tags.