Exemplo n.º 1
0
/**
 * Markdown Parser functional interface
 */
function markdown($text)
{
    static $parser;
    if (!isset($parser)) {
        $parser = new MarkdownExtraParser();
    }
    return $parser->transform($text);
}
Exemplo n.º 2
0
 public function extra($file)
 {
     $extras = new MarkdownExtraParser();
     return $extras->transformMarkdown($file);
 }
Exemplo n.º 3
0
 function teardown()
 {
     parent::teardown();
 }
Exemplo n.º 4
0
 function md($str)
 {
     $markdownParser = new MarkdownExtraParser();
     // Parse the loaded source.
     return $markdownParser->transformMarkdown($str);
 }
Exemplo n.º 5
0
 /**
  * Disable mailto unless auto_mailto
  */
 public function doAutoLinks($text)
 {
     if (!$this->features['auto_mailto']) {
         return preg_replace_callback('{<((https?|ftp|dict):[^\'">\\s]+)>}i', array(&$this, '_doAutoLinks_url_callback'), $text);
     }
     return parent::doAutoLinks($text);
 }
Exemplo n.º 6
0
 /**
  * Converts a description node into something HTML-appropriate.
  *
  * @param  array  $description The description node to handle.
  * @return string              The description as it has been understood.
  */
 public static function descriptionAsHTML(array $description)
 {
     $output = array();
     foreach ($description as $index => $desc) {
         // If this is a string, just pass it along.
         if (is_string($desc)) {
             if ($index === 0) {
                 $desc .= ' ';
             }
             $output[] = $desc;
         } elseif (is_array($desc)) {
             switch (strtolower($desc['name'])) {
                 case 'example':
                     // @todo: Support this!
                     break;
                 case 'internal':
                     // Ignore
                     break;
                 case 'link':
                     if (isset($desc['description'])) {
                         $output[] = '<a href="' . $desc['uri'] . '">' . $desc['description'] . '</a>';
                     } else {
                         $output[] = '<a href="' . $desc['uri'] . '">' . $desc['uri'] . '</a>';
                     }
                     break;
                 case 'see':
                     switch ($desc['entity_hint']) {
                         case 'class':
                             $output[] = '<a href="' . self::getRelativeBasePath($desc['entity'], -1) . '/api-reference/' . self::namespaceAsPath($desc['entity']) . '/index.html' . '">' . $desc['entity'] . '</a>';
                             break;
                         case 'method':
                             list($__class, $__method) = explode('::', $desc['entity']);
                             $output[] = '<a href="' . self::getRelativeBasePath($__class) . '/api-reference/' . self::namespaceAsPath($__class) . '/' . str_replace('()', '', $__method) . '.html' . '">' . $desc['entity'] . '</a>';
                             break;
                         case 'property':
                             list($__class, $__property) = explode('::$', $desc['entity']);
                             $output[] = '<a href="' . self::getRelativeBasePath($__class) . '/api-reference/' . self::namespaceAsPath($__class) . '/properties.html' . '">' . $desc['entity'] . '</a>';
                             break;
                     }
                     break;
             }
         }
     }
     $md = new Markdown();
     return $md->transformMarkdown(implode('', $output));
 }
 /**
  * Transform
  *
  * @param mixed $text
  * @return void
  */
 public function transform($text)
 {
     $text = parent::transform($text);
     return $text;
 }
Exemplo n.º 8
0
 public function getFormattedContent()
 {
     $parser = new MarkdownExtraParser();
     return $parser->transform($this->contents);
 }
Exemplo n.º 9
0
/**
 * Notes for a single author -> /authors/:id/notes/
 *
 * @param  int $id author id
 */
function authorNotes($id)
{
    global $app;
    // parameter checking
    if (!is_numeric($id)) {
        $app->getLog()->warn('authorNotes: invalid author id ' . $id);
        $app->halt(400, "Bad parameter");
    }
    $author = $app->calibre->author($id);
    if (is_null($author)) {
        $app->getLog()->debug('authorNotes: author id not found ' . $id);
        $app->notFound();
    }
    $note = $app->bbs->authorNote($id);
    if (!is_null($note)) {
        $author->notes_source = $note->ntext;
    } else {
        $author->notes_source = null;
    }
    if (!empty($author->notes_source)) {
        $markdownParser = new MarkdownExtraParser();
        $author->notes = $markdownParser->transformMarkdown($author->notes_source);
    } else {
        $author->notes = null;
    }
    $app->render('author_notes.html', array('page' => mkPage(getMessageString('author_notes'), 3, 2), 'url' => 'authors/' . $id, 'author' => $author, 'isadmin' => is_admin()));
}
Exemplo n.º 10
0
 public function __construct(array $configure = null)
 {
     $this->block_gamut += array("parserUser" => 100, 'parserUrl' => 10000);
     $this->span_gamut += array('parserNewLine' => 0);
     parent::__construct($configure);
 }
Exemplo n.º 11
0
 /**
  * Retrieve the HTML excerpt for the story.
  *
  * @return string
  */
 public function getExcerpt()
 {
     $markdownExtra = new MarkdownExtraParser();
     $excerpt = $this->getRawExcerpt();
     return $markdownExtra->transformMarkdown($excerpt);
 }
Exemplo n.º 12
0
 public function getFilters()
 {
     $extension = $this;
     $routers = $this->routers;
     $parser = new MarkdownExtraParser();
     $translator = $this->translator;
     return array('markdown' => new \Twig_SimpleFilter('markdown', function ($value) use($parser) {
         return $parser->transform($value);
     }), 'trans' => new \Twig_SimpleFilter('trans', function ($value, $context) use($translator) {
         if (!$context) {
             $context = array();
         }
         return vsprintf($translator->translate($value), $context);
     }), 'route' => new \Twig_SimpleFilter('route', function ($value, $presentation = 'normal') use($extension, $routers) {
         // FIXME: this code is suboptimal and needs refactoring
         $result = array();
         if ($value instanceof Collection) {
             $value = $value->getAll();
         }
         $singleResult = !is_array($value);
         $value = !is_array($value) ? array($value) : $value;
         foreach ($value as $path) {
             $rule = $routers->match($path);
             $url = $rule ? ltrim($rule->generate($path), '/') : false;
             if ($url && $url[0] != '/') {
                 $url = $extension->convertToRootPath($url);
             }
             switch ($presentation) {
                 case 'url':
                     // return the first url
                     return $url;
                 case 'class:short':
                     $parts = explode('\\', $path);
                     $path = end($parts);
                     break;
             }
             $result[] = $url ? sprintf('<a href="%s">%s</a>', $url, $path) : $path;
         }
         return $singleResult ? reset($result) : $result;
     }));
 }
Exemplo n.º 13
0
 /**
  * @param $string
  */
 public function markdown($string)
 {
     $markdownParser = new MarkdownExtraParser();
     echo $markdownParser->transformMarkdown($string);
 }