API page: http://api.drupal.org/api/drupal/modules--field--modules--text--text.mod...
Describe the problem you have found:
The text_summary function has an early exit, if a <!--break-->
tag will be found in the content. Sadly i discovered a problem if the author of the html body content didn't placed it correctly:
My body <div>is fine<!--break--></div>
This causes an shortened teaser e.g.:
My body <div>is fine
..and break up the div-structure of the surrounding page.
Not only the author of this body can make this mistake, also the ckeditor / wysiwyg didn't care about.
So i have to handle this issue on the theming layer, but i would prefer a central solution in the text.module.
Here is my patch:
Index: text.module
===================================================================
--- text.module (Revision 121)
+++ text.module (Arbeitskopie)
@@ -361,15 +361,19 @@
}
// If a valid delimiter has been specified, use it to chop off the summary.
+ $filters = filter_list_format($format);
if ($delimiter !== FALSE) {
- return substr($text, 0, $delimiter);
+ $summary = substr($text, 0, $delimiter);
+ if (isset($filters['filter_htmlcorrector'])) {
+ $summary = _filter_htmlcorrector($summary);
+ }
+ return $summary;
}
// We check for the presence of the PHP evaluator filter in the current
// format. If the body contains PHP code, we do not split it up to prevent
// parse errors.
if (isset($format)) {
- $filters = filter_list_format($format);
if (isset($filters['php_code']) && $filters['php_code']->status && strpos($text, '<?') !== FALSE) {
return $text;
}
Comment | File | Size | Author |
---|---|---|---|
#1 | summary_html_corrector-1387560-1.patch | 1.05 KB | oriol_e9g |
Comments
Comment #1
oriol_e9gFirst this will be fixed in D8 and then backported to D7, rolled a patch for Drupal 8 but we still need tests for this.
Comment #2
martin.weidner CreditAttribution: martin.weidner commentedHi,
I found a similar problem when using the openWysiwyg editor:
The text_summary() method was just cutting everything and the teaser was empty.
Therefore i inserted the following line to quickfix the problem:
I know that now, all formatting gets lost in the teaser but at least there is displayed sth. Did I miss a setting or is my problem a bug within the function?
Best regards,
Martin
Comment #3
andypostlooks like duplicate of #1300920: The [node:summary] token does not output anything for body fields without a manual summary
Comment #4
oriol_e9gOk, go all to the other issue.
Comment #5
salvisI don't see how the two issues should be related. The other issue is about fixing the [node:summary] token only. This issue here shows up even if you don't use the [node:summary] token.
The token will obviously suffer if text_summary() doesn't work right, but just because preparing the token uses text_summary() doesn't mean the two issues are related. Both issues need to be fixed on their own.
Comment #7
oriol_e9gComment #8
oriol_e9g#1: summary_html_corrector-1387560-1.patch queued for re-testing.
Comment #9
andypost#1: summary_html_corrector-1387560-1.patch queued for re-testing.
Comment #17
goodDenis CreditAttribution: goodDenis as a volunteer commentedI added filter "Correct faulty and chopped off HTML" (filter_htmlcorrector) in text format setting and it helps me!
This is example code:
$summary = text_summary($node->get('body')->value, 'full_html');
Comment #19
Juhi Rathi CreditAttribution: Juhi Rathi at Valuebound commentedhtmlentities() will simply solve the issue. This will convert all applicable characters to HTML entities.
Comment #25
quietone CreditAttribution: quietone at PreviousNext commentedThere are a few issues about the trimmed text. Adding what I think is the closest fit as a related issue.
Comment #27
smustgrave CreditAttribution: smustgrave at Mobomo commentedSeems to be a duplicate of #3022299: Make manual teaser break (<!--break-->) a configuration property closing this one as that one is more ahead.
if you disagree please reopen explaining why thanks!