Ticket #2713: detexturize_patch.diff
| File detexturize_patch.diff, 1.6 KB (added by n8v, 6 years ago) |
|---|
-
functions-formatting.php
3 3 function wptexturize($text) { 4 4 $output = ''; 5 5 // 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 8 9 for ($i = 0; $i < $stop; $i++) { 9 10 $curl = $textarr[$i]; 11 $matches = Array(); 10 12 11 if ( isset($curl{0}) && '<' != $curl{0} && $next) { // If it's not a tag13 if (! $skip && isset($curl{0}) && '<' != $curl{0}) { // If it's not a tag 12 14 $curl = str_replace('---', '—', $curl); 13 15 $curl = str_replace(' -- ', ' — ', $curl); 14 16 $curl = str_replace('--', '–', $curl); … … 35 37 36 38 $curl = preg_replace('/(\d+)x(\d+)/', "$1×$2", $curl); 37 39 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]; 43 44 } 45 elseif ($skip && preg_match("/^<\/$skip/i", $curl)) { 46 $skip = false; 47 } 44 48 $curl = preg_replace('/&([^#])(?![a-zA-Z1-4]{1,8};)/', '&$1', $curl); 45 49 $output .= $curl; 46 50 }
