Anchor texturize to shortcodes to improve regex efficiency.
For the 3.9 branch; see [30449] for trunk. props miqrogroove. see #29557 for segfault issues. Built from https://develop.svn.wordpress.org/branches/3.9@30452 git-svn-id: http://core.svn.wordpress.org/branches/3.9@30445 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
ca3e6728d1
commit
940eb60ad7
|
@ -152,7 +152,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 ) ) {
|
||||
|
@ -163,7 +170,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) ) {
|
||||
|
||||
|
@ -214,6 +221,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