#155337 by gpk and Bevan: only treat newlines teaser breakers, if the newline filter is present in the particular input format

6.x
Gábor Hojtsy 2007-11-29 11:29:24 +00:00
parent dba1500aae
commit 79792eeb6f
1 changed files with 17 additions and 5 deletions

View File

@ -238,14 +238,20 @@ function node_teaser_js(&$form, &$form_state) {
/**
* Automatically generate a teaser for a node body.
*
* If the end of the teaser is not indicated using the <!--break--> delimiter
* then we try to end it at a sensible place, such as the end of a paragraph,
* a line break, or the end of a sentence (in that order of preference).
*
* @param $body
* The content for which a teaser will be generated.
* @param $format
* The format of the content. If the content contains PHP code, we do not
* split it up to prevent parse errors.
* split it up to prevent parse errors. If the line break filter is present
* then we treat newlines embedded in $body as line breaks.
* @param $size
* The desired character length of the teaser. If omitted, the default
* value will be used.
* value will be used. Ignored if the special delimiter is present
* in $body.
* @return
* The generated teaser.
*/
@ -279,7 +285,7 @@ function node_teaser($body, $format = NULL, $size = NULL) {
}
// If we have a short body, the entire body is the teaser.
if (strlen($body) < $size) {
if (strlen($body) <= $size) {
return $body;
}
@ -308,8 +314,14 @@ function node_teaser($body, $format = NULL, $size = NULL) {
// A paragraph near the end of sliced teaser is most preferable.
$break_points[] = array('</p>' => 0);
// Other line breaks often indicate a paragraph.
$break_points[] = array('<br />' => 6, '<br>' => 4, "\n" => 1);
// If no complete paragraph then treat line breaks as paragraphs.
$line_breaks = array('<br />' => 6, '<br>' => 4);
// Newline only indicates a line break if line break converter
// filter is present.
if (isset($filters['filter/1'])) {
$line_breaks["\n"] = 1;
}
$break_points[] = $line_breaks;
// If the first paragraph is too long, split at the end of a sentence.
$break_points[] = array('. ' => 1, '! ' => 1, '? ' => 1, '。' => 0, '؟ ' => 1);