/** * Convert the token * * @param \Zend\Markup\Token $token * @param string $text * * @return string */ public function __invoke(Token $token, $text) { if ($token->hasAttribute('url')) { $uri = $token->getAttribute('url'); } else { $uri = $text; } if (!preg_match('/^([a-z][a-z+\-.]*):/i', $uri)) { $uri = 'http://' . $uri; } // check if the URL is valid // TODO: re-implement this (probably with the new \Zend\Uri) //if (!\Zend\Markup\Renderer\Html::isValidUri($uri)) { // return $text; //} $attributes = $this->renderAttributes($token); // run the URI through htmlentities $uri = htmlentities($uri, ENT_QUOTES, $this->getEncoding()); return "<a href=\"{$uri}\"{$attributes}>{$text}</a>"; }
/** * Convert the token * * @param \Zend\Markup\Token $token * @param string $text * * @return string */ public function __invoke(Token $token, $text) { $uri = $text; if (!preg_match('/^([a-z][a-z+\\-.]*):/i', $uri)) { $uri = 'http://' . $uri; } // check if the URL is valid // TODO: use \Zend\Uri for this if (!\Zend\Markup\Renderer\HTML::isValidUri($uri)) { return $text; } if ($token->hasAttribute('alt')) { $alt = $token->getAttribute('alt'); } else { // try to get the alternative from the URL $alt = rtrim($text, '/'); $alt = strrchr($alt, '/'); if (false !== strpos($alt, '.')) { $alt = substr($alt, 1, strpos($alt, '.') - 1); } } // run the URI and alt through htmlentities $uri = htmlentities($uri, ENT_QUOTES, $this->getEncoding()); $alt = htmlentities($alt, ENT_QUOTES, $this->getEncoding()); return "<img src=\"{$uri}\" alt=\"{$alt}\"" . $this->renderAttributes($token) . " />"; }
/** * Convert the token * * @param \Zend\Markup\Token $token * @param string $text * * @return string */ public function __invoke(Markup\Token $token, $text) { $type = null; if ($token->hasAttribute('list')) { // because '01' == '1' if ($token->getAttribute('list') === '01') { $type = 'decimal-leading-zero'; } else { switch ($token->getAttribute('list')) { case '1': $type = 'decimal'; break; case 'i': $type = 'lower-roman'; break; case 'I': $type = 'upper-roman'; break; case 'a': $type = 'lower-alpha'; break; case 'A': $type = 'upper-alpha'; break; // the following type is unsupported by IE (including IE8) case 'alpha': $type = 'lower-greek'; break; // the CSS names itself case 'armenian': // unsupported by IE (including IE8) case 'decimal': case 'decimal-leading-zero': // unsupported by IE (including IE8) case 'georgian': // unsupported by IE (including IE8) case 'lower-alpha': case 'lower-greek': // unsupported by IE (including IE8) case 'lower-latin': // unsupported by IE (including IE8) case 'lower-roman': case 'upper-alpha': case 'upper-latin': // unsupported by IE (including IE8) case 'upper-roman': $type = $token->getAttribute('list'); break; } } } if (null !== $type) { return "<ol style=\"list-style-type: {$type}\">{$text}</ol>"; } else { return "<ul>{$text}</ul>"; } }