You are here

function convert_characters in Typogrify 5

Same name and namespace in other branches
  1. 6 unicode-conversion.php \convert_characters()
  2. 7 unicode-conversion.php \convert_characters()
1 call to convert_characters()
_typogrify_process in ./typogrify.module

File

./unicode-conversion.php, line 57

Code

function convert_characters($text, $characters_to_convert) {

  // Paramaters:
  // $text                    text to be parsed
  // $characters_to_convert   array of ascii characters to convert
  if ($characters_to_convert == NULL || count($characters_to_convert) < 1) {

    // do nothing
    return $text;
  }

  // get ascii to unicode mappings
  global $unicode_map;
  foreach ($characters_to_convert as $ascii_string) {
    $unicode_strings[] = $unicode_map[$ascii_string];
  }
  $tokens = _TokenizeHTML($text);
  $result = '';
  $in_pre = 0;

  // Keep track of when we're inside <pre> or <code> tags
  foreach ($tokens as $cur_token) {
    if ($cur_token[0] == "tag") {

      // Don't mess with text inside tags, <pre> blocks, or <code> blocks
      $result .= $cur_token[1];

      // Get the tags to skip regex from SmartyPants
      global $sp_tags_to_skip;
      if (preg_match("@{$sp_tags_to_skip}@", $cur_token[1], $matches)) {
        $in_pre = isset($matches[1]) && $matches[1] == '/' ? 0 : 1;
      }
    }
    else {
      $t = $cur_token[1];
      if ($in_pre == 0) {
        $t = ProcessEscapes($t);
        $t = str_replace($characters_to_convert, $unicode_strings, $t);
      }
      $result .= $t;
    }
  }
  return $result;
}