public static function UnicodeConversion::convertCharacters in Typogrify 8
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 UnicodeConversion::convertCharacters()
- TypogrifyFilter::process in src/
Plugin/ Filter/ TypogrifyFilter.php - Performs the filter processing.
File
- src/
UnicodeConversion.php, line 102
Class
- UnicodeConversion
- Return the unicode conversion maps.
Namespace
Drupal\typogrifyCode
public static function convertCharacters($text, array $characters_to_convert) {
if ($characters_to_convert == NULL || count($characters_to_convert) < 1) {
// Do nothing.
return $text;
}
// Get ascii to unicode mappings.
$unicode_map = self::map();
foreach ($characters_to_convert as $ascii_string) {
$unicode_strings[] = $unicode_map[$ascii_string];
}
$tokens = SmartyPants::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::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 = SmartyPants::processEscapes($t);
$t = str_replace($characters_to_convert, $unicode_strings, $t);
}
$result .= $t;
}
}
return $result;
}