"Wrap caps" should capture period-separated abbreviations without trailing periods

Created on 12 August 2025, 2 months ago

Problem/Motivation

The house style for our organization is to not include a trailing period in abbreviations (e.g. "Doing D.I.Y is fun."). However this seems not to be properly captured by the "Wrap Caps" filter, and the last initial is not wrapped.

The same problem was apparently reported and fixed in version 7 here: Wrap Caps is inconsistent (2304643) - the code intended to fix the issue seems to have been carried forward to version 8, but doesn't behave as it should, at least not in version 8.

Looking at the the regex on line 90 of src/Typogrify.php and testing it locally - I can see the solution is most of the way there but still looks for a period followed by possible white-space (\.\s?) - This period would not exist for the last initial of period-separated abbreviations without trailing periods hence it is not captured.

Here's the line in question:

      (?:[[\p{Lu}]+\.\s?)+)  # Followed by the same thing at least once more

We can make period optional on proceeding initials by appending the ? quantifier after \.

Steps to reproduce

1. Enter the following text into a new article using a text-format

"D.I.Y is a great way to save money on home renovation.

2. Save the article

3. Inspect element in your browser to view the rendered markup as follows

<span class="caps">D.I.</span>Y is a great way to save money on home renovation.

4. Note that the "Y" is not captured in the span.

Proposed resolution

Change line 90 of src/Typogrify.php from...

      (?:[[\p{Lu}]+\.\s?)+)  # Followed by the same thing at least once more

..to...

      (?:[[\p{Lu}]+\.?\s?)+)  # Followed by the same thing at least once more

Remaining tasks



Create MR
Review by maintainers
Revisions/Changes
Merge

User interface changes

Rendered text before (with wrapped caps styled red)

Rendered text after (with wrapped caps still styled red)

API changes

N/A

Data model changes

N/A

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇬🇧United Kingdom jacobupal Leeds

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

Comments & Activities

Production build 0.71.5 2024