Пример #1
0
 public function renderFullpage(AbstractMediaEntity $entity)
 {
     /* @var MarkdownEntity $entity */
     $raw = file_get_contents($entity->getPath());
     $rendered = $this->markdownExtraParser->transform($raw);
     return $this->renderEngine->render('CmfcmfMediaModule:MediaType/Markdown:Fullpage.html.twig', ['entity' => $entity, 'rendered' => $rendered, 'raw' => $raw]);
 }
Пример #2
0
 /**
  * @param string $text
  * @return string
  */
 public function block($text)
 {
     $pattern = '~<(code|pre)>(.+?)</\\1>|```php\\s(.+?)\\n```~s';
     $highlighted = preg_replace_callback($pattern, [$this, 'highlightCb'], $text);
     $text = $this->markdown->transform($highlighted);
     return trim($text);
 }
Пример #3
0
 /**
  * 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(';');
 }
Пример #4
0
    /** 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');
    }
Пример #5
0
 /**
  * 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;
 }
Пример #6
0
 /**
  * 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);
 }
Пример #7
0
 public function parse($text)
 {
     $markdown = new MarkdownExtra();
     $text = $this->doShortcodes($text);
     $text = $markdown->transform($text);
     $text = $this->extendTags($text);
     return $text;
 }
Пример #8
0
 /**
  * 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);
 }
Пример #9
0
 /**
  * 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);
     }
 }
Пример #10
0
 private function parse($str)
 {
     if (!preg_match($this->regex, $str, $matches) === 1) {
         throw new \DomainException('Invalid markdown format');
     }
     $meta = trim($matches[2]) !== '' ? $this->yamlParser->parse(trim($matches[2])) : null;
     $str = ltrim($matches[4]);
     return new Post($meta['id'], $meta['title'], $meta['summary'], $this->markdownParser->transform($str), $meta['tags'], $meta['published'], $meta['modified']);
 }
Пример #11
0
 /**
  * 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);
 }
Пример #12
0
 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;
 }
Пример #13
0
 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);
 }
Пример #14
0
 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);
     }
 }
Пример #15
0
 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);
     }
 }
Пример #16
0
 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);
 }
Пример #17
0
 /**
  * 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;
 }
 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;
 }
 public function render($content)
 {
     $html = $this->getLayoutHead();
     $html .= MarkdownExtra::defaultTransform($content);
     $html .= $this->getLayoutFooter();
     return $html;
 }
Пример #20
0
 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;
 }
Пример #21
0
 public function transform($text)
 {
     $text = parent::transform($text);
     $harusame = new \Denshoch\Harusame(array("autoTcy" => $this->autoTcy, "tcyDigit" => $this->tcyDigit, "autoTextOrientation" => $this->autoTextOrientation));
     $text = $harusame->transform($text);
     return $text;
 }
 public function transform($text)
 {
     $text = parent::transform($text);
     $text = preg_replace_callback(TBGTextParser::getIssueRegex(), array($this, '_parse_issuelink'), $text);
     $text = preg_replace_callback(TBGTextParser::getMentionsRegex(), array($this, '_parse_mention'), $text);
     return $text;
 }
Пример #23
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 MichelfMarkdown converter.');
     }
     return MarkdownExtra::defaultTransform($input);
 }
Пример #24
0
 /**
  * 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);
 }
Пример #25
0
 /**
  * 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;
 }
Пример #26
0
 /**
  * @param CollectionEntity|AbstractMediaEntity $entity
  *
  * @return string
  */
 public function escapeDescription($entity)
 {
     $description = $entity->getDescription();
     $strategy = null;
     $hookName = null;
     if ($entity instanceof CollectionEntity) {
         $strategy = \ModUtil::getVar('CmfcmfMediaModule', 'descriptionEscapingStrategyForCollection');
         $hookName = 'collections';
     } elseif ($entity instanceof AbstractMediaEntity) {
         $strategy = \ModUtil::getVar('CmfcmfMediaModule', 'descriptionEscapingStrategyForMedia');
         $hookName = 'media';
     } else {
         throw new \LogicException();
     }
     $eventName = "cmfcmfmediamodule.filter_hooks.{$hookName}.filter";
     $hook = new \Zikula_FilterHook($eventName, $description);
     $description = $this->hookDispatcher->dispatch($eventName, $hook)->getData();
     switch ($strategy) {
         case 'raw':
             return $description;
         case 'text':
             return htmlentities($description);
         case 'markdown':
             return $this->markdownExtra->transform($description);
         default:
             throw new \LogicException();
     }
 }
Пример #27
0
 public function toHtml($mdStr)
 {
     $html = $this->preTransformText($mdStr);
     $html = MarkdownExtra::defaultTransform($html);
     $html = SmartyPants::defaultTransform($html);
     $html = $this->postTransformText($html);
     return $html;
 }
Пример #28
0
 public function toHTML($text)
 {
     $text = $this->preTransformText($text);
     $text = MarkdownExtra::defaultTransform($text);
     $text = SmartyPants::defaultTransform($text);
     $text = $this->postTransformText($text);
     return $text;
 }
Пример #29
0
 public function getContent($page)
 {
     $pageFile = $this->getDocumentationPath() . "/{$page}.md";
     return $this->cache->rememberForever("doc_page_{$pageFile}_content", function () use($pageFile) {
         $data = $this->parser->parse($this->finder->get($pageFile));
         return MarkdownExtra::defaultTransform($data->getContent());
     });
 }
Пример #30
0
 public function getParsedContent()
 {
     // Replace old announcements
     $oldAnnouncementDiv = ['<div style="color:#222;width:400px;font-family:Georgia, serif;text-align:justify;line-height:14pt;' . 'font-size:12pt;">', '<div style="color:#222;width:400px;font-family:Georgia, serif;text-align:left;line-height:14pt;' . 'font-size:12pt;">'];
     $newOldAnnouncementDiv = '<div style="width:400px;font-family:Georgia, serif;text-align:justify;' . 'line-height:14pt;font-size:12pt;">';
     $content = str_replace($oldAnnouncementDiv, $newOldAnnouncementDiv, $this->content);
     return MarkdownExtra::defaultTransform($content);
 }