Anchor texturize to shortcodes to improve regex efficiency.
Merges [30452] to the 3.7 branch. props miqrogroove. see #29557 for segfault issues. Built from https://develop.svn.wordpress.org/branches/3.7@30456 git-svn-id: http://core.svn.wordpress.org/branches/3.7@30447 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
1e0faa77d3
commit
0c8039be21
|
@ -107,7 +107,14 @@ function wptexturize($text) {
|
|||
$no_texturize_tags_stack = array();
|
||||
$no_texturize_shortcodes_stack = array();
|
||||
|
||||
$textarr = preg_split('/(<.*>|\[.*\])/Us', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
|
||||
// Look for shortcodes and HTML elements.
|
||||
|
||||
$shortcode_regex =
|
||||
'\[' // Find start of shortcode.
|
||||
. '[^\[\]<>]++' // Shortcodes do not contain other shortcodes. Possessive critical.
|
||||
. '\]'; // Find end of shortcode.
|
||||
|
||||
$textarr = preg_split("/(<[^>]*>|$shortcode_regex)/s", $text, -1, PREG_SPLIT_DELIM_CAPTURE);
|
||||
|
||||
foreach ( $textarr as &$curl ) {
|
||||
if ( empty( $curl ) )
|
||||
|
@ -117,7 +124,7 @@ function wptexturize($text) {
|
|||
$first = $curl[0];
|
||||
if ( '<' === $first ) {
|
||||
_wptexturize_pushpop_element($curl, $no_texturize_tags_stack, $no_texturize_tags, '<', '>');
|
||||
} elseif ( '[' === $first ) {
|
||||
} elseif ( '[' === $first && 1 === preg_match( '/^' . $shortcode_regex . '$/', $curl ) ) {
|
||||
_wptexturize_pushpop_element($curl, $no_texturize_shortcodes_stack, $no_texturize_shortcodes, '[', ']');
|
||||
} elseif ( empty($no_texturize_shortcodes_stack) && empty($no_texturize_tags_stack) ) {
|
||||
// This is not a tag, nor is the texturization disabled static strings
|
||||
|
@ -158,6 +165,8 @@ function _wptexturize_pushpop_element($text, &$stack, $disabled_elements, $openi
|
|||
|
||||
array_push($stack, $matches[1]);
|
||||
}
|
||||
} elseif ( 0 == count( $stack ) ) {
|
||||
// Stack is empty. Just stop.
|
||||
} else {
|
||||
// Closing? Check $text+2 against disabled elements
|
||||
$c = preg_quote($closing, '/');
|
||||
|
|
Loading…
Reference in New Issue