/** * 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; }
/** * 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; }
/** * 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); }
/** * 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); }
/** * 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; }
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; }
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()); }); }
/** * 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); }
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); }
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; }
public function toHTML($text) { $text = $this->preTransformText($text); $text = MarkdownExtra::defaultTransform($text); $text = SmartyPants::defaultTransform($text); $text = $this->postTransformText($text); return $text; }
/** * 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); } }
/** * 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(); }
/** * 访问器:文章内容(HTML 格式) * @return string */ public function getContentAttribute($v) { switch ($this->attributes['content_format']) { case 'markdown': return MarkdownExtra::defaultTransform($v); case 'html': return $v; } }
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; } }
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())); }
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; }
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; }
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; }
/** * 変換処理の実行 * @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; }
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); } }
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]; }
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); }
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; }
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(); }
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; }