You are here

function convert_characters in Typogrify 6

Same name and namespace in other branches
  1. 5 unicode-conversion.php \convert_characters()
  2. 7 unicode-conversion.php \convert_characters()

Perform character conversion.

Parameters

string $test: Text to be parsed.

array $characters_to_convert: Array of ASCII characters to convert.

Return value

string The result of the conversion.

1 call to convert_characters()
_typogrify_process in ./typogrify.module
Processing function to apply the Typogrify filters

File

./unicode-conversion.php, line 70

Code

function convert_characters($text, $characters_to_convert) {
  if ($characters_to_convert == NULL || count($characters_to_convert) < 1) {

    // do nothing
    return $text;
  }

  // get ascii to unicode mappings
  $unicode_map = unicode_conversion_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
      if (preg_match(SMARTYPANTS_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;
}