Inheritance: extends Markdown_Parser
Exemple #1
0
 function apply($text)
 {
     require_once 'classMarkdown.php';
     $markdown = new MarkdownExtra_Parser();
     $text = $markdown->transform($text);
     return SmartyPants($text);
 }
 /**
  * parse the markdown in the specified fields when an object is updated
  *
  * @param Doctrine_Event $event
  * @return void
  * @author Brent Shaffer
  */
 public function preUpdate(Doctrine_Event $event)
 {
     $parser = new MarkdownExtra_Parser();
     $object = $event->getInvoker();
     foreach ($this->_options['fields'] as $parsedField => $markdownField) {
         if (array_key_exists($markdownField, $object->getModified())) {
             $object[$parsedField] = $parser->transform($object[$markdownField]);
         }
     }
 }
Exemple #3
0
 public function executePreview(sfWebRequest $request)
 {
     if (false === ($markdown = $request->getParameter('markdown_value', false))) {
         $field = $request->getParameter('markdown_field');
         $markdown = sfToolkit::getArrayValueForPath($request->getParameterHolder()->getAll(), $field, false);
         if ($markdown === false) {
             throw new sfException("Cannot generate preview: markdown value or markdown form field not found in request");
         }
     }
     $parser = new MarkdownExtra_Parser();
     // $this->markdown = $parser->transform($markdown);
     $markdown = $markdown ? $markdown : '_No Markdown To Preview!_';
     return $this->renderText($parser->transform($markdown));
 }
Exemple #4
0
function Markdown($text)
{
    #
    # Initialize the parser and return the result of its transform method.
    #
    # Setup static parser variable.
    static $parser;
    if (!isset($parser)) {
        $parser_class = MARKDOWN_PARSER_CLASS;
        $parser = new MarkdownExtra_Parser();
    }
    # Transform text using parser.
    return $parser->transform($text);
}
 public function _doHeaders_callback_atx($matches)
 {
     if (isset($matches[3])) {
         $this->header_ids[] = $matches[3];
     }
     return parent::_doHeaders_callback_atx($matches);
 }
 function _doFencedCodeBlocks_callback($matches)
 {
     if ($m = $this->hasShebang($matches[2])) {
         return $this->_doGeshi($m);
     } else {
         return parent::_doFencedCodeBlocks_callback($matches);
     }
 }
 /**
  * Parse a given path to the documentation for a file. Performs a case insensitive 
  * lookup on the file system. Automatically appends the file extension to one of the markdown
  * extensions as well so /install/ in a web browser will match /install.md or /INSTALL.md
  * 
  * Filepath: /var/www/myproject/src/cms/en/folder/subfolder/page.md
  * URL: http://myhost/mywebroot/dev/docs/2.4/cms/en/folder/subfolder/page
  * Webroot: http://myhost/mywebroot/
  * Baselink: dev/docs/2.4/cms/en/
  * Pathparts: folder/subfolder/page
  * 
  * @param DocumentationPage $page
  * @param String $baselink Link relative to webroot, up until the "root" of the module.  
  *  Necessary to rewrite relative links
  *
  * @return String
  */
 public static function parse(DocumentationPage $page, $baselink = null)
 {
     if (!$page || !$page instanceof DocumentationPage) {
         return false;
     }
     $md = $page->getMarkdown();
     // Pre-processing
     $md = self::rewrite_image_links($md, $page);
     $md = self::rewrite_relative_links($md, $page, $baselink);
     $md = self::rewrite_api_links($md, $page);
     $md = self::rewrite_heading_anchors($md, $page);
     $md = self::rewrite_code_blocks($md, $page);
     require_once BASE_PATH . '/sapphiredocs/thirdparty/markdown/markdown.php';
     $parser = new MarkdownExtra_Parser();
     $parser->no_markup = true;
     return $parser->transform($md);
 }
 /**
  * Overrides parent, rtrim code first
  */
 public function _doCodeBlocks_callback($matches)
 {
     $codeblock = rtrim($this->outdent($matches[1]));
     if (($codeblock = $this->highlightCodeBlock($codeblock)) !== null) {
         return "\n\n" . $this->hashBlock($codeblock) . "\n\n";
     } else {
         return \MarkdownExtra_Parser::_doCodeBlocks_callback($matches);
     }
 }
 /**
  * Callback function when a code block is matched.
  * @param array matches
  * @return string the highlighted code block
  */
 public function _doCodeBlocks_callback($matches)
 {
     $codeblock = $this->outdent($matches[1]);
     if (($codeblock = $this->highlightCodeBlock($codeblock)) !== null) {
         return "\n\n" . $this->hashBlock($codeblock) . "\n\n";
     } else {
         return parent::_doCodeBlocks_callback($matches);
     }
 }
Exemple #10
0
 public function __construct()
 {
     // doImage is 10, add image url just before
     $this->span_gamut['doImageURL'] = 9;
     // doLink is 20, add base url just before
     $this->span_gamut['doBaseURL'] = 19;
     // Add API links
     $this->span_gamut['doAPI'] = 90;
     // Add note spans last
     $this->span_gamut['doNotes'] = 100;
     // Parse Kohana view inclusions at the very end
     $this->document_gamut['doIncludeViews'] = 100;
     // PHP4 makes me sad.
     parent::MarkdownExtra_Parser();
 }
 public function __construct()
 {
     // doImage is 10, add image url just before
     $this->span_gamut['doImageURL'] = 9;
     // doLink is 20, add base url just before
     $this->span_gamut['doBaseURL'] = 19;
     // Add API links
     $this->span_gamut['doAPI'] = 90;
     // Add note spans last
     $this->span_gamut['doNotes'] = 100;
     // Parse Kohana view inclusions at the very end
     $this->document_gamut['doIncludeViews'] = 99;
     // Show table of contents for userguide pages
     $this->document_gamut['doTOC'] = 100;
     // Call parent constructor.
     parent::__construct();
 }
Exemple #12
0
 /**
  * Transforms input text to html.
  */
 function transform($text)
 {
     $text = preg_replace("/\r\n|\r|\n/", "\n", $text);
     $processed = "";
     foreach (preg_split('~(\\n[ \\n]*\\n)~S', $text, -1, PREG_SPLIT_DELIM_CAPTURE) as $part) {
         if (preg_match('~^(\\.\\.\\s*([^:\\n]+)[^\\n]*)\\n?(.*)$~sS', $part, $section)) {
             $name = strtoupper(trim($section[2]));
             if (isset($this->transformers[$name])) {
                 if (is_callable($this->transformers[$name])) {
                     $processed .= call_user_func($this->transformers[$name], $section[3], $name, $section[1]);
                 } else {
                     $processed .= $this->transformers[$section[1]]->transform($section[3], $name, $section[1]);
                 }
             } else {
                 $processed .= $part;
             }
         } else {
             $processed .= $part;
         }
     }
     return parent::transform($processed);
 }
Exemple #13
0
 function ExtendedMarkdown()
 {
     $this->block_gamut += array("doBlockWarning" => 45);
     parent::MarkdownExtra_Parser();
 }
Exemple #14
0
 public static function to_html($string)
 {
     $markdown = new MarkdownExtra_Parser();
     return '<div class="markdown">' . $markdown->transform($string) . '</div>';
 }
 function MarkdownUltra_Parser()
 {
     parent::MarkdownExtra_Parser();
     $this->languages = array();
     $parser = new MarkdownExtra_Parser();
 }
Exemple #16
0
 /**
  * Overload to support Viper's [code] shortcode. Because awesome.
  */
 public function _doFencedCodeBlocks_callback($matches)
 {
     // in case we have some escaped leading hashes right at the start of the block
     $matches[4] = $this->restore_leading_hash($matches[4]);
     // just MarkdownExtra_Parser if we're not going ultra-deluxe
     if (!$this->use_code_shortcode) {
         return parent::_doFencedCodeBlocks_callback($matches);
     }
     // default to a "text" class if one wasn't passed. Helps with encoding issues later.
     if (empty($matches[2])) {
         $matches[2] = 'text';
     }
     $classname =& $matches[2];
     $codeblock = preg_replace_callback('/^\\n+/', array($this, '_doFencedCodeBlocks_newlines'), $matches[4]);
     if ($classname[0] == '.') {
         $classname = substr($classname, 1);
     }
     $codeblock = esc_html($codeblock);
     $codeblock = sprintf($this->shortcode_start, $classname) . "\n{$codeblock}" . $this->shortcode_end;
     return "\n\n" . $this->hashBlock($codeblock) . "\n\n";
 }
Exemple #17
0
 public function __construct(dmHelper $helper, array $options = array())
 {
     $this->helper = $helper;
     parent::__construct();
     $this->initialize($options);
 }
 public function parse_string($template, $data = array(), $return = FALSE, $config = array())
 {
     if (!is_array($config)) {
         $config = array();
     }
     $config = array_merge($this->config, $config);
     $ci = $this->ci;
     $is_mx = false;
     if (!$return) {
         list($ci, $is_mx) = $this->detect_mx();
     }
     switch ($config['markdown_implementation']) {
         case 'parsedown':
             $parser = new ParsedownExtra();
             $template = @$parser->text($template);
             break;
         default:
             if (!empty($config['detect_code_blocks'])) {
                 $template = preg_replace('/`{3,}[a-z]*/i', '~~~', $template);
             }
             $parser = new MarkdownExtra_Parser();
             $template = @$parser->transform($template);
             if (!empty($config['apply_autolink'])) {
                 $this->ci->load->helper('url');
                 $template = auto_link($template);
             }
             break;
     }
     return $this->output($template, $return, $ci, $is_mx);
 }
Exemple #19
0
function mdown_m($m) {
  $md = new MarkdownExtra_Parser;
  $html = $md->transform($m[2]);
  return $m[1] . '>' . $html . '</wrapper>';
}
Exemple #20
0
<?php

require_once './autoloader.php';
require_once EVA_LIB_PATH . '/Markdown/markdownextra.php';
$safeParser = true;
if ($safeParser) {
    $md = new Markdown_Parser();
    $md->no_markup = true;
    $md->no_entities = true;
} else {
    $md = new MarkdownExtra_Parser();
    $md->no_markup = true;
    $md->no_entities = true;
}
$text = file_get_contents('test.md');
$text = $md->transform($text);
echo $text;
Exemple #21
0
$file = preg_replace('/[^a-zA-Z0-9\\-\\.\\/]+/', '', str_replace('../', '', $file));
$filePath = $docsPath . '/' . $file . '.md';
if (!file_exists($filePath)) {
    $file = $defaultFile;
    $filePath = $docsPath . '/' . $file;
}
// Create template instance
$tpl = new Awf_Template();
$tpl->baseurl = $baseurl = $_SERVER['SCRIPT_NAME'];
$tpl->basepath = $basepath = str_replace('index.php', '', $baseurl);
$tpl->title = $file;
$tpl->module = $module;
// Unparsed markdown content;
$markdown = file_get_contents($filePath);
// Get the content of the current page
$md = new MarkdownExtra_Parser();
$md->no_markup = true;
$content = $md->transform($markdown);
// Replace urls with the right ones
$content = str_replace('href="/', 'href="' . $baseurl . '/', $content);
$tpl->content = $content;
// Get the menu
$categories = array();
$dir = new DirectoryIterator($docsPath);
foreach ($dir as $fileinfo) {
    if (!$fileinfo->isDot() && $fileinfo->isDir()) {
        $category = array();
        $dir2 = new DirectoryIterator($docsPath . '/' . $fileinfo->getFilename());
        foreach ($dir2 as $fileinfo2) {
            if ($fileinfo2->isFile()) {
                $category[] = str_replace('.md', '', $fileinfo2->getFilename());
 function _doAnchors_reference_callback($matches)
 {
     $whole_match = $matches[1];
     $res = parent::_doAnchors_reference_callback($matches);
     if ($res != $whole_match || strpos($matches[3], '#') === false) {
         return $res;
     }
     list($matches[3], $anchor) = explode('#', $matches[3], 2);
     $link_id = strtolower($matches[3]);
     $temp = false;
     if (isset($this->urls[$link_id])) {
         $temp = $this->urls[$link_id];
         $explode = explode('#', $this->urls[$link_id], 2);
         if (count($explode) == 2) {
             $this->urls[$link_id] = $explode[0];
         }
         $this->urls[$link_id] .= '#h:' . str_replace('.', '_', $link_id) . ':' . $anchor;
     }
     $res = parent::_doAnchors_reference_callback($matches);
     if ($temp !== false) {
         $this->urls[$link_id] = $temp;
     }
     return $res;
 }
 public function __construct(dmHelper $helper, array $options = array())
 {
     $this->helper = $helper;
     parent::MarkdownExtra_Parser();
     $this->initialize($options);
 }
 /**
  * Overload to enable single-newline paragraphs
  * https://github.com/github/github-flavored-markdown/blob/gh-pages/index.md#newlines
  */
 function formParagraphs($text)
 {
     // Treat single linebreaks as double linebreaks
     $text = preg_replace('#([^\\n])\\n([^\\n])#', "\$1\n\n\$2", $text);
     return parent::formParagraphs($text);
 }
 /**
  * Parses $text containing doc-markdown text and generates the correct
  * HTML
  *
  * ### Options:
  *
  * - stripHtml - remove any HTML before parsing.
  * - engine: default, markdown, markdown_extra
  *
  * IDEAS
  * - elements: allow further elemens like video, latex, ... (use registerElement to register new stuff)
  *
  * @param string $text Text to be converted
  * @param array $options Array of options for converting
  * @return string Parsed HTML
  */
 public function parse($text, $options = array())
 {
     $defaults = array('engine' => 'default');
     $options = am($defaults, $options);
     if (!empty($options['stripHtml'])) {
         $text = strip_tags($text);
     }
     if ($options['engine'] == 'markdown_extra') {
         App::import('Vendor', 'MarkupParsers.markdown/markdown');
         $Markdown = new MarkdownExtra_Parser();
         return trim($Markdown->transform($text));
     } elseif ($options['engine'] == 'markdown') {
         App::import('Vendor', 'MarkupParsers.markdown/markdown');
         $Markdown = new Markdown_Parser();
         return trim($Markdown->transform($text));
     }
     $this->_placeHolders = array();
     $text = str_replace("\r\n", "\n", $text);
     $text = str_replace("\t", str_repeat(' ', $this->spacesPerTab), $text);
     $text = $this->_runBlocks($text);
     return $text;
 }
 public function do_markup($content, $post = null)
 {
     static $textile;
     static $markdown;
     static $bbcode;
     $markup = 'html';
     $process_comments = Options::get('Markup__process_comments');
     // Posts are Post objects and comments are comment objects.
     if ($post instanceof Comment && $process_comments) {
         $markup = Options::get('Markup__comment_markup_type');
     } else {
         if ($post instanceof Post) {
             $markup = Options::get('Markup__markup_type');
         }
     }
     switch ($markup) {
         case 'markdown':
             if (!isset($markdown)) {
                 $markdown = new MarkdownExtra_Parser();
             }
             return $markdown->transform($content);
             break;
         case 'textile':
             if (!isset($textile)) {
                 $textile = new Textile();
             }
             return $textile->TextileThis($content);
             break;
         case 'bbcode':
             if (!isset($bbcode)) {
                 $bbcode = new BBCode();
             }
             return $bbcode->transform($content);
             break;
         case 'html':
         default:
             return $content;
     }
 }
 function transform($text)
 {
     $text = parent::transform($text);
     return $text;
 }
Exemple #28
0
 function _doImages_reference_callback($matches)
 {
     // FIXME-20140921: Hook only support patron.markup, so we replaced a hack with another
     // waiting for a better solution.
     if (self::$images_reference_callback === null) {
         $hook = false;
         if (class_exists('Icybee\\Modules\\Images\\Hooks')) {
             $hook = 'Icybee\\Modules\\Images\\Hooks::textmark_images_reference';
         }
         self::$images_reference_callback = $hook;
     }
     if (self::$images_reference_callback !== false) {
         return $this->hashPart(call_user_func(self::$images_reference_callback, [], $this, $matches));
     }
     static $module;
     if (!$module) {
         $module = \ICanBoogie\app()->modules['images'];
     }
     //		echo l('<pre>in \1: \2</pre>', __FUNCTION__, $matches);
     $align = $matches[2];
     $alt = $matches[3];
     $id = $matches[4];
     # for shortcut links like ![this][].
     if (!$id) {
         $id = $alt;
     }
     $parts = explode(':', $id, 2);
     if (isset($parts[1])) {
         $entry = $module->model()->loadRange(0, 1, 'WHERE `' . $module->getConstant('TITLE') . '` = ? AND `' . $module->getConstant('ALBUM') . '` = ?', array($parts[1], $parts[0]))->fetchAndClose();
     } else {
         $entry = $module->model()->loadRange(0, 1, 'WHERE `slug` = ? OR `title` = ?', array($id, $id))->fetchAndClose();
     }
     if (!$entry) {
         $matches[2] = $matches[3];
         $matches[3] = $matches[4];
         return parent::_doImages_reference_callback($matches);
     }
     $params = array('src' => $entry->path, 'alt' => \ICanBoogie\escape($alt), 'width' => $entry->width, 'height' => $entry->height);
     if ($align) {
         switch ($align) {
             case '<':
                 $align = 'left';
                 break;
             case '=':
             case '|':
                 $align = 'middle';
                 break;
             case '>':
                 $align = 'right';
                 break;
         }
         $params['align'] = $align;
     }
     # the image has been found is the database
     return $this->hashPart($this->createElement('img', $params));
 }
Exemple #29
0
 /**
  * Overload to support Viper's [code] shortcode. Because awesome.
  */
 public function _doFencedCodeBlocks_callback($matches)
 {
     // just MarkdownExtra_Parser if we're not going ultra-deluxe, or if
     // there wasn't a language class passed
     if (!$this->use_code_shortcode || empty($matches[2])) {
         return parent::_doFencedCodeBlocks_callback($matches);
     }
     $classname =& $matches[2];
     $codeblock = preg_replace_callback('/^\\n+/', array($this, '_doFencedCodeBlocks_newlines'), $matches[4]);
     if ($classname[0] == '.') {
         $classname = substr($classname, 1);
     }
     $codeblock = sprintf($this->shortcode_start, $classname) . "\n{$codeblock}" . $this->shortcode_end;
     return "\n\n" . $this->hashBlock($codeblock) . "\n\n";
 }
Exemple #30
0
 public function __construct($callbacks = array())
 {
     parent::__construct();
     $this->_callbacks = $callbacks;
 }