public static function SmartyPants::smartAbbreviation in Typogrify 8
Wrapping abbreviations and adding half space between digit grouping.
Parameters
string $text: The string to prettify.
int $attr: The kind of space to use.
array $ctx: Not used.
Return value
string The modified text.
1 call to SmartyPants::smartAbbreviation()
- TypogrifyFilter::process in src/
Plugin/ Filter/ TypogrifyFilter.php - Performs the filter processing.
File
- src/
SmartyPants.php, line 805
Class
- SmartyPants
- SmartyPants - Smart punctuation for web sites.
Namespace
Drupal\typogrifyCode
public static function smartAbbreviation($text, $attr = 0, array $ctx = NULL) {
$tokens;
$tokens = self::tokenizeHtml($text);
$replace_method = 'abbrAsis';
if ($attr == 1) {
$replace_method = 'abbrNarrownbsp';
}
elseif ($attr == 2) {
$replace_method = 'abbrThinsp';
}
elseif ($attr == 3) {
$replace_method = 'abbrSpan';
}
$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 quotes inside tags.
$result .= $cur_token[1];
if (preg_match(self::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) {
$abbr_finder = '/(?<=\\s|)(\\p{L}+\\.)(\\p{L}+\\.)+(?=\\s|)/u';
$t = preg_replace_callback($abbr_finder, [
__CLASS__,
$replace_method,
], $t);
}
$result .= $t;
}
}
return $result;
}