Hi,
When I let the usage of HTML filters for posts (I tryed with book pages) the Preview trimmed version does not works if the post contains some HTML tag.

i.e.:
- set Length of trimmed posts = 200 characters.
- write a book page with this text:

row 1 row 1 row 1 row 1 row 1 row 1 row 1 row 1
row 2 row 2 row 2 row 2 row 2 row 2 row 2 row 2
row 3 row 3 row 3 row 3 row 3 row 3 row 3 row 3
row 4 row 4 row 4 row 4 row 4 row 4 row 4 row 4
row 5 row 5 row 5 row 5 row 5 row 5 row 5 row 5

And you will get the text up to the row 4 (right).

Now try with

row 1 row 1 row 1 row 1 row 1 row 1 row 1 row 1
<p>row 2 row 2 row 2 row 2 row 2 row 2 row 2 row 2</p>;
row 3 row 3 row 3 row 3 row 3 row 3 row 3 row 3
row 4 row 4 row 4 row 4 row 4 row 4 row 4 row 4
row 5 row 5 row 5 row 5 row 5 row 5 row 5 row 5

Also if the <p> is included in the Filtered HTML or if the Filtered HTML is set for Escape all tags you'll get the preview up to only the row 2.
I used <p> tag but also others tags give some problems, i.e. the <b> let the preview to write up to the row 3 (!?).

Comments

devbox’s picture

I see this problem in the function node_teaser() in this block that I don't understand the reason:

  // In some cases, no delimiter has been specified. In this case, we try to
  // split at paragraph boundaries.
  $breakpoints = array('</p>' => 0, '<br />' => 6, '<br>' => 4, "\n" => 1);
  // We use strpos on the reversed needle and haystack for speed.
  foreach ($breakpoints as $point => $offset) {
    $length = strpos($reversed, strrev($point));
    if ($length !== FALSE) {
      $position = - $length - $offset;
      return ($position == 0) ? $teaser : substr($teaser, 0, $position);
    }
  }

If I remove this block all seems to work correctly and the html code produced seems all right.

gpk’s picture

Status: Active » Fixed

The problem is to do with how newlines within $body are interpreted, and the fact that node_teaser() tries to break at the end of a complete paragraph, i.e. a <p> element, in preference to a line break. See http://drupal.org/node/155337 for more details and a patch that provides significant improvements to the behaviour you are experiencing. Also see http://api.drupal.org/api/function/node_teaser for description of what the function is trying to do.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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