/**
  * Builder of HTML tags :
  *     <TAG ATTR1="ATTR_VAL1" ... > TEXT </TAG>
  *
  * @param string $text The content of the tag
  * @param string $tag The tag name
  * @param array $attributes An array of attributes constructed by "variable=>value" pairs
  * @param bool $close Is it a closed tag ? (FALSE by default)
  *
  * @return string The built tag string
  */
 public function getTagString($text, $tag, array $attributes = array(), $close = false)
 {
     $attr = '';
     $prefix = '';
     if (!empty($attributes)) {
         if (isset($attributes['mde-prefix'])) {
             $prefix = $attributes['mde-prefix'];
             unset($attributes['mde-prefix']);
         }
         foreach ($attributes as $variable => $value) {
             $value = Helper::getSafeString($value);
             if (!empty($value)) {
                 if (is_string($variable)) {
                     $attr .= " {$variable}=\"{$value}\"";
                 } else {
                     $attr .= ' ' . trim($value);
                 }
             }
         }
     }
     if (true === $close) {
         return $prefix . "<{$tag}{$attr}" . $this->empty_element_suffix;
     } else {
         return $prefix . "<{$tag}{$attr}>{$text}</{$tag}>";
     }
 }
 /**
  * Gets the array of parameters to pass in the template based on a content object
  *
  * @param \MarkdownExtended\API\ContentInterface $content
  *
  * @return array
  *
  * @throws \MarkdownExtended\Exception\UnexpectedValueException if a keyword can not be found in the content object
  */
 public function getParams(ContentInterface $content)
 {
     $params = array();
     $keywords = $this->config->get('keywords');
     // all options keywords
     foreach ($keywords as $var => $word) {
         $mask = $this->_buildKeywordMask($word);
         $method = 'get' . Helper::toCamelCase($var);
         if (!method_exists($content, $method)) {
             throw new UnexpectedValueException(sprintf('Template keyword "%s" not found in content', $var));
         }
         $method_tostring = $method . 'Formatted';
         $params[$mask] = function () use($content, $method, $method_tostring) {
             return call_user_func(array($content, method_exists($content, $method_tostring) ? $method_tostring : $method));
         };
     }
     // all metadata: META:name
     $meta = $content->getMetadata();
     if (!empty($meta) && isset($keywords['metadata'])) {
         foreach ($meta as $name => $value) {
             $mask = $this->_buildKeywordMask($keywords['metadata'] . ':' . $name);
             $params[$mask] = function () use($value) {
                 return Helper::getSafeString($value);
             };
         }
     }
     return $params;
 }
 public function buildMetaData($text = null, array $attributes = array())
 {
     $text = $this->escapeString($text);
     if (!empty($attributes['name'])) {
         if (empty($attributes['content']) && !empty($text)) {
             $attributes['content'] = $text;
         }
         return '.\\" ' . $attributes['name'] . ': ' . Helper::getSafeString($attributes['content']);
     }
     return '.\\" ' . $text;
 }
 /**
  * Renders results in plain text format
  */
 protected function renderOutputPlain()
 {
     $results = $this->getResults();
     foreach ($results as $i => $result) {
         if (count($results) > 1) {
             $this->stream->writeln("==> {$i} <==");
         }
         $this->stream->write(Helper::getSafeString($result));
     }
     $this->stream->_exit();
 }