-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Formatting: Treat quotes immediately after closing inline tags as closing #12249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dknauss
wants to merge
2
commits into
WordPress:trunk
Choose a base branch
from
dknauss:fix/18549-inline-quote-context
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+154
−2
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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, '<!--' ) ) { | ||
| // This is an HTML comment delimiter. | ||
| $quote_after_inline_tag = false; | ||
| continue; | ||
| } else { | ||
| // This is an HTML element delimiter. | ||
| $quote_after_inline_tag = $last_text_ends_with_quote_context && _wptexturize_is_inline_closing_tag( $curl ); | ||
|
|
||
| // Replace each & with & unless it already looks like an entity. | ||
| $curl = preg_replace( '/&(?!#(?:\d+|x[a-f0-9]+);|[a-z1-4]{1,8};)/i', '&', $curl ); | ||
|
|
@@ -257,9 +261,11 @@ function wptexturize( $text, $reset = false ) { | |
| } | ||
| } elseif ( '' === trim( $curl ) ) { | ||
| // This is a newline between delimiters. Performance improves when we check this. | ||
| $quote_after_inline_tag = false; | ||
| continue; | ||
|
|
||
| } elseif ( '[' === $first && $found_shortcodes && 1 === preg_match( '/^' . $shortcode_regex . '$/', $curl ) ) { | ||
| $quote_after_inline_tag = false; | ||
| // This is a shortcode delimiter. | ||
|
|
||
| if ( ! str_starts_with( $curl, '[[' ) && ! str_ends_with( $curl, ']]' ) ) { | ||
|
|
@@ -274,6 +280,15 @@ function wptexturize( $text, $reset = false ) { | |
|
|
||
| $curl = str_replace( $static_characters, $static_replacements, $curl ); | ||
|
|
||
| if ( $quote_after_inline_tag ) { | ||
| if ( preg_match( "/^'[\p{L}\p{N}\p{Po}\p{Pf}\s.,;:!?\)\}\-&]|^'$/u", $curl ) ) { | ||
| $curl = $apos . substr( $curl, 1 ); | ||
| } elseif ( preg_match( '/^"[\p{L}\p{N}\p{Po}\p{Pf}\s.,;:!?\)\}\-&]|^"$/u', $curl ) ) { | ||
| $curl = $closing_quote . substr( $curl, 1 ); | ||
| } | ||
| } | ||
| $quote_after_inline_tag = false; | ||
|
|
||
| if ( str_contains( $curl, "'" ) ) { | ||
| $curl = preg_replace( $dynamic_characters['apos'], $dynamic_replacements['apos'], $curl ); | ||
| $curl = wptexturize_primes( $curl, "'", $prime, $open_sq_flag, $closing_single_quote ); | ||
|
|
@@ -297,12 +312,96 @@ function wptexturize( $text, $reset = false ) { | |
|
|
||
| // Replace each & with & unless it already looks like an entity. | ||
| $curl = preg_replace( '/&(?!#(?:\d+|x[a-f0-9]+);|[a-z1-4]{1,8};)/i', '&', $curl ); | ||
|
|
||
| $last_text_ends_with_quote_context = _wptexturize_text_ends_with_quote_context( $curl ); | ||
| } else { | ||
| $quote_after_inline_tag = false; | ||
| } | ||
| } | ||
|
|
||
| return implode( '', $textarr ); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| /** | ||
| * Determines whether text ends with a character that can provide quote context. | ||
| * | ||
| * This avoids running a Unicode regular expression for every text token in | ||
| * 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 | ||
| * | ||
| * @param string $text Text token from wptexturize(). | ||
| * @return bool Whether the text ends with quote context. | ||
| */ | ||
| function _wptexturize_text_ends_with_quote_context( $text ) { | ||
| if ( '' === $text ) { | ||
| return false; | ||
| } | ||
|
|
||
| $last_character = substr( $text, -1 ); | ||
|
|
||
| if ( ctype_alnum( $last_character ) || in_array( $last_character, array( '.', '!', '?', ')' ), true ) ) { | ||
| return true; | ||
| } | ||
|
|
||
| if ( ';' === $last_character ) { | ||
| return (bool) preg_match( '/&#(?:8217|8221);$/', $text ); | ||
| } | ||
|
|
||
| if ( ord( $last_character ) >= 0x80 ) { | ||
| return (bool) preg_match( '/[\p{L}\p{N}]$/u', $text ); | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| /** | ||
| * Determines whether a token is a closing tag for a common inline HTML element. | ||
| * | ||
| * @since 7.0.0 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
| * | ||
| * @param string $text A token from wptexturize()'s split input. | ||
| * @return bool Whether the token is a closing inline HTML element. | ||
| */ | ||
| function _wptexturize_is_inline_closing_tag( $text ) { | ||
| if ( ! preg_match( '/^<\/([a-z][a-z0-9]*)\s*>$/i', $text, $matches ) ) { | ||
| return false; | ||
| } | ||
|
|
||
| $inline_tags = array( | ||
| 'a', | ||
| 'abbr', | ||
| 'b', | ||
| 'bdi', | ||
| 'bdo', | ||
| 'cite', | ||
| 'data', | ||
| 'del', | ||
| 'dfn', | ||
| 'em', | ||
| 'i', | ||
| 'ins', | ||
| 'label', | ||
| 'mark', | ||
| 'q', | ||
| 's', | ||
| 'samp', | ||
| 'small', | ||
| 'span', | ||
| 'strong', | ||
| 'sub', | ||
| 'sup', | ||
| 'time', | ||
| 'u', | ||
| 'var', | ||
| ); | ||
|
|
||
| return in_array( strtolower( $matches[1] ), $inline_tags, true ); | ||
| } | ||
|
|
||
| /** | ||
| * Implements a logic tree to determine whether or not "7'." represents seven feet, | ||
| * then converts the special char into either a prime char or a closing quote char. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.