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. Curabitur non nulla sit amet nisl tempus convallis quis ac lectus. Pellentesque in ipsum id orci porta dapibus. Vestibulum ac diam sit amet quam vehicula elementum sed sit amet dui. Nulla porttitor accumsan tincidunt. Cras ultricies ligula sed magna dictum porta. Nulla quis lorem ut libero malesuada feugiat. Proin eget tortor risus. Curabitur non nulla sit amet nisl tempus convallis quis ac lectus. Proin eget tortor risus. Praesent sapien massa, convallis a pellentesque nec, egestas non nisi. 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 .
, 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 ' '=> 1
here, but no works.
Comment | File | Size | Author |
---|---|---|---|
#30 | Screenshot 2024-02-27 at 14.10.29.png | 1 MB | 2dareis2do |
#30 | Screenshot 2024-02-27 at 14.10.16.png | 228.62 KB | 2dareis2do |
#30 | Screenshot 2024-02-27 at 14.09.48.png | 1007.86 KB | 2dareis2do |
#20 | 2835615-20.patch | 4.09 KB | smustgrave |
#20 | interdiff-17-20.txt | 2.64 KB | smustgrave |
Comments
Comment #2
edysmpComment #3
edysmpComment #4
darrenwh CreditAttribution: darrenwh as a volunteer and at Investis Digital commentedI 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
Comment #14
smustgrave CreditAttribution: smustgrave at Mobomo commentedConfirmed this is still relevant in D9.5
Will need an issue summary update when a solution is agreed upon.
Comment #15
smustgrave CreditAttribution: smustgrave at Mobomo commentedThis 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.
Comment #16
smustgrave CreditAttribution: smustgrave at Mobomo commentedSo 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
Comment #17
smustgrave CreditAttribution: smustgrave at Mobomo commentedComment #20
smustgrave CreditAttribution: smustgrave at Mobomo commentedComment #27
smustgrave CreditAttribution: smustgrave at Mobomo commentedClosed #1482178: text_summary does not break on word boundaries if the first sentence is longer than the length of the summary being produced as duplicate moving over credit.
Comment #28
RoSk0I 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
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.
Comment #30
2dareis2do CreditAttribution: 2dareis2do commentedI 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
Not seen 。before
adding '.' => 0, works for me. e.g.
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