function smarty_modifier_markdown($text)
{
    $parser = new Markdown_Parser();
    $parser->no_markup = true;
    $parser->no_entities = true;
    $html = $parser->transform($text);
    return $html;
}
Beispiel #2
0
 /**
  * @param string $text Markdown formatted text.
  * @return string HTML
  */
 public static function format($text)
 {
     static $markdown;
     if (!isset($markdown)) {
         $markdown = new Markdown_Parser();
     }
     foreach (PicoraEvent::getObserverList('PicoraTextile.beforeFormat') as $callback) {
         call_user_func($callback, $text);
     }
     $output = $markdown->transform($text);
     foreach (PicoraEvent::getObserverList('PicoraTextile.afterFormat') as $callback) {
         call_user_func($callback, $output);
     }
     return $output;
 }
Beispiel #3
0
 /**
  * @see IFilter::filter()
  */
 public function filter(HamlNode $node)
 {
     if (null === $node) {
         throw new Exception("MarkdownFilter: node is null.");
     }
     $children = $node->getChildren();
     $output = '';
     $indent = 999999999;
     // gets the lowes indent among the children to set as base
     foreach ($children as $child) {
         if ($indent > ($ind = $child->getIndentationLevel())) {
             $indent = $ind;
         }
     }
     foreach ($children as $childNode) {
         $output .= substr($childNode->getRawHaml(), $indent) . "\n";
     }
     return $this->parser->transform($output);
 }
 function teardown()
 {
     #
     # Clearing Extra-specific variables.
     #
     $this->footnotes = array();
     $this->footnotes_ordered = array();
     $this->abbr_desciptions = array();
     $this->abbr_word_re = '';
     parent::teardown();
 }
Beispiel #5
0
 static function parseMarkdown($text)
 {
     static $parser = null;
     if (is_null($parser)) {
         $parser = new Markdown_Parser();
     }
     return $parser->transform($text);
 }
Beispiel #6
0
 public static function markdown2html($text)
 {
     static $parser;
     if (!isset($parser)) {
         $parser = new Markdown_Parser();
     }
     return $parser->transform($text);
 }
 public function preview()
 {
     require_once 'classMarkdown.php';
     $markdown = new Markdown_Parser();
     echo $markdown->transform($_POST['data']);
 }
 public function text_to_html($str)
 {
     switch (PERCH_APPS_EDITOR_MARKUP_LANGUAGE) {
         case 'textile':
             $Textile = new Textile();
             $str = $Textile->TextileThis($str);
             break;
         case 'markdown':
             $Markdown = new Markdown_Parser();
             $str = $Markdown->transform($str);
             break;
     }
     if (defined('PERCH_XHTML_MARKUP') && PERCH_XHTML_MARKUP == false) {
         $str = str_replace(' />', '>', $str);
     }
     return $str;
 }
Beispiel #9
0
    function doCodeBlocks($text)
    {
        #
        # Adding the fenced code block syntax to regular Markdown:
        #
        # ~~~
        # Code block
        # ~~~
        #
        $less_than_tab = $this->tab_width;
        $text = preg_replace_callback('{
				(?:\\n|\\A)
				# 1: Opening marker
				(
					~{3,} # Marker: three tilde or more.
				)
				[ ]* \\n # Whitespace and newline following marker.
				
				# 2: Content
				(
					(?>
						(?!\\1 [ ]* \\n)	# Not a closing marker.
						.*\\n+
					)+
				)
				
				# Closing marker.
				\\1 [ ]* \\n
			}xm', array(&$this, '_doCodeBlocks_fenced_callback'), $text);
        $text = parent::doCodeBlocks($text);
        return $text;
    }
Beispiel #10
0
 public static function filter_post_content_out($content, $post)
 {
     static $textile;
     static $markdown;
     $markup = Options::get('Markup__markup_type');
     switch ($markup) {
         case 'markdown':
             //				return Markdown( $content );
             if (!isset($markdown)) {
                 $markdown = new Markdown_Parser();
             }
             return $markdown->transform($content);
             break;
         case 'textile':
             if (!isset($textile)) {
                 $textile = new Textile();
             }
             return $textile->TextileThis($content);
             break;
         case 'html':
         default:
             return $content;
     }
 }
 /**
  * Parse markdown
  *
  * @param $markdown
  * @return string The HTML
  */
 function parse_markdown($markdown)
 {
     if (!class_exists('Markdown_Parser')) {
         include plugin_dir_path(__FILE__) . 'inc/markdown.php';
     }
     $parser = new Markdown_Parser();
     return $parser->transform($markdown);
 }
Beispiel #12
0
 /**
  * Parse the incoming template
  *
  * @param string $tpl Source template content
  * @param array $vars List of variables passed to template engine
  *
  * @return string Processed template
  */
 public function render($tpl, $vars = array())
 {
     return $this->markdown->transform($tpl);
 }
Beispiel #13
0
 function teardown()
 {
     //
     // Clearing Extra-specific variables.
     //
     $this->footnotes = array();
     $this->footnotes_ordered = array();
     $this->footnotes_ref_count = array();
     $this->footnotes_numbers = array();
     $this->abbr_desciptions = array();
     $this->abbr_word_re = '';
     parent::teardown();
 }
Beispiel #14
0
 protected static function init()
 {
     if (self::$initialized) {
         return;
     }
     self::$initialized = TRUE;
     #
     # Prepare regular expressions for seraching emphasis tokens in any
     # context.
     #
     foreach (self::$em_relist as $em => $em_re) {
         foreach (self::$strong_relist as $strong => $strong_re) {
             # Construct list of allowed token expressions.
             $token_relist = array();
             if (isset(self::$em_strong_relist["{$em}{$strong}"])) {
                 $token_relist[] = self::$em_strong_relist["{$em}{$strong}"];
             }
             $token_relist[] = $em_re;
             $token_relist[] = $strong_re;
             # Construct master expression from list.
             $token_re = '{(' . implode('|', $token_relist) . ')}';
             self::$em_strong_prepared_relist["{$em}{$strong}"] = $token_re;
         }
     }
     self::$nested_brackets_re = str_repeat('(?>[^\\[\\]]+|\\[', self::nested_brackets_depth) . str_repeat('\\])*', self::nested_brackets_depth);
     self::$nested_url_parenthesis_re = str_repeat('(?>[^()\\s]+|\\(', self::nested_url_parenthesis_depth) . str_repeat('(?>\\)))*', self::nested_url_parenthesis_depth);
     self::$escape_chars_re = '[' . preg_quote(self::escape_chars) . ']';
     # Sort document, block, and span gamut in ascendent priority order.
     asort(self::$document_gamut);
     asort(self::$block_gamut);
     asort(self::$span_gamut);
 }
Beispiel #15
0
<?php

require_once 'libs/markdown.php';
$article = 'articles/' . $_GET['article'] . '.md';
$theme = isset($_GET['theme']) ? $_GET['theme'] : 'notmyidea';
if (file_exists($article)) {
    $content = file_get_contents($article);
    $parser = new Markdown_Parser();
    include 'themes/' . $theme . '/_header.php';
    echo $parser->transform($content);
    include 'themes/' . $theme . '/_footer.php';
}
Beispiel #16
0
function tc_post_process($text, $do_text = '', $do_char = '')
{
    if ('textile2' == $do_text) {
        require_once 'text-control/textile2.php';
        $t = new Textile();
        $text = $t->process($text);
    } else {
        if ('textile1' == $do_text) {
            require_once 'text-control/textile1.php';
            $text = textile($text);
        } else {
            if ('markdown' == $do_text) {
                require_once 'text-control/markdown.php';
                //$text = Markdown_Parser($text);
                $o = new Markdown_Parser();
                return $o->transform($text);
            } else {
                if ('txt2tags' == $do_text) {
                    require_once 'text-control/txt2tags.class.php';
                    $x = new T2T($text);
                    $x->go();
                    return $text = $x->bodyhtml;
                } else {
                    if ('wpautop' == $do_text) {
                        $text = wpautop($text);
                    } else {
                        if ('nl2br' == $do_text) {
                            $text = nl2br($text);
                        } else {
                            if ('none' == $do_text) {
                                $text = $text;
                            } else {
                                $text = wpautop($text);
                            }
                        }
                    }
                }
            }
        }
    }
    if ('smartypants' == $do_char) {
        require_once 'text-control/smartypants.php';
        $text = SmartyPants($text);
    } else {
        if ('wptexturize' == $do_char) {
            $text = wptexturize($text);
        } else {
            if ('none' == $do_char) {
                $text = $text;
            } else {
                $text = wptexturize($text);
            }
        }
    }
    return $text;
}
Beispiel #17
0
 /**
  * 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;
 }
Beispiel #18
0
 function transform($text)
 {
     #
     # Added clear to the new $html_hashes, reordered `hashHTMLBlocks` before
     # blank line stripping and added extra parameter to `runBlockGamut`.
     #
     # Clear the global hashes. If we don't clear these, you get conflicts
     # from other articles when generating a page which contains more than
     # one article (e.g. an index page that shows the N most recent
     # articles):
     $this->footnotes = array();
     $this->footnotes_ordered = array();
     $this->abbr_desciptions = array();
     $this->abbr_matches = array();
     $this->html_cleans = array();
     return parent::transform($text);
 }
Beispiel #19
0
<?php

use Verbier\Application;
Application::registerPlugin('Markdown', function ($app) {
    $app->helper('markdown', function ($text) {
        $parser = new Markdown_Parser();
        return $parser->transform($text);
    });
});
define('MARKDOWN_VERSION', "1.0.1n");
define('MARKDOWN_EMPTY_ELEMENT_SUFFIX', " />");
define('MARKDOWN_TAB_WIDTH', 4);
class Markdown_Parser
{
    # Regex to match balanced [brackets].
    # Needed to insert a maximum bracked depth while converting to PHP.
    var $nested_brackets_depth = 6;
    var $nested_brackets_re;
    var $nested_url_parenthesis_depth = 4;
    var $nested_url_parenthesis_re;
    # Table of hash values for escaped characters:
    var $escape_chars = '\\`*_{}[]()>#+-.!';
    var $escape_chars_re;
    # Change to ">" for HTML output.
    var $empty_element_suffix = MARKDOWN_EMPTY_ELEMENT_SUFFIX;
    var $tab_width = MARKDOWN_TAB_WIDTH;
    # Change to `true` to disallow markup or entities.
    var $no_markup = false;
    var $no_entities = false;
    # Predefined urls and titles for reference links and images.
    var $predef_urls = array();
Beispiel #20
0
 /**
  * Runs a string through Markdown.
  *
  * @param string $str
  *
  * @return string
  */
 public static function parseMarkdown($str)
 {
     if (!class_exists('\\Markdown_Parser', false)) {
         require_once craft()->path->getFrameworkPath() . 'vendors/markdown/markdown.php';
     }
     $md = new \Markdown_Parser();
     return $md->transform($str);
 }
Beispiel #21
0
 function process($text, $params = array())
 {
     #
     # strip bang-path #!markdown
     #
     if ($text[0] == '#' and $text[1] == '!') {
         list($line, $text) = explode("\n", $text, 2);
         $dum = preg_split('/\\s+/', $line);
         $myarg = $dum[1];
     }
     #
     # Added clear to the new $html_hashes, reordered `hashHTMLBlocks` before
     # blank line stripping and added extra parameter to `runBlockGamut`.
     #
     # Clear the global hashes. If we don't clear these, you get conflicts
     # from other articles when generating a page which contains more than
     # one article (e.g. an index page that shows the N most recent
     # articles):
     $this->footnotes = array();
     $this->footnotes_ordered = array();
     $this->abbr_desciptions = array();
     $this->abbr_matches = array();
     return parent::transform($text);
 }
Beispiel #22
0
 /**
  * Parse content to Markdown
  * @param  string $str     String to parse
  * @param  array  $options Associative array containing options
  *                         - encode_ee_tags (yes/no) can be used to disable
  *                         	ee tag encoding
  *                         - smartypants (yes/no) enable or disable
  *                         	smartypants
  *                         - no_markup (TRUE/FALSE) set to TRUE to disable
  *                          the parsing of markup in Markdown
  * @return string          Parsed Markdown content
  */
 public function markdown($str, $options = array())
 {
     require_once APPPATH . 'libraries/typography/Markdown/markdown.php';
     // Encode EE Tags
     if (!isset($options['encode_ee_tags']) or $options['encode_ee_tags'] == 'yes') {
         $str = ee()->functions->encode_ee_tags($str);
     }
     // Ignore [code]
     $code_blocks = array();
     preg_match_all("/\\[code\\](.*?)\\[\\/code\\]/uis", $str, $matches);
     foreach ($matches[0] as $match) {
         $hash = random_string('md5');
         $code_blocks[$hash] = $match;
         $str = str_replace($match, $hash, $str);
     }
     $parser = new Markdown_Parser();
     // Disable other markup if this is set
     if (isset($options['no_markup']) && $options['no_markup'] === TRUE) {
         $parser->no_markup = TRUE;
     }
     // Protect any quotes in EE tags from the Markdown and SmartyPants
     // processors.
     $str = $this->protect_quotes_in_tags($str);
     // Parse the Markdown
     $str = $parser->transform($str);
     // Run everything through SmartyPants
     if (!isset($options['smartypants']) or $options['smartypants'] == 'yes') {
         require_once APPPATH . 'libraries/typography/SmartyPants/smartypants.php';
         $str = SmartyPants($str);
     }
     // Restore the quotes we protected earlier.
     $str = $this->restore_quotes_in_tags($str);
     // Replace <pre><code> with [code]
     // Only relevant IF being called by typography parser
     $backtrace = debug_backtrace();
     if (!in_array($backtrace[1]['class'], array('EE_Typography', 'Markdown'))) {
         $str = preg_replace("/<pre><code>(.*?)<\\/code><\\/pre>/uis", "[code]\$1[/code]", $str);
     }
     // Replace [code]
     foreach ($code_blocks as $hash => $code_block) {
         $str = str_replace($hash, $code_block, $str);
     }
     return $str;
 }
Beispiel #23
0
 function apply($text)
 {
     require_once 'classMarkdown.php';
     $markdown = new Markdown_Parser();
     return $markdown->transform($text);
 }