X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/5d244c8fd9a27c9f89dd08da2af6fbc67d4fce63..f5fcdc7994bb67cce809bc4777944ae8b7fad4a4:/wp-includes/formatting.php diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php index 7bd354af..0151e1fc 100644 --- a/wp-includes/formatting.php +++ b/wp-includes/formatting.php @@ -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 element. + . '[^>]*>' // Find end of element. . ')' . '|' . $shortcode_regex // Find shortcodes. @@ -360,14 +360,14 @@ function _wptexturize_pushpop_element($text, &$stack, $disabled_elements) { * Replaces double line-breaks with paragraph elements. * * A group of regex replaces used to identify text formatted with newlines and - * replace double line-breaks with HTML paragraph tags. The remaining - * line-breaks after conversion become <
> tags, unless $br is set to '0' - * or 'false'. + * replace double line-breaks with HTML paragraph tags. The remaining line-breaks + * after conversion become <
> tags, unless $br is set to '0' or 'false'. * * @since 0.71 * * @param string $pee The text which has to be formatted. - * @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true. + * @param bool $br Optional. If set, this will convert all remaining line-breaks + * after paragraphing. Default true. * @return string Text which has been converted into correct paragraph tags. */ function wpautop($pee, $br = true) { @@ -376,8 +376,13 @@ function wpautop($pee, $br = true) { if ( trim($pee) === '' ) return ''; - $pee = $pee . "\n"; // just to make things a little easier, pad the end + // Just to make things a little easier, pad the end. + $pee = $pee . "\n"; + /* + * Pre tags shouldn't be touched by autop. + * Replace pre tags with placeholders and bring them back after autop. + */ if ( strpos($pee, '', $pee ); $last_pee = array_pop($pee_parts); @@ -402,68 +407,211 @@ function wpautop($pee, $br = true) { $pee .= $last_pee; } - + // Change multiple
s into two line breaks, which will turn into paragraphs. $pee = preg_replace('|
\s*
|', "\n\n", $pee); - // Space things out a little - $allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|legend|section|article|aside|hgroup|header|footer|nav|figure|details|menu|summary)'; + + $allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)'; + + // Add a single line break above block-level opening tags. $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n$1", $pee); + + // Add a double line break below block-level closing tags. $pee = preg_replace('!()!', "$1\n\n", $pee); - $pee = str_replace(array("\r\n", "\r"), "\n", $pee); // cross-platform newlines + // Standardize newline characters to "\n". + $pee = str_replace(array("\r\n", "\r"), "\n", $pee); + + // Find newlines in all elements and add placeholders. + $pee = wp_replace_in_html_tags( $pee, array( "\n" => " " ) ); + + // 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