コード例 #1
0
 /**
  * This will try to call a method `build{TagName}()` if it exists, then will try to use
  * the object `$tags_map` static to automatically find what to do, and then call the
  * default `getTagString()` method passing it the arguments.
  *
  * @param string $tag_name
  * @param string $content
  * @param array $attributes An array of attributes constructed like "variable=>value" pairs
  *
  * @return string
  */
 public function buildTag($tag_name, $content = null, array $attributes = array())
 {
     $_method = 'build' . Helper::toCamelCase($tag_name);
     if (method_exists($this, $_method)) {
         return call_user_func_array(array($this, $_method), array($content, $attributes));
     } else {
         return call_user_func_array(array($this, 'getTagString'), array($content, $tag_name, $attributes));
     }
 }
コード例 #2
0
 /**
  * Loads a new formatter
  *
  * @param   string  $format     The formatter name
  * @throws  \MarkdownExtended\Exception\InvalidArgumentException if the class can not be found
  */
 public function load($format)
 {
     $cls_name = $format;
     if (!class_exists($cls_name)) {
         $cls_name = '\\MarkdownExtended\\OutputFormat\\' . Helper::toCamelCase($format);
     }
     if (!class_exists($cls_name)) {
         throw new InvalidArgumentException(sprintf('Output format "%s" not found', $format));
     }
     $cls = new $cls_name();
     if (Kernel::validate($cls, Kernel::TYPE_OUTPUTFORMAT, $format)) {
         $this->setFormatter($cls);
     }
 }
コード例 #3
0
 /**
  * This will try to call a method `build{TagName}()` if it exists, then will try to use
  * the object `$tags_map` static to automatically find what to do, and then call the
  * default `getTagString()` method passing it the arguments.
  *
  * @param   string  $tag_name
  * @param   string  $content
  * @param   array   $attributes     An array of attributes constructed like "variable=>value" pairs
  *
  * @return  string
  */
 public function buildTag($tag_name, $content = null, array $attributes = array())
 {
     $_method = 'build' . Helper::toCamelCase($tag_name);
     if (isset($this->tags_map[$tag_name]) && isset($this->tags_map[$tag_name]['prefix'])) {
         $attributes['mde-prefix'] = $this->tags_map[$tag_name]['prefix'];
     }
     if (method_exists($this, $_method)) {
         return call_user_func_array(array($this, $_method), array($content, $attributes));
     }
     $closable = false;
     if (isset($this->tags_map[$tag_name])) {
         $closable = isset($this->tags_map[$tag_name]['closable']) ? $this->tags_map[$tag_name]['closable'] : false;
         $tag_name = isset($this->tags_map[$tag_name]['tag']) ? $this->tags_map[$tag_name]['tag'] : $tag_name;
     }
     return call_user_func_array(array($this, 'getTagString'), array($content, $tag_name, $attributes, $closable));
 }
コード例 #4
0
 /**
  * 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;
 }
コード例 #5
0
 /**
  * Actually process arguments with markdown transformation
  *
  * @return $this
  */
 protected function parseArguments()
 {
     // treat arguments one by one
     $counter = 1;
     foreach ($this->arguments as $i => $input) {
         if (false === strpos($input, PHP_EOL) && file_exists($input)) {
             $this->results[$input] = $this->getMarkdownExtendedParser()->transformSource($input);
         } else {
             $this->results['STDIN#' . $counter] = $this->getMarkdownExtendedParser()->transform($input, $counter);
             $counter++;
         }
     }
     // extraction?
     if (false !== $this->getOption('extract')) {
         $extract = $this->getOption('extract');
         if (!is_string($extract)) {
             $extract = 'metadata';
         }
         foreach ($this->results as $i => $item) {
             $method = 'get' . Helper::toCamelCase($extract);
             if (method_exists($item, $method)) {
                 $this->results[$i] = call_user_func(array($item, $method));
             } else {
                 $this->results[$i] = call_user_func(array($item, 'getMetadata'), $extract);
             }
         }
     }
     return $this;
 }