When no delimiter has been specified it tries to split at paragraph boundaries (when it finds a <p> or <br /> or a linebreak etc.). The problem is that it does't check well enough how much actual content will remain. When you have a really long first paragraph this can cause great trouble. When using tinyMCE I get Code like this:
<p>
Lorem ipsum dolor....
In other words there's a linebrek just after the <p> and if the text in the paragraph is longer than the specified trim-lenght node_teaser will cut my teaser text at that linebreak. Leaving me with no text and a broken <p> tag...
For the time beeing I have altered my node.module and added $half_size = $size / 2; and && $length < $half_size
// 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);
// Introducing $half_size
$half_size = $size / 2;
foreach ($breakpoints as $point => $offset) {
$length = strpos($reversed, strrev($point));
// Checking that the length of what we cut off is not longer than half the teaser text length asked for
// Otherwise we let the function go on and split at the end of the last full sentence
if ($length !== FALSE && $length < $half_size) {
$position = - $length - $offset;
return ($position == 0) ? $teaser : substr($teaser, 0, $position);
}
}
This works OK for me now, get alot of broken <p> tags that doesn't validate though, an additional function to validate the HTML and close open tags would be nice.
Comments
Comment #1
gpk commentedThanks for posting this issue snobojohan, I was literally just about to do same but you beat me to it!
Previously I reported same problem in a forum topic http://drupal.org/node/160241.
Comment #2
jscheel commentedI can confirm this. Fix seems to work fine.
Comment #3
Bevan commentedPlease check if this is the same as the issue described at http://drupal.org/node/180425
Comment #4
gpk commentedIt's not a duplicate of that issue but of http://drupal.org/node/155337
Comment #5
manerhabe commentedThanks so much! This fixed the really strange teasers I was getting.
Comment #6
Bevan commentedThis has been improved on in http://drupal.org/node/155337 and http://drupal.org/node/180425.
To the point where the issue described can probably be considered fixed.
Feel free to reset status to active if you plan on contributing this as a patch. I think any patch introducing the approach here would be a feature and need to go into drupal 7.
Comment #7
(not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.