Changeset 11345 for trunk/wp-includes/formatting.php
- Timestamp:
- 05/15/2009 09:37:18 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/formatting.php
r11338 r11345 29 29 function wptexturize($text) { 30 30 global $wp_cockneyreplace; 31 $next = true;32 $has_pre_parent = false;33 31 $output = ''; 34 32 $curl = ''; 35 33 $textarr = preg_split('/(<.*>|\[.*\])/Us', $text, -1, PREG_SPLIT_DELIM_CAPTURE); 36 34 $stop = count($textarr); 35 $no_texturize_tags = apply_filters('no_texturize_tags', array('pre', 'code', 'kbd', 'style', 'script', 'tt')); 36 $no_texturize_shortcodes = apply_filters('no_texturize_shortcodes', array('code')); 37 $no_texturize_tags_stack = array(); 38 $no_texturize_shortcodes_stack = array(); 37 39 38 40 // if a plugin has provided an autocorrect array, use it … … 54 56 $curl = $textarr[$i]; 55 57 56 if ( !empty($curl) && '<' != $curl{0} && '[' != $curl{0} && $next && !$has_pre_parent) { // If it's not a tag 58 if ( !empty($curl) && '<' != $curl{0} && '[' != $curl{0} 59 && empty($no_texturize_shortcodes_stack) && empty($no_texturize_tags_stack)) { // If it's not a tag 57 60 // static strings 58 61 $curl = str_replace($static_characters, $static_replacements, $curl); 59 62 // regular expressions 60 63 $curl = preg_replace($dynamic_characters, $dynamic_replacements, $curl); 61 } elseif (strpos($curl, '<tt') !== false || strpos($curl, '<code') !== false || strpos($curl, '<kbd') !== false || strpos($curl, '<style') !== false || strpos($curl, '<script') !== false) {62 $next = false;63 } elseif (strpos($curl, '<pre') !== false) {64 $has_pre_parent = true;65 } elseif (strpos($curl, '</pre>') !== false) {66 $has_pre_parent = false;67 64 } else { 68 $next = true; 65 wptexturize_pushpop_element($curl, $no_texturize_tags_stack, $no_texturize_tags, '<', '>'); 66 wptexturize_pushpop_element($curl, $no_texturize_shortcodes_stack, $no_texturize_shortcodes, '[', ']'); 69 67 } 70 68 … … 74 72 75 73 return $output; 74 } 75 76 function wptexturize_pushpop_element($text, &$stack, $disabled_elements, $opening = '<', $closing = '>') { 77 $o = preg_quote($opening); 78 $c = preg_quote($closing); 79 foreach($disabled_elements as $element) { 80 if (preg_match('/^'.$o.$element.'\b/', $text)) array_push($stack, $element); 81 if (preg_match('/^'.$o.'\/'.$element.$c.'/', $text)) { 82 $last = array_pop($stack); 83 // disable texturize until we find a closing tag of our type (e.g. <pre>) 84 // even if there was invalid nesting before that 85 // Example: in the case <pre>sadsadasd</code>"baba"</pre> "baba" won't be texturized 86 if ($last != $element) array_push($stack, $last); 87 } 88 } 76 89 } 77 90
Note: See TracChangeset
for help on using the changeset viewer.