From d44f503ca61d99cd8ec994dfc093371849c295c6 Mon Sep 17 00:00:00 2001 From: Dan Knauss Date: Sat, 20 Jun 2026 18:28:40 -0600 Subject: [PATCH] Formatting: Treat quotes immediately after closing inline tags as closing. wptexturize() loses word context across an inline HTML tag boundary, so a straight quote or apostrophe immediately after a closing inline element (for example He's or 'quoted') 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 Co-authored-by: OpenAI Codex --- src/wp-includes/formatting.php | 103 +++++++++++++++++- .../phpunit/tests/formatting/wpTexturize.php | 53 +++++++++ 2 files changed, 154 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php index e3681b071a2eb..a9288f65a98c4 100644 --- a/src/wp-includes/formatting.php +++ b/src/wp-includes/formatting.php @@ -227,8 +227,10 @@ function wptexturize( $text, $reset = false ) { */ $no_texturize_shortcodes = apply_filters( 'no_texturize_shortcodes', $default_no_texturize_shortcodes ); - $no_texturize_tags_stack = array(); - $no_texturize_shortcodes_stack = array(); + $no_texturize_tags_stack = array(); + $no_texturize_shortcodes_stack = array(); + $last_text_ends_with_quote_context = false; + $quote_after_inline_tag = false; // Look for shortcodes and HTML elements. @@ -246,9 +248,11 @@ function wptexturize( $text, $reset = false ) { if ( '<' === $first ) { if ( str_starts_with( $curl, '