function convert_characters in Typogrify 7
Same name and namespace in other branches
- 5 unicode-conversion.php \convert_characters()
- 6 unicode-conversion.php \convert_characters()
Perform character conversion.
Parameters
string $text: 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 101 - Return the unicode conversion maps.
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 = '';
// Keep track of when we're inside <pre> or <code> tags.
$in_pre = 0;
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;
}