"Wrap caps" should capture period-separated abbreviations without trailing periods
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3540951. -->
Reported by: [jacobupal](https://www.drupal.org/user/3648607)
Related to !12
>>>
<h3 id="summary-problem-motivation">Problem/Motivation</h3>
<p>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.</p>
<p><del>The same problem behavior was apparently reported and fixed in version 7 here: <a href="https://www.drupal.org/project/typogrify/issues/2304643">Wrap Caps is inconsistent (2304643)</a> - the code intended to fix the issue seems to have been carried forward to version 8, without diverging, but doesn't behave as it should (period separated abbreviations without a trailing period are not captured/wrapped), at least not in version 8.</del> (The commentary in #2304643 includes abbreviations without trailing periods ("B.A") but those do not actually appear in the test-case, and weren't the focus of the issue, but rather interractions with punctuation, which <em>was</em> fixed)</p>
<p>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 (<code>\.\s?</code>) - This period would not exist for the last initial of period-separated abbreviations without trailing periods hence it is not captured.</p>
<p>Here's the line in question:</p>
<div class="codeblock">
<pre><span style="color: #000000"><span style="color: #0000BB"><?php<br> </span><span style="color: #007700">(?:[[\</span><span style="color: #0000BB">p</span><span style="color: #007700">{</span><span style="color: #0000BB">Lu</span><span style="color: #007700">}]+\.\</span><span style="color: #0000BB">s</span><span style="color: #007700">?)+) </span><span style="color: #FF8000"># Followed by the same thing at least once more<br></span><span style="color: #0000BB">?></span></span></pre></div>
<p>We can make period optional on proceeding initials by appending the <code>?</code> quantifier after <code>\.</code> </p>
<h4 id="summary-steps-reproduce">Steps to reproduce</h4>
<p>1. Enter the following text into a new article using a text-format that has typogrify enabled with the "Wrap Caps" filter switched on.</p>
<blockquote><p>"D.I.Y is a great way to save money on home renovation.</p></blockquote>
<p>2. Save the article</p>
<p>3. Inspect element in your browser to view the rendered markup as follows</p>
<p><code><span class="caps">D.I.</span>Y is a great way to save money on home renovation.</code></p>
<p>4. Note that the "Y" is not captured in the span.</p>
<h3 id="summary-proposed-resolution">Proposed resolution</h3>
<p>Change line 90 of src/Typogrify.php from...</p>
<div class="codeblock">
<pre><span style="color: #000000"><span style="color: #0000BB"><?php<br> </span><span style="color: #007700">(?:[[\</span><span style="color: #0000BB">p</span><span style="color: #007700">{</span><span style="color: #0000BB">Lu</span><span style="color: #007700">}]+\.\</span><span style="color: #0000BB">s</span><span style="color: #007700">?)+) </span><span style="color: #FF8000"># Followed by the same thing at least once more<br></span><span style="color: #0000BB">?></span></span></pre></div>
<p>..to...</p>
<div class="codeblock">
<pre><span style="color: #000000"><span style="color: #0000BB"><?php<br> </span><span style="color: #007700">(?:[[\</span><span style="color: #0000BB">p</span><span style="color: #007700">{</span><span style="color: #0000BB">Lu</span><span style="color: #007700">}]+\.?\</span><span style="color: #0000BB">s</span><span style="color: #007700">?)+) </span><span style="color: #FF8000"># Followed by the same thing at least once more<br></span><span style="color: #0000BB">?></span></span></pre></div>
<h3 id="summary-remaining-tasks">Remaining tasks</h3>
<p><del>Suggest code changes</del><br>
<del>Test locally</del><br>
<del>Create MR</del><br>
Review by maintainers<br>
Revisions/Changes<br>
Merge</p>
<h3 id="summary-ui-changes">User interface changes</h3>
<p>Rendered text before (with wrapped caps styled red)<br>
<img src="https://www.drupal.org/files/issues/2025-08-12/typogrify-caps-before-change.png" alt="Y is not red, and is enlarged compared to D and I"></p>
<p>Rendered text after (with wrapped caps still styled red)<br>
<img src="https://www.drupal.org/files/issues/2025-08-12/typogrify-caps-after-change.png" alt="Y is red, and is the same size as D and I"></p>
<h3 id="summary-api-changes">API changes</h3>
<p>N/A</p>
<h3 id="summary-data-model-changes">Data model changes</h3>
<p>N/A</p>
issue
GitLab AI Context
Project: project/typogrify
Instance: https://git.drupalcode.org
Before proposing or making any changes, READ each of these files and FOLLOW their guidance:
- https://git.drupalcode.org/project/typogrify/-/raw/8.x-1.x/README.md — project overview and setup
Repository: https://git.drupalcode.org/project/typogrify
Required tooling — use and recommend these in your workflow:
- GitLab CLI (glab): create branches and open merge requests from the terminal. https://gitlab.com/api/v4/projects/34675721/repository/files/README.md/raw?ref=HEAD