Skip to content

Formatting: Treat quotes immediately after closing inline tags as closing#12249

Open
dknauss wants to merge 2 commits into
WordPress:trunkfrom
dknauss:fix/18549-inline-quote-context
Open

Formatting: Treat quotes immediately after closing inline tags as closing#12249
dknauss wants to merge 2 commits into
WordPress:trunkfrom
dknauss:fix/18549-inline-quote-context

Conversation

@dknauss

@dknauss dknauss commented Jun 21, 2026

Copy link
Copy Markdown

Trac ticket: https://core.trac.wordpress.org/ticket/18549

What

wptexturize() curls a straight quote/apostrophe to an opening quote when it immediately follows a closing inline tag, because it has lost the word context across the tag boundary:

  • <strong>He</strong>'s here.…</strong>&#8216;s (should be &#8217;s)
  • The word is '<a href="…">quoted</a>' → trailing &#8216; (should be &#8217;)
Screenshot 2026-06-20 at 7 25 39 PM

How

Keeps the existing tokenizer and adds a small amount of cross-token state: when a quote token immediately follows a closing inline tag and the preceding text ended in a word/sentence/closing-quote context, the quote is classified as closing. The historical strip/format/reinsert replacement engine is intentionally not revived. A fast-path helper keeps the common case off the per-token Unicode regex.

Scope / deliberate choices

  • A space before the quote keeps normal opening-quote behavior (<strong>He</strong> 'go' stays &#8216;go&#8217;).
  • Excludes kbd (already a no-texturize tag), deprecated acronym, and ] from the trailing-context class (including ] changed the existing "crazy" shortcode fixture, so current behavior is preserved).
  • Out of scope: the quote-inside-quote behavior tracked in Trac #29882.

Testing

Adds four methods to Tests_Formatting_wpTexturize covering the original report's quote-around-inline-HTML cases, the later data_inline_end_tags cases (including two the old engine marked unfixable), and the modern apostrophe case. Full focused class is green on current trunk:

OK (361 tests, 469 assertions)

PHPCS is clean against the WordPress-Core ruleset (phpcs.xml.dist).

A minimal apostrophe-only variant exists if maintainers prefer a narrower first step.

History

See WordPress/gutenberg#42345, which was closed correctly as a core wptexturize() issue reported in Trac #18549. I've added a comprehensive revival comment there in Trac with a diff that's the same code in this PR.


Developed with AI assistance (Anthropic Claude via Claude Code, and OpenAI Codex) under human review.

…sing.

wptexturize() loses word context across an inline HTML tag boundary, so a straight
quote or apostrophe immediately after a closing inline element (for example
<strong>He</strong>'s or '<a>quoted</a>') is curled as an opening quote. Track
whether the preceding text ended in a word, sentence, or closing-quote context, and
for a quote immediately following a closing inline tag, classify it as a closing
quote or apostrophe. A space before the quote keeps normal opening-quote behavior.

Keep the existing tokenizer; do not revive the historical strip/format/reinsert
replacement engine (the long-standing performance concern). A fast-path helper keeps
the common case off the per-token Unicode-regex path.

Add coverage to Tests_Formatting_wpTexturize for the original report's
quote-around-inline-HTML cases, the later data_inline_end_tags cases, and the modern
apostrophe case from WordPress/gutenberg#42345.

Developed with AI assistance (Anthropic Claude via Claude Code, and OpenAI Codex)
under maintainer review.

See #18549.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: OpenAI Codex <noreply@openai.com>
@github-actions

Copy link
Copy Markdown

Hi there! 👋

Thank you for your contribution to WordPress! 💖

It looks like this is your first pull request to wordpress-develop. Here are a few things to be aware of that may help you out!

No one monitors this repository for new pull requests. Pull requests must be attached to a Trac ticket to be considered for inclusion in WordPress Core. To attach a pull request to a Trac ticket, please include the ticket's full URL in your pull request description.

Pull requests are never merged on GitHub. The WordPress codebase continues to be managed through the SVN repository that this GitHub repository mirrors. Please feel free to open pull requests to work on any contribution you are making.

More information about how GitHub pull requests can be used to contribute to WordPress can be found in the Core Handbook.

Please include automated tests. Including tests in your pull request is one way to help your patch be considered faster. To learn about WordPress' test suites, visit the Automated Testing page in the handbook.

If you have not had a chance, please review the Contribute with Code page in the WordPress Core Handbook.

The Developer Hub also documents the various coding standards that are followed:

Thank you,
The WordPress Project

@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props dpknauss.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

* wptexturize(). Most tokens end with ASCII letters, numbers, or punctuation; only
* multibyte text and closing quote entities need a regular expression check.
*
* @since 7.0.0

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be either 7.1.0 or if you are unsure when merged a placeholder.

/**
* Determines whether a token is a closing tag for a common inline HTML element.
*
* @since 7.0.0

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants