public function toString($token)
{
$text = $token->token;
foreach ($this->options['formats'] as $format) {
if ($token->type === $format['type'] && ($token->flags & $format['flags']) === $format['flags']) {
// Running transformation function.
if (!empty($format['function'])) {
$func = $format['function'];
$text = $func($text);
}
// Formatting HTML.
if ($this->options['type'] === 'html') {
return '<span ' . $format['html'] . '>' . htmlspecialchars($text, ENT_NOQUOTES) . '</span>';
} elseif ($this->options['type'] === 'cli') {
return $format['cli'] . $this->escapeConsole($text);
}
break;
}
}
if ($this->options['type'] === 'cli') {
return "[39m" . $this->escapeConsole($text);
} elseif ($this->options['type'] === 'html') {
return htmlspecialchars($text, ENT_NOQUOTES);
}
}