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 «te;rocks»te; in Ukraine"
Added ellipsis: "Drupal «te;rocks»te..."
Passed html corrector: "Drupal «te;rocks»te..." (»te 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.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | views_handler_field.patch | 620 bytes | neochief |
| views_handler_field.patch | 602 bytes | neochief |
Comments
Comment #1
neochief commentedAh, 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)
Comment #2
merlinofchaos commentedCan 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.
Comment #3
merlinofchaos commented(thanks to chx for the new regex!)
Comment #4
arraypad commentedThe above regex will replace valid entities. To fix this,
/(?:<(?!.+>)|&(?!.+;)).{1,10}$/sNB. also added the s modifier to allow newline characters
Comment #5
neochief commentedpatch for #4, which works well for me
Comment #6
merlinofchaos commentedCommitted! Thanks for the regex help folks!
Comment #7
neochief commentedYou're welcome!
Comment #9
sidharth_k commentedI 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...
Comment #10
dawehnerDo you have enabled the can contain html option?
Comment #11
sidharth_k commentedI did not -- sorry.
I selected it and it works properly. Sorry for the false alarm.