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]); } } }
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)); }
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); }
/** * 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); }
/** * 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); }
/** * Overload to specify heading styles only if the hash has space(s) after it. This is actually in keeping with * the documentation and eases the semantic overload of the hash character. * #Will Not Produce a Heading 1 * # This Will Produce a Heading 1 * * @param string $text Markdown text * @return string HTML-transformed text */ public function transform($text) { // Remove all shortcodes so their interiors are left intact if ($this->preserve_shortcodes) { $text = $this->shortcode_preserve($text); } // Remove legacy LaTeX so it's left intact if ($this->preserve_latex) { $text = $this->latex_preserve($text); } // escape line-beginning # chars that do not have a space after them. $text = preg_replace_callback('|^#{1,6}( )?|um', array($this, '_doEscapeForHashWithoutSpacing'), $text); // run through core Markdown $text = parent::transform($text); // put start-of-line # chars back in place $text = preg_replace("/^(<p>)?(#|\\\\#)/um", "\$1#", $text); // Restore shortcodes/LaTeX $text = $this->shortcode_restore($text); // Strip paras if set if ($this->strip_paras) { $text = $this->unp($text); } return $text; }
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); }
/** * Overload to specify heading styles only if the hash has space(s) after it. This is actually in keeping with * the documentation and eases the semantic overload of the hash character. * #Will Not Produce a Heading 1 * # This Will Produce a Heading 1 * * @param string $text Markdown text * @return string HTML-transformed text */ public function transform($text) { // Preserve anything inside a single-line <code> element if ($this->preserve_inline_code_blocks) { $text = $this->single_line_code_preserve($text); } // Remove all shortcodes so their interiors are left intact if ($this->preserve_shortcodes) { $text = $this->shortcode_preserve($text); } // Remove legacy LaTeX so it's left intact if ($this->preserve_latex) { $text = $this->latex_preserve($text); } // escape line-beginning # chars that do not have a space after them. $text = preg_replace_callback('|^#{1,6}( )?|um', array($this, '_doEscapeForHashWithoutSpacing'), $text); // run through core Markdown $text = parent::transform($text); // Occasionally Markdown Extra chokes on a para structure, producing odd paragraphs. $text = str_replace("<p><</p>\n\n<p>p>", '<p>', $text); // put start-of-line # chars back in place $text = $this->restore_leading_hash($text); // Strip paras if set if ($this->strip_paras) { $text = $this->unp($text); } // Restore preserved things like shortcodes/LaTeX $text = $this->do_restore($text); return $text; }
/** * Overload to specify heading styles only if the hash has space(s) after it. This is actually in keeping with * the documentation and eases the semantic overload of the hash character. * #Will Not Produce a Heading 1 * # This Will Produce a Heading 1 * * @param string $text Markdown text * @return string HTML-transformed text */ public function transform($text) { // Preserve anything inside a single-line <code> element if ($this->preserve_inline_code_blocks) { $text = $this->single_line_code_preserve($text); } // Remove all shortcodes so their interiors are left intact if ($this->preserve_shortcodes) { $text = $this->shortcode_preserve($text); } // Remove legacy LaTeX so it's left intact if ($this->preserve_latex) { $text = $this->latex_preserve($text); } // escape line-beginning # chars that do not have a space after them. $text = preg_replace_callback('|^#{1,6}( )?|um', array($this, '_doEscapeForHashWithoutSpacing'), $text); /** * Allow third-party plugins to define custom patterns that won't be processed by Markdown. * * @module markdown * * @since 3.9.2 * * @param array $custom_patterns Array of custom patterns to be ignored by Markdown. */ $custom_patterns = apply_filters('jetpack_markdown_preserve_pattern', array()); if (is_array($custom_patterns) && !empty($custom_patterns)) { foreach ($custom_patterns as $pattern) { $text = preg_replace_callback($pattern, array($this, '_doRemoveText'), $text); } } // run through core Markdown $text = parent::transform($text); // Occasionally Markdown Extra chokes on a para structure, producing odd paragraphs. $text = str_replace("<p><</p>\n\n<p>p>", '<p>', $text); // put start-of-line # chars back in place $text = $this->restore_leading_hash($text); // Strip paras if set if ($this->strip_paras) { $text = $this->unp($text); } // Restore preserved things like shortcodes/LaTeX $text = $this->do_restore($text); return $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; }
function transform($text) { $text = parent::transform($text); return $text; }
public static function to_html($string) { $markdown = new MarkdownExtra_Parser(); return '<div class="markdown">' . $markdown->transform($string) . '</div>'; }
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; } }
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()); } }
<?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;
function mdown_m($m) { $md = new MarkdownExtra_Parser; $html = $md->transform($m[2]); return $m[1] . '>' . $html . '</wrapper>'; }