Example #1
0
 /**
  * Parse and transform Markdown strings into HTML
  *
  * @param string  $string  text to transform
  * @return string
  */
 public static function markdown($string)
 {
     // start measuring
     $hash = Debug::markStart('parsing', 'markdown');
     // check for parser, create if needed
     if (!isset(self::$parsers['markdown'])) {
         if (strtolower(Config::get('markdown_parser', 'standard')) === "parsedown") {
             $parser = new ParsedownExtra();
             $parser->setUrlsLinked(Config::get('markdown:convert_urls_to_links', true));
         } else {
             $parser = new MarkdownExtra();
             $parser->no_markup = Config::get('markdown:no_markup', false);
             $parser->no_entities = Config::get('markdown:no_entities', false);
             $parser->predef_urls = Config::get('markdown:predefined_urls', array());
             $parser->predef_abbr = Config::get('markdown:predefined_abbreviations', array());
             $parser->code_class_prefix = Config::get('markdown:code_class_prefix', '');
             $parser->code_attr_on_pre = Config::get('markdown:code_attr_on_pre', false);
         }
         self::$parsers['markdown'] = $parser;
     }
     // parse for markdown
     if (strtolower(Config::get('markdown_parser', 'standard')) === "parsedown") {
         $result = self::$parsers['markdown']->text($string);
     } else {
         $result = self::$parsers['markdown']->transform($string);
     }
     // end measuring
     Debug::markEnd($hash);
     Debug::increment('parses', 'markdown');
     return $result;
 }
Example #2
0
 public function render($path, $params)
 {
     $view = $this->_view;
     $options = $this->_options;
     $Extra = new \ParsedownExtra();
     echo $Extra->text(file_get_contents($path));
 }
Example #3
0
 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;
 }
 /**
  * @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">&lt;<span class="scml">' . $matches[1][$i] . '</span>&gt;</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 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);
 }
Example #6
0
 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);
 }
Example #7
0
 /**
  * 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);
 }
Example #8
0
 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);
 }
Example #9
0
 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');
 }
Example #10
0
 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;
 }
Example #11
0
 /**
  * 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;
 }
Example #12
0
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";
}
Example #13
0
/**
 * 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);
 }
Example #15
0
 function init()
 {
     parent::init();
     $this->addField('name');
     $this->addField('title');
     $this->addField('data')->caption('Markdown Template');
     $this->addField('rendered')->caption('HTML render cache');
     $this->addHook('afterLoad', function ($m) {
         if (is_null($m['rendered'])) {
             $markdown = $m['data'];
             if (!$m->hook('prepareTemplate', array(&$markdown))) {
                 $markdown = $this->prepareTemplate($markdown);
             }
             $m['rendered'] = \ParsedownExtra::instance()->parse($markdown);
             // $this->prepareTemplate());
         }
         if (is_null($m['title'])) {
             $x = null;
             preg_match('/^# (.*)$/m', $m['data'], $x);
             $m['title'] = $x[1];
             //v
             //$m['rendered'] = \ParsedownExtra::instance()->parse($markdown);
             // $this->prepareTemplate());
         }
     });
 }
 /**
  * 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;
 }
Example #17
0
 protected function identifyLink($Excerpt)
 {
     $r = parent::identifyLink($Excerpt);
     if (isset($r['element']['name']) && $r['element']['name'] == 'img') {
         $r['element']['attributes']['src'] = '/doc/' . $r['element']['attributes']['src'];
     }
     return $r;
 }
 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);
 }
 protected function inlineUrlTag($Excerpt)
 {
     if (strpos($Excerpt['text'], '>') !== false and preg_match('/^<(\\w+:\\/{2}[^ >]+)>/i', $Excerpt['text'], $matches)) {
         return;
     }
     $link = parent::inlineUrlTag($Excerpt);
     $link['element']['attributes']['target'] = "_blank";
     return $link;
 }
Example #20
0
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;
}
Example #21
0
 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;
 }
Example #22
0
 /**
  * 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;
 }
 public function text($text)
 {
     // Fix markdown blockquote syntax - > gets encoded.
     if (substr($text, 0, 4) == '&gt;') {
         $text = '>' . substr($text, 5);
     }
     $text = preg_replace('/[\\n\\r]&gt;\\s/', "\n> ", $text);
     // Fix autolink syntax
     $text = preg_replace('#&lt;(http[a-zA-Z0-9-\\.\\/:]*)&gt;#', "<\$1>", $text);
     $text = parent::text($text);
     $text = $this->smartypants($text);
     // Parsedown has naive encoding of URLs - fix it.
     $text = str_replace('&amp;amp;', '&amp;', $text);
     return $text;
 }
Example #24
0
 /**
  * ContentGetter constructor.
  *
  * @param string $version
  * @param string $slug
  */
 public function __construct($version, $slug = null)
 {
     if ($version === 'local') {
         $this->basepath = dirname(__DIR__);
     } else {
         $this->basepath = sprintf('%s/version/%s/', dirname(__DIR__), $version);
     }
     if ($slug !== null) {
         $sourceFile = sprintf('%s/source_docs/%s.md', $this->basepath, $slug);
         if (!is_readable($sourceFile)) {
             return;
         }
         $this->source = \ParsedownExtra::instance()->text(file_get_contents($sourceFile));
     }
     $this->slug = $slug;
     $this->version = $version;
 }
Example #25
0
---- */
// Markup for <h1> and <h2>..
$source = preg_replace_callback("/<h([234])>(.*)<\\/h([234])>/i", function ($matches) {
    $output = sprintf("<h%s id='%s'>%s<a href='#%s' class='anchor'>ΒΆ</a></h%s>", $matches[1], makeSlug($matches[2]), $matches[2], makeSlug($matches[2]), $matches[1]);
    return $output;
}, $source);
$loader = new Twig_Loader_Filesystem('./view');
$twig = new Twig_Environment($loader, array());
// Add Dumper function to twig.
$dumper = new Twig_SimpleFunction('dump', function ($var) {
    return dump($var);
}, array('is_safe' => array('html')));
$twig->addFunction($dumper);
// Add markdown to twig.
$markdown = new Twig_SimpleFilter('markdown', function ($content) {
    return \ParsedownExtra::instance()->text($content);
}, array('is_safe' => array('html')));
$twig->addFilter($markdown);
// Add slug filter to twig.
$slug = new Twig_SimpleFilter('slug', function ($name) {
    return \URLify::filter($name);
}, array('is_safe' => array('html')));
$twig->addFilter($slug);
echo $twig->render('index.twig', array('title' => $maintitle, 'source' => $source, 'menu' => $menu, 'submenu' => $submenu, 'current' => $request, 'version' => $version, 'requested_page' => $request, 'prefix' => $prefix == "/" ? "" : $prefix));
// ----------
/**
 * Modify a string, so that we can use it for slugs. Like
 * safeString, but using hyphens instead of underscores.
 *
 * @param string $str
 * @param string $type
 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]&gt;\\s/', "\n> ", $value);
             // Fix autolink syntax
             $value = preg_replace('#&lt;(http[a-zA-Z0-9-\\.\\/:]*)&gt;#', "<\$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;
 }
Example #27
0
 /**
  * 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;
 }
 /**
  * ParsedownExtra constructor.
  *
  * @param $page
  * @param $defaults
  */
 public function __construct($page, $defaults)
 {
     parent::__construct();
     $this->init($page, $defaults);
 }
Example #29
0
function formatContent($markdownstring)
{
    $parsedown = new ParsedownExtra();
    $content = $parsedown->text($markdownstring);
    return $content;
}
Example #30
0
<?php

$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());
    }