php Michelf-MarkdownExtra类(方法)实例源码

下面列出了php Michelf-MarkdownExtra 类(方法)源码代码实例,从而了解它的用法。

作者:bgao-c    项目:vasema   
/**
  * compile
  *
  * @param \Twig_Compiler $compiler
  *
  * @return  void
  */
 public function compile(\Twig_Compiler $compiler)
 {
     $data = $this->getNode('value')->getAttribute('data');
     $markdown = new MarkdownExtra();
     $data = $markdown->defaultTransform($data);
     $compiler->write('echo ')->string($data)->raw(';');
 }

作者:bibyzhan    项目:produce_cm   
/** markdown格式接口 */
    public function develop_public()
    {
        $gData = checkData($_GET);
        $int_opt = $gData['int_opt'];
        if (!$int_opt) {
            ajaxReturn('非法操作[缺少必须参数]', 300);
        }
        //样式
        echo '<style>
            .markdown-here-wrapper h1{ font-size: 20px; font-weight:bold; margin-top: 10px;}
            .markdown-here-wrapper h2{ font-size: 18px; font-weight:bold; margin-top: 10px;}
            .markdown-here-wrapper h3{ font-size: 16px; font-weight:bold; margin-top: 10px;}
            .markdown-here-wrapper table{ border-collapse: collapse; border: 1px solid yellowgreen;}
            .markdown-here-wrapper th { vertical-align: baseline; border: 1px solid yellowgreen; font-weight:bold; font-size: 18px;}
            .markdown-here-wrapper td { vertical-align: middle; border: 1px solid yellowgreen; font-size: 18px;}
            .markdown-here-wrapper tr { border: 1px solid yellowgreen;}

            .markdown-here-wrapper p a{font-size: 16px;}
            </style>';
        $output = $text = file_get_contents(MODULE_PATH . 'develop_info/' . $int_opt . '.md');
        $parser = new MarkdownExtra();
        $my_html = $parser->transform($output);
        $this->s->assign('my_html', $my_html);
        $this->s->display('interface_admin/interface_list.html');
    }

作者:Trul    项目:windspeaker-dem   
/**
  * prepareData
  *
  * @param \Windwalker\Data\Data $data
  *
  * @return  void
  */
 protected function prepareData($data)
 {
     $markdown = new MarkdownExtra();
     foreach ($data['posts'] as $post) {
         $post->link = Router::buildHtml('front:post_default', ['id' => $post->id, 'alias' => $post->alias]);
         $post->introtext = $markdown->defaultTransform($post->introtext);
         $post->author = Author::getPostAuthor($post->author);
         $post->created = new Date($post->created);
         $post->created = $post->created->format('F j, Y');
     }
     foreach ($data['statics'] as $post) {
         $post->link = Router::buildHtml('front:static_default', ['id' => $post->id, 'alias' => $post->alias]);
     }
     // Title
     if ($data->type == 'home') {
         $title = $data->blog->title;
         $suffix = '';
         $data->bodyClass = 'home posts page-' . $data->page;
     } else {
         $title = '';
         $suffix = $data->blog->title;
         $data->bodyClass = 'home posts page-' . $data->page;
     }
     $data->pageTitle = $title;
     $data->pageTitle .= $data->page > 1 ? ' - Page ' . $data->page : '';
     $data->pageTitle .= $suffix ? '|' . $suffix : '';
     // Meta
     $desc = $data->blog->description;
     $desc = OutputFilter::cleanText($desc);
     $desc = Utf8String::substr($desc, 0, 200);
     $data->meta->desc = $desc;
 }

作者:bgao-c    项目:vasema   
/**
  * render
  *
  * @return  string
  */
 public function render()
 {
     $md = file_get_contents($this->file->getPathname());
     $md = $this->prepareData($md);
     $markdown = new MarkdownExtra();
     $content = $markdown->defaultTransform($md);
     return $this->output = $this->renderLayout($content);
 }

作者:Absolute-Softwar    项目:laravel-apidoc   
public function parse($text)
 {
     $markdown = new MarkdownExtra();
     $text = $this->doShortcodes($text);
     $text = $markdown->transform($text);
     $text = $this->extendTags($text);
     return $text;
 }

作者:patrov    项目:Phil   
/**
  * overload parse with the MarkdownExtra parser
  *
  * @param $data
  *
  * @return string
  */
 public function parse($data)
 {
     $parser = new MarkdownExtra();
     foreach ($this->config as $key => $value) {
         $parser->{$key} = $value;
     }
     return $parser->transform($data);
 }

作者:Trul    项目:windspeaker-dem   
/**
  * prepareData
  *
  * @param \Windwalker\Data\Data $data
  *
  * @return  void
  */
 protected function prepareData($data)
 {
     $markdown = new MarkdownExtra();
     foreach ($data['posts'] as $post) {
         $post->link = Router::buildHtml('front:post_default', ['id' => $post->id, 'alias' => $post->alias]);
         $post->introtext = $markdown->defaultTransform($post->introtext);
         $post->author = Author::getPostAuthor($post->author);
     }
 }

作者:kangq    项目:yii2-markdow   
/**
  * Converts markdown into HTML
  *
  * @param string $content
  * @param array $config
  * @return string
  */
 public static function process($content, $config = [])
 {
     if (static::$markdown === null) {
         static::$markdown = new MarkdownExtra();
     }
     foreach ($config as $name => $value) {
         static::$markdown->{$name} = $value;
     }
     return static::$markdown->transform($content);
 }

作者:sloan5    项目:karma-te   
public function toHTML($text)
 {
     $html = new MarkdownExtra();
     $html->code_attr_on_pre = true;
     $text = $this->preTransformText($text);
     $text = $html->defaultTransform($text);
     $text = SmartyPants::defaultTransform($text);
     $text = $this->postTransformText($text);
     return $text;
 }

作者:sunnycame    项目:swoole.co   
static function parseMarkdown($text)
 {
     //GitHub Code Parse
     $text = str_replace('```', '~~~', $text);
     $parser = new Michelf\MarkdownExtra();
     $parser->fn_id_prefix = "post22-";
     $parser->code_attr_on_pre = false;
     $parser->tab_width = 4;
     return $parser->transform($text);
 }

作者:snje198    项目:markdow   
public function test_custom_code()
 {
     $markdown = new MarkdownExtra();
     $markdown->custom_code_parser = function ($class, $code) {
         return '<' . $class . '>' . $code . '</' . $class . '>';
     };
     $tests = [["```..svg\n123123123\n```", "<svg>123123123\n</svg>\n"], ["#111\n```..svg\n123123123\n```", "<h1>111</h1>\n\n<svg>123123123\n</svg>\n"]];
     foreach ($tests as $v) {
         $ret = $markdown->transform($v[0]);
         $this->assertEquals($v[1], $ret);
     }
 }

作者:snje198    项目:markdow   
public function test_TodoList()
 {
     $markdown = new MarkdownExtra();
     $markdown->custom_code_parser = function ($class, $code) {
         return '<' . $class . '>' . $code . '</' . $class . '>';
     };
     $tests = [["## aaa\n[] 1111", "<h2>aaa</h2>\n\n<p class=\"todo\"><input type=\"checkbox\" disabled=\"disabled\" />1111</p>"], ["[*] 2222", '<p class="todo"><input type="checkbox" disabled="disabled" checked="checked" />2222</p>'], ['[+]3333', '<p class="todo"><input type="checkbox" disabled="disabled" checked="checked" />3333</p>'], ['[ ]4444[111](https://www.baidu.com)', '<p class="todo"><input type="checkbox" disabled="disabled" />4444<a href="https://www.baidu.com">111</a></p>'], ['[-]55`abc`55', '<p class="todo"><input type="checkbox" disabled="disabled" />55<code>abc</code>55</p>'], ["## aaa\n() 1111", "<h2>aaa</h2>\n\n<p class=\"todo\"><input type=\"radio\" disabled=\"disabled\" />1111</p>"], ["(*) 2222", '<p class="todo"><input type="radio" disabled="disabled" checked="checked" />2222</p>'], ['(+)3333', '<p class="todo"><input type="radio" disabled="disabled" checked="checked" />3333</p>'], ['( )4444[111](https://www.baidu.com)', '<p class="todo"><input type="radio" disabled="disabled" />4444<a href="https://www.baidu.com">111</a></p>'], ['(-)55`abc`55', '<p class="todo"><input type="radio" disabled="disabled" />55<code>abc</code>55</p>']];
     foreach ($tests as $v) {
         $ret = $markdown->transform($v[0]);
         $this->assertEquals($v[1] . "\n", $ret);
     }
 }

作者:jarve    项目:jarve   
public function transform($text)
 {
     $parser = new MarkdownExtra();
     $stylesAdded = false;
     if (class_exists('Kadet\\Highlighter\\Language\\Language')) {
         $parser->code_block_content_func = function ($code, $language) use(&$stylesAdded) {
             if (!$stylesAdded) {
                 $this->pageStack->getPageResponse()->addCssFile('@Jarves/keylighter/default.scss');
                 $stylesAdded = true;
             }
             return Highlighter\highlight($code, Language::byName($language));
         };
     }
     return $parser->transform($text);
 }

作者:webshark    项目:cor   
/**
  * A very simple markdown parser.
  *
  * @since 150424 Initial release.
  *
  * @param mixed $value Any input value.
  * @param array $args  Any additional behavioral args.
  *
  * @return string|array|object Html markup value(s).
  */
 public function __invoke($value, array $args = [])
 {
     if (is_array($value) || is_object($value)) {
         foreach ($value as $_key => &$_value) {
             $_value = $this->__invoke($_value, $args);
         }
         //unset($_key, $_value);
         return $value;
     }
     if (!($string = (string) $value)) {
         return $string;
         // Nothing to do.
     }
     $default_args = ['flavor' => 'markdown-extra', 'breaks' => true, 'anchorize' => false, 'anchor_rels' => [], 'no_p' => false];
     $args = array_merge($default_args, $args);
     $args = array_intersect_key($args, $default_args);
     $flavor = (string) $args['flavor'];
     $breaks = (bool) $args['breaks'];
     $no_p = (bool) $args['no_p'];
     $anchorize = (bool) $args['anchorize'];
     $anchor_rels = (array) $args['anchor_rels'];
     if ($flavor === 'parsedown-extra') {
         if (is_null($ParsedownExtra =& $this->cacheKey(__FUNCTION__, $flavor))) {
             $ParsedownExtra = new ParsedownExtra();
         }
         $ParsedownExtra->setBreaksEnabled($breaks);
         $string = $ParsedownExtra->text($string);
     } else {
         $flavor = 'markdown-extra';
         // Default flavor.
         if (is_null($MarkdownExtra =& $this->cacheKey(__FUNCTION__, $flavor))) {
             $MarkdownExtra = new MarkdownExtra();
             $MarkdownExtra->code_class_prefix = 'language-';
         }
         $string = $MarkdownExtra->transform($string);
     }
     if ($anchorize) {
         $string = $this->c::htmlAnchorize($string);
     }
     if ($anchor_rels) {
         $string = $this->c::htmlAnchorRels($string, $anchor_rels);
     }
     if ($no_p) {
         // Strip ` ^<p>|</p>$ ` tags?
         $string = preg_replace('/^\\s*(?:\\<p(?:\\s[^>]*)?\\>)+|(?:\\<\\/p\\>)+\\s*$/ui', '', $string);
     }
     return $string;
 }

作者:KartikPadmanabha    项目:markdown-resum   
protected function generateHtml($source, $template, $refresh)
 {
     // Check that the source file is sane
     if (!file_exists($source)) {
         throw new \Exception("Unable to open source file: {$source}");
     }
     // Check that our template is sane, or set to the default one
     if (!$template) {
         $template = $this->app->defaultTemplate;
     }
     $templatePath = join(DIRECTORY_SEPARATOR, array($this->app->templatePath, basename($template)));
     $templateIndexPath = join(DIRECTORY_SEPARATOR, array($templatePath, 'index.html'));
     if (!file_exists($templateIndexPath)) {
         throw new \Exception("Unable to open template file: {$templateIndexPath}");
     }
     $style = $this->generateContent($templatePath, 'css');
     $links = $this->generateContent($templatePath, 'links');
     $templateContent = file_get_contents($templateIndexPath);
     $resumeContent = file_get_contents($source);
     // Process with Markdown, and then use SmartyPants to clean up punctuation.
     $resumeHtml = MarkdownExtra::defaultTransform($resumeContent);
     $resumeHtml = SmartyPants::defaultTransform($resumeHtml);
     // Construct the title for the html document from the h1 and h2 tags
     $simpleDom = HtmlDomParser::str_get_html($resumeHtml);
     $title = sprintf('%s | %s', $simpleDom->find('h1', 0)->innertext, $simpleDom->find('h2', 0)->innertext);
     // Render the Markdown into an html file with Mustache Templates
     $m = new \Mustache_Engine();
     $rendered = $m->render($templateContent, array('title' => $title, 'style' => $style, 'links' => $links, 'resume' => $resumeHtml, 'reload' => (bool) $refresh, 'refresh_rate' => $refresh));
     return $rendered;
 }

作者:mimi    项目:silex-documentation-provide   
public function render($content)
 {
     $html = $this->getLayoutHead();
     $html .= MarkdownExtra::defaultTransform($content);
     $html .= $this->getLayoutFooter();
     return $html;
 }

作者:hotl    项目:JustWritin   
public function markdown($value = '')
 {
     $text = $value;
     $html = MarkdownExtra::defaultTransform($text);
     $html = preg_replace('/<img src="images\\/([^\\"]*)"/i', '<img src="/posts/images/$1"', $html);
     return $html;
 }

作者:jjk-jack    项目:Spres   
/**
  * 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 MichelfMarkdown converter.');
     }
     return MarkdownExtra::defaultTransform($input);
 }

作者:panca    项目:Spres   
/**
  * Convert the input data
  * 
  * @param string $input The raw content without Front-matter
  * 
  * @return string
  */
 public function convert($input)
 {
     if (!is_string($input)) {
         throw new \InvalidArgumentException('Expected Markdown string to parse');
     }
     return MarkdownExtra::defaultTransform($input);
 }

作者:kamicrafte    项目:designhu   
/**
  * Runs the given string through the "markup" parser (MarkdownExtra).
  *
  * @param string $source
  *
  * @return string
  */
 public function parseMarkup($source)
 {
     $source = $this->callHook('modifySmartDownMarkupInput', $source);
     $source = MarkdownExtra::defaultTransform($source);
     $source = $this->callHook('modifySmartDownMarkupOutput', $source);
     return $source;
 }


问题


面经


文章

微信
公众号

扫码关注公众号