summaryrefslogtreecommitdiff
path: root/modules/node
diff options
context:
space:
mode:
authorGábor Hojtsy <gabor@hojtsy.hu>2007-11-29 11:29:24 +0000
committerGábor Hojtsy <gabor@hojtsy.hu>2007-11-29 11:29:24 +0000
commit79792eeb6fccfdbe91affb228e3e6259328d7c7a (patch)
tree876c3d75ded6f6348d2c25a1118e539b1fc46131 /modules/node
parentdba1500aae7a20fc57c0825c50458dc90446e2b1 (diff)
downloadbrdo-79792eeb6fccfdbe91affb228e3e6259328d7c7a.tar.gz
brdo-79792eeb6fccfdbe91affb228e3e6259328d7c7a.tar.bz2
#155337 by gpk and Bevan: only treat newlines teaser breakers, if the newline filter is present in the particular input format
Diffstat (limited to 'modules/node')
-rw-r--r--modules/node/node.module22
1 files changed, 17 insertions, 5 deletions
diff --git a/modules/node/node.module b/modules/node/node.module
index 0a3696753..dd62af23b 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 <!--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);