Commit 79792eeb authored by Gábor Hojtsy's avatar Gábor Hojtsy

#155337 by gpk and Bevan: only treat newlines teaser breakers, if the newline...

#155337 by gpk and Bevan: only treat newlines teaser breakers, if the newline filter is present in the particular input format
parent dba1500a
...@@ -238,14 +238,20 @@ function node_teaser_js(&$form, &$form_state) { ...@@ -238,14 +238,20 @@ function node_teaser_js(&$form, &$form_state) {
/** /**
* Automatically generate a teaser for a node body. * 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 * @param $body
* The content for which a teaser will be generated. * The content for which a teaser will be generated.
* @param $format * @param $format
* The format of the content. If the content contains PHP code, we do not * 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 * @param $size
* The desired character length of the teaser. If omitted, the default * 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 * @return
* The generated teaser. * The generated teaser.
*/ */
...@@ -279,7 +285,7 @@ function node_teaser($body, $format = NULL, $size = NULL) { ...@@ -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 we have a short body, the entire body is the teaser.
if (strlen($body) < $size) { if (strlen($body) <= $size) {
return $body; return $body;
} }
...@@ -308,8 +314,14 @@ function node_teaser($body, $format = NULL, $size = NULL) { ...@@ -308,8 +314,14 @@ function node_teaser($body, $format = NULL, $size = NULL) {
// A paragraph near the end of sliced teaser is most preferable. // A paragraph near the end of sliced teaser is most preferable.
$break_points[] = array('</p>' => 0); $break_points[] = array('</p>' => 0);
// Other line breaks often indicate a paragraph. // If no complete paragraph then treat line breaks as paragraphs.
$break_points[] = array('<br />' => 6, '<br>' => 4, "\n" => 1); $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. // If the first paragraph is too long, split at the end of a sentence.
$break_points[] = array('. ' => 1, '! ' => 1, '? ' => 1, '。' => 0, '؟ ' => 1); $break_points[] = array('. ' => 1, '! ' => 1, '? ' => 1, '。' => 0, '؟ ' => 1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment