Ticket #2713: detexturize_patch.diff

File detexturize_patch.diff, 1.6 KB (added by n8v, 6 years ago)
  • functions-formatting.php

     
    33function wptexturize($text) { 
    44        $output = ''; 
    55        // Capture tags and everything inside them 
    6         $textarr = preg_split("/(<.*>)/Us", $text, -1, PREG_SPLIT_DELIM_CAPTURE); 
    7         $stop = count($textarr); $next = true; // loop stuff 
     6        $textarr = preg_split("/(<[^>]+>)/Us", $text, -1, PREG_SPLIT_DELIM_CAPTURE); 
     7        $stop = count($textarr); $skip = false; // loop stuff 
     8         
    89        for ($i = 0; $i < $stop; $i++) { 
    910                $curl = $textarr[$i]; 
     11                $matches = Array(); 
    1012 
    11                 if (isset($curl{0}) && '<' != $curl{0} && $next) { // If it's not a tag 
     13                if (! $skip && isset($curl{0}) && '<' != $curl{0}) { // If it's not a tag 
    1214                        $curl = str_replace('---', '&#8212;', $curl); 
    1315                        $curl = str_replace(' -- ', ' &#8212; ', $curl); 
    1416                        $curl = str_replace('--', '&#8211;', $curl); 
     
    3537 
    3638                        $curl = preg_replace('/(\d+)x(\d+)/', "$1&#215;$2", $curl); 
    3739 
    38                 } elseif (strstr($curl, '<code') || strstr($curl, '<pre') || strstr($curl, '<kbd' || strstr($curl, '<style') || strstr($curl, '<script'))) { 
    39                         // strstr is fast 
    40                         $next = false; 
    41                 } else { 
    42                         $next = true; 
     40                }  
     41                // skip anything inside these tags 
     42                elseif (! $skip && preg_match('/^<(code|pre|kbd|style|script|samp)/i', $curl, $matches) ) { 
     43                  $skip = $matches[1]; 
    4344                } 
     45                elseif ($skip && preg_match("/^<\/$skip/i", $curl)) { 
     46                  $skip = false; 
     47                } 
    4448                $curl = preg_replace('/&([^#])(?![a-zA-Z1-4]{1,8};)/', '&#038;$1', $curl); 
    4549                $output .= $curl; 
    4650        }