Problem/Motivation

Summary or trimmed setting is cutting off at periods. When using long paragraphs with periods for Dr. (for example) it's cut off early.

Steps to reproduce

Create a node with the text from the original issue
View the page in the teaser
Verify it's cut off at Dr.

Proposed resolution

TBD

Remaining tasks

Figure out a solution
Write tests
Review
Commit

User interface changes

NA

API changes

NA

Data model changes

NA

Release notes snippet

NA

Original Post

I have a text in the body field trimmed to 600 characters in the tesaer view:
<p>Dr. Cras ultricies ligula sed magna dictum porta.&nbsp;Curabitur non nulla sit amet nisl tempus convallis quis ac lectus.&nbsp;Pellentesque in ipsum id orci porta dapibus.&nbsp;Vestibulum ac diam sit amet quam vehicula elementum sed sit amet dui.&nbsp;Nulla porttitor accumsan tincidunt.&nbsp;Cras ultricies ligula sed magna dictum porta.&nbsp;Nulla quis lorem ut libero malesuada feugiat.&nbsp;Proin eget tortor risus.&nbsp;Curabitur non nulla sit amet nisl tempus convallis quis ac lectus.&nbsp;Proin eget tortor risus.&nbsp;Praesent sapien massa, convallis a pellentesque nec, egestas non nisi.&nbsp;Vivamus suscipit tortor eget felis porttitor volutpat. Quisque velit nisi, pretium ut lacinia in, elementum id enim. Curabitur arcu erat, accumsan id imperdiet et, porttitor at sem. Quisque velit nisi, pretium ut lacinia in, elementum id enim. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Donec velit neque, auctor sit amet aliquam vel, ullamcorper sit amet ligula. Curabitur aliquet quam id dui posuere blandit. Curabitur aliquet quam id dui posuere blandit. Curabitur non nulla sit amet nisl tempus convallis quis ac lectus. Pellentesque in ipsum id orci porta dapibus.</p>

I am getting a teaser trimmed:
Dr.

I think the problem is .&nbsp;, if I removed this, the trimmed is fine, there is a drupal solution for not removed all the html code space in my site?

I try fixed adding '&nbsp;'=> 1 here, but no works.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

edysmp created an issue. See original summary.

edysmp’s picture

Issue summary: View changes
edysmp’s picture

Issue summary: View changes
darrenwh’s picture

I can replicate this issue, the system is trimming up to the period(.) if this is moved further into the sentence the trimming happens after the period

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Version: 9.4.x-dev » 9.5.x-dev
Issue tags: +Bug Smash Initiative, +Needs issue summary update

Confirmed this is still relevant in D9.5

Will need an issue summary update when a solution is agreed upon.

smustgrave’s picture

Issue summary: View changes
Issue tags: -Needs issue summary update

This doesn't seem to be related to the html character nbsp but that it's one paragraph and the code uses the period in doctor as a breakpoint.

Not sure best way to avoid certain periods, like Dr, Mr, Mrs, but apply at end of sentences.

smustgrave’s picture

So one contrib module that may be worth mentioning is https://www.drupal.org/project/smart_trim

Also playing around with the function there’s a line
$rpos = strpos($reversed, strrev($point));
if I replace as
$rpos = strpos($summary, strrev($point)); OR
$rpos = strpos($reversed, $point);
it works then too but I’m sure using reversed as for a reason

smustgrave’s picture

The last submitted patch, 17: 2835615-17-tests-only.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 17: 2835615-17.patch, failed testing. View results

smustgrave’s picture

Status: Needs work » Needs review
FileSize
2.64 KB
4.09 KB

Status: Needs review » Needs work

The last submitted patch, 20: 2835615-20.patch, failed testing. View results

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave credited chx.

smustgrave’s picture

RoSk0’s picture

I don't think it's fair to call #1482178: text_summary does not break on word boundaries if the first sentence is longer than the length of the summary being produced duplicate of this one. To me it feels like they are talking about related, but different things.

The problem we see with text_trimmed formatter is that it breaks works when trimming body field with HTML. We have no &nbsp; there mostly.

Tested the patch from #20 and it haven't changed anything for us - we still see broken words at the end of the field output where the text was trimmed.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

2dareis2do’s picture

I have a similar issue where when importing content. if space does not follow then period then it will be be not be trimmed as described. This took a little while for me to try and debug but as you can see from the screenshots appear like a bug.

e.g. // If the first paragraph is too long, split at the end of a sentence.

So in text.module you have

  // If the first paragraph is too long, split at the end of a sentence.
  $break_points[] = ['. ' => 1, '! ' => 1, '? ' => 1, '。' => 0, '؟ ' => 1];

Not seen 。before

adding '.' => 0, works for me. e.g.

  $break_points[] = ['. ' => 1, '! ' => 1, '? ' => 1, '。' => 0, '.' => 0, '؟ ' => 1];

For my purposes I can change to following, but the dr. problem would still exist.

e.g.

Please see screen shots attached.

Add separate issue for this https://www.drupal.org/project/drupal/issues/3424444