Strip tags from formatted text before trimming

Created on 10 September 2024, 2 months ago
Updated 18 September 2024, 2 months ago

Problem/Motivation

The default 'Summary or trimmed' formatter specifically includes HTML tags in the character count, which is not very intuitive. The trim count should exclude HTML tags, which Smart Trim module โ†’ does.

This is explicitly tested for in https://git.drupalcode.org/project/drupal/-/blob/HEAD/core/modules/text/...

Steps to reproduce

Install Drupal using the Standard install
Modify the article teaser display to trim at 100 characters
Create an article with the following markup as the body: <p><a href="https://wwww.drupal.org/"><em><span><strong>The maximum number of characters used in the trimmed version of a post. Drupal will use this setting to determine at which offset long posts should be trimmed Note that this setting will only affect new or updated content and will not affect existing teasers.</strong></span></em></a></p>
See that the resulting teaser displays as The maximum number of characters used in the because the preceding HTML tags are counted in the 100 chars.

Proposed resolution

Strip tags before trimming.

Remaining tasks

  1. Determine the approach for this, including whether it should be a setting, since it would affect existing sites if we just change the behaviour
  2. MR with tests
  3. Review
  4. Commit

User interface changes

N/A

Introduced terminology

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

TBC

โœจ Feature request
Status

Needs work

Version

11.0 ๐Ÿ”ฅ

Component
Textย  โ†’

Last updated 15 days ago

Created by

๐Ÿ‡ฆ๐Ÿ‡บAustralia pameeela

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024