X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/9e77185fafaf4e60e2b73821e0e4b9b1a11fb85f..f5fcdc7994bb67cce809bc4777944ae8b7fad4a4:/wp-includes/formatting.php diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php index 1f18ab9d..0151e1fc 100644 --- a/wp-includes/formatting.php +++ b/wp-includes/formatting.php @@ -11,13 +11,13 @@ * Replaces common plain text characters into formatted entities * * As an example, - * - * 'cause today's effort makes it worth tomorrow's "holiday"... - * + * + * 'cause today's effort makes it worth tomorrow's "holiday" ... + * * Becomes: - * - * ’cause today’s effort makes it worth tomorrow’s “holiday”… - * + * + * ’cause today’s effort makes it worth tomorrow’s “holiday” … + * * Code within certain html blocks are skipped. * * @since 0.71 @@ -28,7 +28,7 @@ * @return string The string replaced with html entities */ function wptexturize($text, $reset = false) { - global $wp_cockneyreplace; + global $wp_cockneyreplace, $shortcode_tags; static $static_characters, $static_replacements, $dynamic_characters, $dynamic_replacements, $default_no_texturize_tags, $default_no_texturize_shortcodes, $run_texturize = true; @@ -86,11 +86,11 @@ function wptexturize($text, $reset = false) { // if a plugin has provided an autocorrect array, use it if ( isset($wp_cockneyreplace) ) { - $cockney = array_keys($wp_cockneyreplace); - $cockneyreplace = array_values($wp_cockneyreplace); + $cockney = array_keys( $wp_cockneyreplace ); + $cockneyreplace = array_values( $wp_cockneyreplace ); } elseif ( "'" != $apos ) { // Only bother if we're doing a replacement. - $cockney = array( "'tain't", "'twere", "'twas", "'tis", "'twill", "'til", "'bout", "'nuff", "'round", "'cause" ); - $cockneyreplace = array( $apos . "tain" . $apos . "t", $apos . "twere", $apos . "twas", $apos . "tis", $apos . "twill", $apos . "til", $apos . "bout", $apos . "nuff", $apos . "round", $apos . "cause" ); + $cockney = array( "'tain't", "'twere", "'twas", "'tis", "'twill", "'til", "'bout", "'nuff", "'round", "'cause", "'em" ); + $cockneyreplace = array( $apos . "tain" . $apos . "t", $apos . "twere", $apos . "twas", $apos . "tis", $apos . "twill", $apos . "til", $apos . "bout", $apos . "nuff", $apos . "round", $apos . "cause", $apos . "em" ); } else { $cockney = $cockneyreplace = array(); } @@ -174,9 +174,9 @@ function wptexturize($text, $reset = false) { // Dashes and spaces $dynamic[ '/---/' ] = $em_dash; - $dynamic[ '/(?<=' . $spaces . ')--(?=' . $spaces . ')/' ] = $em_dash; + $dynamic[ '/(?<=^|' . $spaces . ')--(?=$|' . $spaces . ')/' ] = $em_dash; $dynamic[ '/(?' // Find end of comment - . '|' - . '[^>]+>' // Find end of element - . ')' + $tagnames = array_keys( $shortcode_tags ); + $tagregexp = join( '|', array_map( 'preg_quote', $tagnames ) ); + $tagregexp = "(?:$tagregexp)(?![\\w-])"; // Excerpt of get_shortcode_regex(). + + $comment_regex = + '!' // Start of comment, after the <. + . '(?:' // Unroll the loop: Consume everything until --> is found. + . '-(?!->)' // Dash not followed by end of comment. + . '[^\-]*+' // Consume non-dashes. + . ')*+' // Loop possessively. + . '(?:-->)?'; // End of comment. If not found, match all input. + + $shortcode_regex = + '\[' // Find start of shortcode. + . '[\/\[]?' // Shortcodes may begin with [/ or [[ + . $tagregexp // Only match registered shortcodes, because performance. + . '(?:' + . '[^\[\]<>]+' // Shortcodes do not contain other shortcodes. Quantifier critical. + . '|' + . '<[^\[\]>]*>' // HTML elements permitted. Prevents matching ] before >. + . ')*+' // Possessive critical. + . '\]' // Find end of shortcode. + . '\]?'; // Shortcodes may end with ]] + + $regex = + '/(' // Capture the entire match. + . '<' // Find start of element. + . '(?(?=!--)' // Is this a comment? + . $comment_regex // Find end of comment. + . '|' + . '[^>]*>' // Find end of element. + . ')' . '|' - . '\[' // Find start of shortcode. - . '\[?' // Shortcodes may begin with [[ - . '(?:' - . '[^\[\]<>]' // Shortcodes do not contain other shortcodes. - . '|' - . '<[^>]+>' // HTML elements permitted. Prevents matching ] before >. - . ')++' - . '\]' // Find end of shortcode. - . '\]?' // Shortcodes may end with ]] + . $shortcode_regex // Find shortcodes. . ')/s'; $textarr = preg_split( $regex, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY ); @@ -229,30 +246,31 @@ function wptexturize($text, $reset = false) { foreach ( $textarr as &$curl ) { // Only call _wptexturize_pushpop_element if $curl is a delimiter. $first = $curl[0]; - if ( '<' === $first && '>' === substr( $curl, -1 ) ) { - // This is an HTML delimiter. + if ( '<' === $first && ' " ) ); + + // Collapse line breaks before and after ', $pee ); } + /* + * Collapse line breaks inside elements, before and elements + * so they don't get autop'd. + */ if ( strpos( $pee, '' ) !== false ) { - // no P/BR around param and embed $pee = preg_replace( '|(]*>)\s*|', '$1', $pee ); $pee = preg_replace( '|\s*|', '', $pee ); $pee = preg_replace( '%\s*(]*>)\s*%', '$1', $pee ); } + /* + * Collapse line breaks inside