Пример #1
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(';');
 }
 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;
 }
Пример #3
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;
 }
 public function render($content)
 {
     $html = $this->getLayoutHead();
     $html .= MarkdownExtra::defaultTransform($content);
     $html .= $this->getLayoutFooter();
     return $html;
 }
Пример #5
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);
 }
Пример #6
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);
 }
Пример #7
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;
 }
Пример #8
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;
 }
Пример #9
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());
     });
 }
Пример #10
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);
 }
Пример #11
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);
 }
Пример #12
0
 public function toHtml($mdStr)
 {
     $html = $this->preTransformText($mdStr);
     $html = MarkdownExtra::defaultTransform($html);
     $html = SmartyPants::defaultTransform($html);
     $html = $this->postTransformText($html);
     return $html;
 }
 public static function markdown($content)
 {
     $html = \Michelf\MarkdownExtra::defaultTransform($content);
     if (Options::get('habarimarkdown__smarty', false)) {
         $html = SmartyPants($html);
     }
     return $html;
 }
Пример #14
0
 public function toHTML($text)
 {
     $text = $this->preTransformText($text);
     $text = MarkdownExtra::defaultTransform($text);
     $text = SmartyPants::defaultTransform($text);
     $text = $this->postTransformText($text);
     return $text;
 }
Пример #15
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);
     }
 }
Пример #16
0
 /**
  * Process the $text using settings with explode \n to <p>
  * @param $text
  * @return string
  */
 public function typo($text)
 {
     $t = $this->Setup();
     if ($this->markdown) {
         $text = MarkdownExtra::defaultTransform($text);
     }
     $t->set_text($text);
     return $t->apply();
 }
Пример #17
0
 /**
  * 访问器:文章内容(HTML 格式)
  * @return string
  */
 public function getContentAttribute($v)
 {
     switch ($this->attributes['content_format']) {
         case 'markdown':
             return MarkdownExtra::defaultTransform($v);
         case 'html':
             return $v;
     }
 }
Пример #18
0
function convertFile($src, $dst)
{
    $text = file_get_contents($src);
    $params = extractParams($text);
    $params['text'] = \Michelf\MarkdownExtra::defaultTransform($text);
    $html = loadTemplate($params['template'], $params);
    $dst = str_replace(array('.txt', '.md'), '.html', $dst);
    file_put_contents($dst, $html);
}
 /**
  * 文章内容(HTML 格式)
  * @return string
  */
 public function getContentHtmlAttribute()
 {
     switch ($this->content_format) {
         case 'markdown':
             return MarkdownExtra::defaultTransform($this->content);
         case 'html':
             return $this->content;
     }
 }
Пример #20
0
 protected function _render($page)
 {
     $path = realpath(LIBRARY . DIRECTORY_SEPARATOR . $page);
     $parts = explode('/', $page);
     $not_found = function () use($page) {
         $page = htmlspecialchars($page, ENT_QUOTES);
         throw new Exception("Page '{$page}' was not found");
     };
     if (!$this->_pathIsSafe($path)) {
         $not_found();
     }
     // Handle directories by showing a neat listing of its
     // contents
     if (is_dir($path)) {
         // Get a printable version of the actual folder name:
         $dir_name = htmlspecialchars(end($parts), ENT_QUOTES, 'UTF-8');
         // Get a printable version of the rest of the path,
         // so that we can display it with a different appearance:
         $rest_parts = array_slice($parts, 0, count($parts) - 1);
         $rest_parts = htmlspecialchars(join("/", $rest_parts), ENT_QUOTES, 'UTF-8');
         // Pass this to the render view, cleverly disguised as just
         // another page, so we can make use of the tree, breadcrumb,
         // etc.
         $page_data = $this->_default_page_data;
         $page_data['title'] = 'Listing: ' . $dir_name;
         return $this->_view('render', array('parts' => $parts, 'page' => $page_data, 'html' => "<h3><span class=\"directory-path\">{$rest_parts}/</span> {$dir_name}</h3>" . "<p>Use the tree menu on the left to select a file</p>", 'is_dir' => true));
     }
     $finfo = finfo_open(FILEINFO_MIME);
     $mime_type = finfo_file($finfo, $path);
     if (substr($mime_type, 0, 4) != 'text') {
         // not an ASCII file, send it directly to the browser
         $file = fopen($path, 'rb');
         header("Content-Type: {$mime_type}");
         header("Content-Length: " . filesize($path));
         fpassthru($file);
         exit;
     }
     $source = file_get_contents($path);
     $extension = pathinfo($path, PATHINFO_EXTENSION);
     $renderer = $this->_getRenderer($extension);
     $page_data = $this->_default_page_data;
     // Extract the JSON header, if the feature is enabled:
     if (USE_PAGE_METADATA) {
         list($source, $meta_data) = $this->_extractJsonFrontMatter($source);
         $page_data = array_merge($page_data, $meta_data);
     }
     // We need to know the source file in case editing is enabled:
     $page_data['file'] = $page;
     $html = false;
     if ($renderer && $renderer == 'HTML') {
         $html = $renderer($source);
     }
     if ($renderer && $renderer == 'Markdown') {
         $html = \Michelf\MarkdownExtra::defaultTransform($source);
     }
     return $this->_view('render', array('html' => $html, 'source' => $source, 'extension' => $extension, 'parts' => $parts, 'page' => $page_data, 'is_dir' => false, 'use_pastebin' => $this->_usePasteBin()));
 }
Пример #21
0
function Markdown($text)
{
    $a = get_app();
    $stamp1 = microtime(true);
    # Read file and pass content through the Markdown parser
    $html = MarkdownExtra::defaultTransform($text);
    $a->save_timestamp($stamp1, "parser");
    return $html;
}
Пример #22
0
 public static function get($param)
 {
     $data = self::getDb()->fetchOne(SqlMap\Article::getOne, self::$defaultSqlMap, $param);
     if ($data) {
         if ($data->content_format == 'markdown') {
             $data->content = MarkdownExtra::defaultTransform($data->content);
         }
     }
     return $data;
 }
Пример #23
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;
 }
Пример #24
0
 /**
  * 変換処理の実行
  * @param object $px Picklesオブジェクト
  */
 public static function exec($px)
 {
     foreach ($px->bowl()->get_keys() as $key) {
         $src = $px->bowl()->pull($key);
         if ($key != 'head' && $key != 'foot') {
             $src = \Michelf\MarkdownExtra::defaultTransform($src);
         }
         $px->bowl()->replace($src, $key);
     }
     return true;
 }
Пример #25
0
 public function getContentHtml()
 {
     $blogItem = $this->getModel()->getItem();
     if ($blogItem->codeType == 'html') {
         return $this->ContentHtml = $this->content;
     } elseif ($blogItem->codeType == 'reStructuredText') {
         $rst = new \RST_Parser();
         return $this->ContentHtml = $rst->transform($this->content);
     } else {
         return $this->ContentHtml = MarkdownExtra::defaultTransform($this->content);
     }
 }
Пример #26
0
 protected function transformMarkdown($str, $config)
 {
     $html = MarkdownExtra::defaultTransform($str);
     //@todo refactor parsers functions
     $trsf = new PressHTMLTransformer($this);
     $trsf->load($html);
     $trsf->applyTransforms();
     // There is no way to extract footnotes from the class, so we will get
     // them from the HTML parser
     $footnotes_html = $trsf->stripMarkdownExtraFootNotes();
     return ['html' => $trsf->toHTML(), 'footnotes_html' => $footnotes_html];
 }
Пример #27
0
 public static function parse($file = NULL)
 {
     $data = preg_replace('#/\\*.+?\\*/#s', '', self::readFile($file));
     // Remove comments and meta
     $data = preg_replace('@\\%BASE\\%@', BASE_URL, $data);
     // convert the base url
     //$html = Markdown::defaultTransform($data);
     $html = MarkdownExtra::defaultTransform($data);
     //$html = preg_replace('<table>', '<table class="' . TABE_CLASS . '">', $html);
     //$Extra = new \ParsedownExtra();
     //$html = $Extra->text($data);
     return self::post_process($html);
 }
Пример #28
0
 public function toHtml(array $data)
 {
     $text = $data['text'];
     $html = '<blockquote>';
     $html .= \Michelf\MarkdownExtra::defaultTransform($text);
     // Add the cite if necessary
     if (isset($data['cite']) && !empty($data['cite'])) {
         // remove the indent thats added by Sir Trevor
         $cite = ltrim($data['cite'], '>');
         $html .= '<cite>' . \Michelf\MarkdownExtra::defaultTransform($cite) . '</cite>';
     }
     $html .= '</blockquote>';
     return $html;
 }
Пример #29
0
 public function run()
 {
     if ($this->hasModel()) {
         $tagOptions = ArrayHelper::merge($this->options, ['id' => $this->targetId, 'class' => $this->clientOptions['class'] ?: '', 'data' => ['target' => $this->options['id']]]);
         if (isset($this->clientOptions['inline'])) {
             $value = Markdown::processParagraph(Html::getAttributeValue($this->model, $this->attribute));
             echo Html::tag($this->clientOptions['tag'] ?: 'p', $value, $tagOptions);
         } else {
             $value = MarkdownExtra::defaultTransform(Html::getAttributeValue($this->model, $this->attribute));
             echo Html::tag('section', Html::tag($this->clientOptions['tag'] ?: 'p', $value), $tagOptions);
         }
         echo Html::activeHiddenInput($this->model, $this->attribute);
     }
     $this->registerPlugin();
 }
Пример #30
0
 public static function markdown($content)
 {
     $content = \Michelf\MarkdownExtra::defaultTransform($content);
     // change table formatting
     $content = str_replace('<table>', '<table class="table table-striped table-condensed">', $content);
     // add syntax highlighter
     $content = preg_replace('|<pre><code class="([a-z]+?)">|s', '<pre><code class="language-$1">', $content);
     // auto link classes
     $content = preg_replace_callback('|(\\\\[A-Z][\\\\A-Za-z0-9]+)|s', function ($match) {
         $url = Factory::load('Url')->create('class/');
         $url .= str_replace('\\', '/', $match[0]);
         return '<a href="' . $url . '">' . $match[0] . '</a>';
     }, $content);
     return $content;
 }