/** * @param string $string * @param array $args * * @return string */ public function render($string, array $args = []) { @preg_match_all('#{~sm:(.*)}#i', $string, $matches); if (0 < count($matches[0])) { for ($i = 0; $i < count($matches[0]); ++$i) { $replace = '<small class="text-muted">' . $this->parsedown->text($matches[1][$i]) . '</small>'; $string = str_ireplace($matches[0][$i], $replace, $string); } } @preg_match_all('#{~scml:([^}]*)}#i', $string, $matches); if (0 < count($matches[0])) { for ($i = 0; $i < count($matches[0]); ++$i) { $replace = '<span class="scml">' . $matches[1][$i] . '</span>'; $string = str_ireplace($matches[0][$i], $replace, $string); } } @preg_match_all('#{~scml-tag:([^}]*)}#i', $string, $matches); if (0 < count($matches[0])) { for ($i = 0; $i < count($matches[0]); ++$i) { $replace = '<span class="scml-tag"><<span class="scml">' . $matches[1][$i] . '</span>></span>'; $string = str_ireplace($matches[0][$i], $replace, $string); } } @preg_match_all('#{~app-menu:([^}]*)}#i', $string, $matches); if (0 < count($matches[0])) { for ($i = 0; $i < count($matches[0]); ++$i) { $replace = '<span class="app-menu">' . $matches[1][$i] . '</span>'; $string = str_ireplace($matches[0][$i], $replace, $string); } } return $string; }
public function render($path, $params) { $view = $this->_view; $options = $this->_options; $Extra = new \ParsedownExtra(); echo $Extra->text(file_get_contents($path)); }
public function changelog() { $output = ''; $url = 'https://api.github.com/repos/arastta/arastta/releases'; $json = $this->utility->getRemoteData($url); if (empty($json)) { return $output; } $parsedown = new ParsedownExtra(); $releases = json_decode($json); foreach ($releases as $release) { if ($release->tag_name <= VERSION) { continue; } if (empty($release->body)) { continue; } $output .= '<h2><span class="label label-primary">' . $release->tag_name . '</span></h2>'; // Parse markdown output $markdown = str_replace('## Changelog', '', $release->body); $output .= $parsedown->text($markdown); $output .= '<hr>'; } return $output; }
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); }
/** * Convert the input data. * * @param string $input The raw content without Front-matter * * @return string */ public function convert($input) { if (is_string($input) === false) { throw new \InvalidArgumentException('Expected a string value at Parsedown converter.'); } $converter = new \ParsedownExtra(); return $converter->text($input); }
public static function parseMarkdown($value) { include_once __DIR__ . '/vendor/Parsedown.php'; include_once __DIR__ . '/vendor/ParsedownExtra.php'; $parser = new \ParsedownExtra(); $parser->setUrlsLinked(false); return $parser->text($value); }
public function previewpost() { $this->load->library('Parsedown'); $this->load->library('ParsedownExtra'); $tulisan = $this->input->post('inilah'); /*$tulisan = htmlspecialchars($_POST['inilah']);*/ $Tulis = new ParsedownExtra(); echo $Tulis->text($tulisan); }
public function get() { $content = []; $count = 1; // initial object creation foreach (glob(ELSA . '/content/' . $this->folder . '/*.' . $this->extension) as $contentItem) { // parse content $frontmatter = new FrontMatter($contentItem); $parsedown = new ParsedownExtra(); $meta = []; $type = preg_match('/content\\/(.*)\\//', $contentItem, $match); $type = $match[1]; foreach ($frontmatter->fetchMeta() as $key => $value) { $meta[$key] = $value; } // compose $content[$count]['id'] = (int) @explode('_', array_pop(explode('/', $contentItem)))[0]; $content[$count]['slug'] = @explode('.', explode('_', array_pop(explode('/', $contentItem)))[1])[0]; $content[$count]['content'] = $parsedown->text($frontmatter->fetchContent()); $content[$count]['content_raw'] = $frontmatter->fetchContent(); $content[$count]['type'] = $type; $content[$count]['meta'] = $meta; $count++; } // order usort($content, function ($a, $b) { // id desc if ($this->orderby === 'id' && $this->order === 'desc') { return $b['id'] - $a['id']; } // id asc if ($this->orderby === 'id' && $this->order === 'asc') { return $a['id'] - $b['id']; } // timestamp desc if ($this->orderby === 'timestamp' && $this->order === 'desc') { return $b['meta']['timestamp'] - $a['meta']['timestamp']; } // timestamp asc if ($this->orderby === 'timestamp' && $this->order === 'asc') { return $a['meta']['timestamp'] - $b['meta']['timestamp']; } }); // convert to objects $content = json_decode(json_encode($content)); // with slug ... if ($this->slug) { // find the content we want foreach ($content as $contentItem) { if ($contentItem->slug === $this->slug) { return $contentItem; break; } } } return $content; }
/** * Get the content of a file * @param string $path file path * @return string markdown formated string */ public function getPageContent($path) { $extra = new \ParsedownExtra(); $content = null; if (Storage::exists($path) === true) { $content = $extra->text(Storage::get($path)); } return $content; }
protected function execute(array $arguments) { if (isset($arguments[0]) && ($wf_id = (int) $GLOBALS['workflow_id'])) { $extra = new \ParsedownExtra(); WorkflowRepository::component_result($wf_id, 'markdown-view', $extra->text($arguments[0])); return ''; } throw new InvalidArgumentException('strings invalid'); }
function printPostRSS($post) { $parseDown = new ParsedownExtra(); echo " <item>\n"; echo " <title>" . $post['title'] . "</title>\n"; echo " <link>http://fisherevans.com/blog/post/" . $post['title_slug'] . "</link>\n"; echo " <guid>http://fisherevans.com/blog/post/" . $post['title_slug'] . "</guid>\n"; echo " <pubDate>" . date("D, d M Y H:i:s O", strtotime($post['posted_date'])) . "</pubDate>\n"; echo " <content:encoded><![CDATA[" . fixRelativeLinks($parseDown->text($post['content'])) . "]]></content:encoded>\n"; echo " </item>\n"; }
/** * Markdown * * Parse Markdown to HTML * * @since 2.0.0 * * @param $content (string) Markdown string or file to parse */ function markdown($content) { // Check for file if (is_readable($content)) { $content = file_get_contents($content); } // Parse Markdown $markdown = new ParsedownExtra(); $result = $markdown->text($content); return $result; }
/** * Index Page for this controller. * * Maps to the following URL * http://example.com/index.php/welcome * - or - * http://example.com/index.php/welcome/index * - or - * Since this controller is set as the default controller in * config/routes.php, it's displayed at http://example.com/ * * So any other public methods not prefixed with an underscore will * map to /index.php/welcome/<method_name> * @see http://codeigniter.com/user_guide/general/urls.html */ public function index() { $this->load->helper('url'); $data = array(); $data['readme'] = null; $readme = @file_get_contents(FCPATH . 'README.md'); if ($readme != '') { $parser = new ParsedownExtra(); $data['readme'] = @$parser->text($readme); } $this->load->view('welcome_message', $data); }
public function text($text) { // Fix markdown blockquote syntax - > gets encoded. if (substr($text, 0, 4) == '>') { $text = '>' . substr($text, 5); } $text = preg_replace('/[\\n\\r]>\\s/', "\n> ", $text); // Fix autolink syntax $text = preg_replace('#<(http[a-zA-Z0-9-\\.\\/:]*)>#', "<\$1>", $text); $text = parent::text($text); $text = $this->smartypants($text); // Parsedown has naive encoding of URLs - fix it. $text = str_replace('&amp;', '&', $text); return $text; }
function text_to_html($text) { /* static $parser; if (!isset($parser)) { $parser = new MarkdownExtra_Parser(); } return @ $parser->transform($text); */ static $parser; if (!isset($parser)) { $parser = new ParsedownExtra(); } return @$parser->text($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(true); // 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); $parser = new ParsedownExtra(); $parser->setBreaksEnabled(false); $text = $parser->text($md); return $text; }
function HtmlPreprocessor($content, $type) { if ($type == 'markdown') { $Parsedown = new ParsedownExtra(); $content = $Parsedown->text($content); } else { if ($type == 'jade') { $jade = new \Jade\Jade(); $content = $jade->render($content); } else { if ($type == 'haml') { } else { if ($type == 'html') { } } } } return $content; }
public function changelog() { $output = ''; // Get remote data $version = $this->request->get['version']; $url = 'https://api.github.com/repos/arastta/arastta/releases/latest'; $json = $this->utility->getRemoteData($url); if (empty($json)) { return $output; } $data = json_decode($json); if (empty($data->body)) { return $output; } // Parse markdown output $markdown = str_replace('## Changelog', '', $data->body); $parsedown = new ParsedownExtra(); $output = $parsedown->text($markdown); return $output; }
/** * Parses markdown and optionally fixes punctuation with SmartyPants * * @param string $content String to be parsed * @return string Parsed string */ public static function parseMarkdown($content, $options = ["fix_punctuation" => false]) { if (!is_string($content)) { return null; } // Strip whitepace from the start of all lines with HTML // so that the Markdown parser does not wrap HTML within a <pre> element $clean_content = ''; foreach (explode("\n", $content) as $line) { if (trim($line) == '') { $clean_content .= "\n"; } else { $clean_content .= preg_replace('/^(\\s+[?!<])/m', '<', $line) . "\n"; } } $content = $clean_content; $parser = new \ParsedownExtra(); $content = $parser->text($content); if ($options['fix_punctuation']) { $content = static::fixPunctuation($content); } return $content; }
/** * markdown * * @param mixed $text * @access public * @return void */ public function markdown($text) { $html = $this->pluginHandle(__CLASS__)->trigger($parsed)->markdown($text); if (!$parsed) { static $parser; if (empty($parser)) { $parser = new ParsedownExtra(); $parser->setBreaksEnabled(true); } $html = $parser->text($text); } return $html; }
include_once "{$root}/includes/parsedown-extra.php"; $parsedown = new ParsedownExtra(); $parsedown->setMarkupEscaped(true); ?> <div class="markdown-preview"> <link rel="stylesheet" type="text/css" href="css/markdown-light.css" class="md-css"/> <link rel="stylesheet" type="text/css" href="css/markdown.css"/> <h1 class="mdh">Markdown Preview</h1> <div class="css-switcher"> <a href="css/markdown.css" style="float: left; margin-right: 16px; color: #fff;" class="css-link">CSS</a> <div class="css-switch" id="light"></div> <div class="css-switch" id="dark"></div> </div> <div class="markdown-content"> <?php echo $parsedown->text(html_entity_decode(bzdecompress(file_get_contents("{$dir}/{$foundFile}")))); ?> </div> </div> <script> $(document).ready(function(){ $(".css-switch").on("click",function(){ switch($(this).attr("id")) { case "dark": $(".md-css").attr("href","css/markdown-dark.css"); $(".css-link").attr("href","css/markdown-dark.css"); break; default: case "light": $(".md-css").attr("href","css/markdown-light.css");
<?php $parseDown = new ParsedownExtra(); ?> <div class="section" itemscope itemtype="http://schema.org/<?php echo $staticContent['itemtype']; ?> "> <h1 itemprop="name"><?php echo $staticContent['name']; ?> </h1> <div itemprop="text"> <?php echo fixRelativeLinks($parseDown->text($staticContent['content'])); ?> </div> </div>
$app['app.assets.base'] = ['assets:vendor/polyfills/es-shim.js', 'assets:vendor/jquery.js', 'assets:vendor/storage.js', 'assets:vendor/i18n.js', 'assets:vendor/animate.css', 'assets:css/cockpit.css', 'assets:vendor/uikit/js/uikit.min.js', 'assets:vendor/uikit/js/components/notify.min.js']; // API $this->module("cockpit")->extend(["assets" => function ($assets, $key = null, $cache = 0, $cache_folder = null) use($app) { $key = $key ? $key : md5(serialize($assets)); $cache_folder = $cache_folder ? $cache_folder : $app->path("cache:assets"); $app("assets")->style_and_script($assets, $key, $cache_folder, $cache); }, "markdown" => function ($content, $extra = false) use($app) { static $parseDown; static $parsedownExtra; if (!$extra && !$parseDown) { $parseDown = new \Parsedown(); } if ($extra && !$parsedownExtra) { $parsedownExtra = new \ParsedownExtra(); } return $extra ? $parsedownExtra->text($content) : $parseDown->text($content); }, "get_registry" => function ($key, $default = null) use($app) { return $app->memory->hget("cockpit.api.registry", $key, $default); }, "clearCache" => function () use($app) { $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($app->path("cache:")), \RecursiveIteratorIterator::SELF_FIRST); foreach ($files as $file) { if (!$file->isFile()) { continue; } if (preg_match('/(.gitkeep|index\\.html)$/', $file)) { continue; } @unlink($file->getRealPath()); } $app->helper("fs")->removeEmptySubFolders('cache:'); return ["size" => $app->helper("utils")->formatSize($app->helper("fs")->getDirSize('cache:'))];
/** * Displays the content of the current post. * * * @since 0.1 */ function post_content() { global $post; if (is_array($post) && array_key_exists('content', $post)) { $markdownExtra = new ParsedownExtra(); $file_content = $markdownExtra->text($post['content']); echo $file_content; } }
/** * Parses the content using Parsedown-extra * * @param string $content the raw txt content * @return string $content the Markdown formatted content */ protected function parse_content($content) { $content = preg_replace('#/\\*.+?\\*/#s', '', $content, 1); // Remove first comment (with meta) $content = str_replace('%base_url%', $this->base_url(), $content); $Parsedown = new ParsedownExtra(); $content = $Parsedown->text($content); return $content; }
/** * Parses the contents of a page using ParsedownExtra * * @see Pico::prepareFileContent() * @see Pico::getFileContent() * @param string $content raw contents of a page (Markdown) * @return string parsed contents (HTML) */ public function parseFileContent($content) { if ($this->parsedown === null) { throw new LogicException("Unable to parse file contents: Parsedown instance wasn't registered yet"); } return $this->parsedown->text($content); }
function formatContent($markdownstring) { $parsedown = new ParsedownExtra(); $content = $parsedown->text($markdownstring); return $content; }
/** * Parsedown * * <code> * $content = Morfy::parsedown($content); * </code> * * @access public * @param string $content Content to parse * @return string Formatted content */ public static function parsedown($content) { $parsedown_extra = new ParsedownExtra(); return $parsedown_extra->text($content); }
public function text_to_html($value) { switch (PERCH_APPS_EDITOR_MARKUP_LANGUAGE) { case 'textile': if (!class_exists('\\Netcarver\\Textile\\Parser', false) && class_exists('Textile', true)) { // sneaky autoloading hack } if (PERCH_HTML5) { $Textile = new \Netcarver\Textile\Parser('html5'); } else { $Textile = new \Netcarver\Textile\Parser(); } if (PERCH_RWD) { $value = $Textile->setDimensionlessImages(true)->textileThis($value); } else { $value = $Textile->textileThis($value); } break; case 'markdown': // Fix markdown blockquote syntax - > gets encoded. $value = preg_replace('/[\\n\\r]>\\s/', "\n> ", $value); // Fix autolink syntax $value = preg_replace('#<(http[a-zA-Z0-9-\\.\\/:]*)>#', "<\$1>", $value); $Markdown = new ParsedownExtra(); $value = $Markdown->text($value); if (!class_exists('\\Michelf\\SmartyPants', false) && class_exists('SmartyPants', true)) { // sneaky autoloading hack } $SmartyPants = new \Michelf\SmartyPants(); $value = $SmartyPants->transform($value); if (PERCH_HTML_ENTITIES == false) { $value = html_entity_decode($value, ENT_NOQUOTES, 'UTF-8'); } break; } if (defined('PERCH_XHTML_MARKUP') && PERCH_XHTML_MARKUP == false) { $value = str_replace(' />', '>', $value); } return $value; }
function au_parse_markdown($content, $line = false) { // We need to require the parsedown file, but only once. require_once au_get_path_from_root('library/parsedown.require.php'); require_once au_get_path_from_root('library/parsedown_extra.require.php'); $parse = new ParsedownExtra(); if ($line) { return $parse->line($content); } else { return $parse->text($content); } }