Hello

Make a view with a Teaser field. There are "Trim only on a word boundary" option. When you enabling it, there's a planty of situations, which will cause trimming of a last symbol of HTML. As for tags, it causing loose of ellipsis, and for html entities, you will have crap in your content. Here's an example:

Full string: "Drupal rocks in Ukraine"
Trimmed by views: "Drupal rocks Added ellipsis: "Drupal rocks Passed html corrector: "Drupal rocks" (ellipsis gone)

Full string: "Drupal &laquote;rocks&raquote; in Ukraine"
Added ellipsis: "Drupal &laquote;rocks&raquote..."
Passed html corrector: "Drupal &laquote;rocks&raquote..." (&raquote in text)

Here's my patch to solve this. It cuts the rest of tag or entitiy from a text, so we will avoid such a bad picture.

Comments

neochief’s picture

Ah, damn, forgot to escape tags. Here's correct first example.

Full string: "Drupal <em>rocks</em> in Ukraine"
Trimmed string: "Drupal <em>rocks</em"
Added ellipsis: "Drupal <em>rocks</em..."
Passed html corrector: "Drupal <em>rocks</em>" (ellipsis gone)

merlinofchaos’s picture

Can you try it with this regex, which should be a little safer:
[&<](?!.{1,10}>).{1,10}$

That should refuse to eat whole tags but still get the scraps.

merlinofchaos’s picture

(thanks to chx for the new regex!)

arraypad’s picture

The above regex will replace valid entities. To fix this,

/(?:<(?!.+>)|&(?!.+;)).{1,10}$/s

NB. also added the s modifier to allow newline characters

neochief’s picture

StatusFileSize
new620 bytes

patch for #4, which works well for me

merlinofchaos’s picture

Status: Needs review » Fixed

Committed! Thanks for the regex help folks!

neochief’s picture

You're welcome!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

sidharth_k’s picture

Version: 6.x-2.3 » 6.x-2.11
Status: Closed (fixed) » Active

I am seeing this in Views 2.11 . I made an arbitrary view in the unformatted style that shows node title and node body (which is chopped off at, say, 200 chars). In a particular node body I added the <em> tag that starts before the 200th character. The ending </em> is much later. When is see the view, the <em> is not closed after the trim performed by the views. All text becomes italicized in subsequent rows.

This issue arose out a discussion in http://stackoverflow.com/questions/3832687/drupal-views-trimming-text-do...

dawehner’s picture

Do you have enabled the can contain html option?

sidharth_k’s picture

Status: Active » Closed (fixed)

I did not -- sorry.

I selected it and it works properly. Sorry for the false alarm.