diff --git a/modules/node/node.module b/modules/node/node.module index 0a369675398..dd62af23b41 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -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 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('

' => 0); - // Other line breaks often indicate a paragraph. - $break_points[] = array('
' => 6, '
' => 4, "\n" => 1); + // If no complete paragraph then treat line breaks as paragraphs. + $line_breaks = array('
' => 6, '
' => 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);