The text is trimmed in unexpected places

Created on 30 May 2024, 7 months ago
Updated 10 June 2024, 7 months ago

Problem/Motivation

The readmore module trims text in unexpected places, leading to awkward and incomplete sentences. For example, when the trim length is set to 100 characters, and the text is:
"As the sun began to set, casting a warm, golden glow over the small town of Oakridge, Mr. Thompson strolled down Maple Street."
it trims to:
"As the sun began to set, casting a warm, golden glow over the small town of Oakridge, Mr..."
instead of:
"As the sun began to set, casting a warm, golden glow over the small town of Oakridge, Mr. Thompson..."
This results in an abrupt display of text, affecting readability and user experience.
After debugging the module, I identified that the code in the readmore_truncate_string() function is deciding to cut within the first paragraph, which contributes to this issue.

Steps to reproduce

  1. Install and enable the readmore module on a Drupal 10 site.
  2. Configure a content type to use the readmore format for trimming text.
  3. Set the trim length to 100 characters.
  4. Create a new piece of content with the following text:
  5. "As the sun began to set, casting a warm, golden glow over the small town of Oakridge, Mr. Thompson strolled down Maple Street."
  6. Save the content and view it on the site.

Expected result:
The text should be trimmed to complete sentences, such as:
"As the sun began to set, casting a warm, golden glow over the small town of Oakridge, Mr. Thompson..."

Actual result:
The text is trimmed abruptly, resulting in:
"As the sun began to set, casting a warm, golden glow over the small town of Oakridge, Mr..."

Proposed resolution

To improve the readmore module, the feature "If the first paragraph is too long, split at the end of a sentence" should be made optional. This would allow users to enable or disable this behavior based on their preferences.

  1. Introduce a new configuration option in the module settings to enable or disable splitting at the end of a sentence.
  2. When this option is enabled, the module should analyze the text and trim it at the end of the nearest complete sentence within the specified character limit.
  3. When this option is disabled, the module should trim the text strictly at the specified character limit, even if it results in incomplete sentences.
✨ Feature request
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States xopoc

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024