function loadPost($page) { // traduire les donné du markdown en html $text = file_get_contents($page); $html = Markdown::defaultTransform($text); return $html; }
public function __construct($file, $app = null) { $env = $app->environment; $info = new \SplFileInfo($file); $this->type = $info->getExtension(); $file_text = file_get_contents($file); $file_header = substr($file_text, 0, strpos($file_text, '}') + 1); $file_header = json_decode($file_header, true); $page_path = ltrim(str_replace($env['PAGES_ROOT_PATH'], '', $file), '/'); $this->id = str_replace('.' . $this->type, '', $page_path); $this->header = $file_header; if (!isset($this->header['order'])) { $this->header['order'] = ''; } $file_body = substr_replace($file_text, '', 0, strpos($file_text, '}') + 2); $this->contents = $file_body; if ($this->type == 'md') { $this->contents = str_replace('@@siteurl@@', $env['ROOT_PATH'], $this->contents); $this->contents = Markdown::defaultTransform($this->contents); } else { if ($this->type == 'html') { $this->contents = str_replace('@@siteurl@@', $env['ROOT_PATH'], $this->contents); } else { if ($this->type == 'txt') { $this->contents = '<p>' . str_replace("\n", '</p><p>', $this->contents) . '</p>'; } } } }
public function __invoke($string = null) { if (!class_exists('Michelf\\Markdown')) { require_once __DIR__ . '/vendor/php-markdown/Michelf/Markdown.inc.php'; } return \Michelf\Markdown::defaultTransform($string); }
function transform($mysql, $text) { //Transforms a mardown text to LUNI flavored HTML $text = linkUsers($mysql, $text); $my_html = Markdown::defaultTransform($text); return $my_html; }
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { $user = User::findWithPermission($id); $document = $this->policyRepository->getByName('member-agreement'); $htmlDocument = Markdown::defaultTransform($document); return view('account.induction.show')->with('user', $user)->with('document', $htmlDocument); }
function onStartNoticeSave($notice) { // Only run this on local notices if ($notice->isLocal()) { $text = $notice->content; // From /lib/util.php::common_render_text // We don't want to call it directly since we don't want to // run common_linkify() on the text $text = common_remove_unicode_formatting($text); $text = preg_replace('/[\\x{0}-\\x{8}\\x{b}-\\x{c}\\x{e}-\\x{19}]/', '', $text); $text = common_replace_urls_callback($text, 'common_linkify'); // Link #hashtags $rendered = preg_replace_callback('/(^|\\"\\;|\'|\\(|\\[|\\{|\\s+)#([\\pL\\pN_\\-\\.]{1,64})/u', function ($m) { return "{$m[1]}#" . common_tag_link($m[2]); }, $text); // Link @mentions, !mentions, @#mentions $rendered = common_linkify_mentions($rendered, $notice->getProfile(), $notice->hasParent() ? $notice->getParent() : null); // Prevent leading #hashtags from becoming headers by adding a backslash // before the "#", telling markdown to leave it alone // $repl_rendered = preg_replace('/^#[\pL\pN_\-\.]{1,64}/u', 'replaced!', $rendered); $repl_rendered = preg_replace('/^#<span class="tag">/u', '\\\\\\0', $rendered); // Only use the replaced value from above if it returned a success if ($rendered !== null) { $rendered = $repl_rendered; } // handle Markdown link forms in order not to convert doubly. $rendered = preg_replace('/\\[([^]]+)\\]\\((<a [^>]+>)([^<]+)<\\/a>\\)/u', '\\2\\1</a>', $rendered); // Convert Markdown to HTML $notice->rendered = \Michelf\Markdown::defaultTransform($rendered); } return true; }
function transform($text) { //Transforms a mardown text to LUNI flavored HTML //Only compiles Markdown atm $my_html = Markdown::defaultTransform($text); return $my_html; }
public function handleRequest() { // TODO create "page not found" page $uri = Request::path(); // Default version of the documentation $page = 'introduction'; $versions = array("4.0", "4.1", "4.2", "4.3", "4.6", "5.0", "5.6", "5.12"); $version = end($versions); // If not the root, then split the uri to find the content $segment1 = Request::segment(1); $segment2 = Request::segment(2); if (!empty($segment1)) { $version = $segment1; if (!empty($segment2)) { $page = $segment2; } } // Show the correct markdown contents $page = __DIR__ . '/docs/' . $version . '/' . $page . '.md'; if (file_exists($page)) { $contents = file_get_contents($page); $sidebar = file_get_contents(__DIR__ . '/docs/' . $version . '/sidebar.md'); // Transform documents $contents_html = Markdown::defaultTransform($contents); $sidebar_html = Markdown::defaultTransform($sidebar); // Replace url variable $sidebar_html = preg_replace('/{url}/mi', URL::to($version), $sidebar_html); return View::make('layouts.master')->with('version', $version)->with('versions', $versions)->with('sidebar', $sidebar_html)->with('content', $contents_html); } else { \App::abort(400, "The page you were looking for could not be found."); } }
public function processAll($viewType) { foreach ($this->posts as $post) { if (!$post->isRepost() && $post->hasAnnotation(self::ANNOTATION_TYPE)) { // Use longpost template $post->setTemplate('longpost.twig.html'); // Convert longpost annotation to HTML and move to meta for access from the template $annotation = $post->getAnnotationValue(self::ANNOTATION_TYPE); $post->setMetaField('title', $annotation['title']); $post->setMetaField('truncated', false); $bodyLines = explode("\n", $annotation['body']); if ($viewType == View::PERMALINK) { $body = $annotation['body']; } else { $body = ''; $i = 0; foreach ($bodyLines as $l) { if (trim($l) != '') { $body .= $l . "\n\n"; $i++; if ($i >= self::TRUNCATED_PARAGRAPH_COUNT) { $post->setMetaField('truncated', true); break; } } } } $post->set('html', Markdown::defaultTransform($body)); $post->setMetaField('description', $bodyLines[0]); // Do not handle other annotations $post->stopProcessing(); } } }
/** * @param array $values * @return bool * @throws \UnexpectedValueException * @throws \InvalidArgumentException */ public function send(array $values) { $this->values = $values; // Substitute markers $subject = $this->renderWithFluid($this->getSubject(), $values); $body = $this->renderWithFluid($this->getBody(), $values); // Parse body through Markdown processing. $body = Markdown::defaultTransform($body); $this->getMailMessage()->setFrom($this->getFrom())->setTo($this->getTo())->setSubject($subject); // According to preference. if ($this->isPlainTextPreferred()) { $text = Html2Text::getInstance()->convert($body); $this->getMailMessage()->setBody($text); } else { $this->getMailMessage()->setBody($body, 'text/html'); // Attach plain text version if HTML tags are found in body if ($this->hasHtml($body)) { $text = Html2Text::getInstance()->convert($body); $this->getMailMessage()->addPart($text, 'text/plain'); } } // Handle attachment #foreach ($this->attachments as $attachment) { # $this->getMailMessage()->attach($attachment); #} $this->getMailMessage()->send(); $isSent = $this->getMailMessage()->isSent(); $this->getLoggingService()->log($this->getMailMessage()); return $isSent; }
/** * Get github readme * * @param array $atts * @param string $content * @return string */ public function _eg_shortcode_readme($atts) { $atts = shortcode_atts(array('repo' => 'johnie/embedgithub', 'file' => false, 'trim' => 0), $atts); $transient = "embedgithub_" . $atts['repo'] . "_" . $atts['file'] . "_" . $atts['trim']; if (false === ($html = get_transient($transient))) { if ($atts['file']) { $url = "https://api.github.com/repos/" . $atts['repo'] . "/contents/" . $atts['file']; } else { $url = "https://api.github.com/repos/" . $atts['repo'] . "/readme"; } $ch = curl_init(); $timeout = 5; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERAGENT, 'WordPress'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $data = curl_exec($ch); curl_close($ch); $json = json_decode($data); $markdown = base64_decode($json->content); if ($atts['trim'] > 0) { $markdown = implode("\n", array_slice(explode("\n", $markdown), $atts['trim'])); } $html = Markdown::defaultTransform($markdown); set_transient($transient, $html, 12 * HOUR_IN_SECONDS); } return $html; }
public function indexAction() { $title = '# Hello world ! '; $content = '*This is my first mardown parsing !*'; $my_html_title = Markdown::defaultTransform($title); $my_html_content = Markdown::defaultTransform($content); return $this->render('KarkTutoBundle:Default:index.html.twig', array('title' => $my_html_title, 'content' => $my_html_content)); }
function smarty_function_markdown($params, &$smarty) { if (!in_array('text', array_keys($params))) { trigger_error("markdown missing 'text' parameter", E_USER_NOTICE); return; } return Markdown::defaultTransform($params['text']); }
public function makeEmbed($embed, $markdown) { $position = $embed['position']; $url = $embed['url']; $text = $embed['text']; $line = $embed['line']; return ['url' => $url, 'text' => $text, 'markdown' => $line, 'html' => rtrim(strip_tags(Markdown::defaultTransform($line), '<a>')), 'indices' => [$position, $position + strlen($text)]]; }
function smarty_block_markdown($params, $content, $template, &$repeat) { if (!$repeat) { if (isset($content)) { return Markdown::defaultTransform($content); } } }
function process_body($b) { $columns = explode("++", $b); foreach ($columns as &$b) { $b = trim($b); $b = Markdown::defaultTransform($b); } return $columns; }
protected function loadCopy() { $copy = @file_get_contents($this->path . '/README.md'); if ($copy) { return \Michelf\Markdown::defaultTransform($copy); } else { return false; } }
/** * Transforms Markdown to HTML using {@link https://michelf.ca/projects/php-markdown/ PHP Markdown}. * One special feature is single line detection - if the passed $text is single line, this function * removes the wrapping `<p>` element which PHPMarkdown automatically adds. * * @param $text * @return string HTML */ public static function transform($text) { $html = \Michelf\Markdown::defaultTransform($text); if (strstr($text, "\n")) { return $html; } else { // single line, unwrap the <p> tag return substr($html, 3, -3); } }
/** * Método que renderiza una página en formato Markdown * @param file Archivo que se desea renderizar * @param vars Arreglo con variables que se desean pasar * @return Buffer de la página renderizada * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]delaf.cl) * @version 2014-03-29 */ public static function render($file, $variables = array()) { $data = file_get_contents($file); foreach ($variables as $key => $valor) { if (!is_object($valor)) { $data = str_replace('{' . $key . '}', $valor, $data); } } return \Michelf\Markdown::defaultTransform($data); }
public function getPage($page) { $pagehtml = '<h2>' . $page . ' not found!</h2>'; $path = $this->datapath . '/' . $page . '.md'; if (file_exists($path)) { $pagehtml = Markdown::defaultTransform(file_get_contents($path)); } $page = new Wikipage($page, $pagehtml); return $page; }
function process_event($b) { $b_arr = explode("##", $b); foreach($b_arr as &$b) { $b = trim($b); $b = \Michelf\Markdown::defaultTransform($b); } return $b_arr; }
/** * Adapter for Markdown that caches the result * * @param string $text The content to parse from MarkDown to HTML * * @return string The HTML */ public static function parse($text) { try { return Cache::item('foolframe.model.markdown.parse.md5.' . md5($text))->get(); } catch (\OutOfBoundsException $e) { $parsed = M::defaultTransform($text); Cache::item('foolframe.model.markdown.parse.md5.' . md5($text))->set($parsed, 900); return $parsed; } }
public function setTemplateFilters() { //markdown $this->template->addFilter('md', function ($s) { return \Michelf\Markdown::defaultTransform($s); }); //inline markdown $this->template->addFilter('imd', function ($s) { return strip_tags(Markdown::defaultTransform($s), '<a><strong><em>'); }); }
public function readBySlug($slug) { if (!is_string($slug)) { throw new InvalidArgumentException('slug must be a string.'); } $path = "{$this->pageFolder}/{$slug}.md"; if (!file_exists($path)) { throw new InvalidPageException($slug); } return Markdown::defaultTransform(file_get_contents($path)); }
public function __construct($name = null) { parent::__construct(); // Load Twig templates $loader = new \Twig_Loader_Filesystem(getcwd() . '/src/templates'); $this->twig = new \Twig_Environment($loader, array('debug' => false)); $this->twig->addExtension(new \Twig_Extension_Debug()); // Custom filter for parsing the endpoint URI $this->twig->addFilter(new \Twig_SimpleFilter('parseUri', function ($baseUrl, $uriTemplate, $action) { // Check if the URI Template has parameters if (strpos($uriTemplate, '{?') !== false) { $resultString = preg_match('/{(.*?)}/', $uriTemplate, $matches); $resultString = $matches[1]; if (strpos($resultString, '?') !== false) { $resultString = str_replace(',', '&', substr($resultString, 1)); $urlParameters = explode('&', $resultString); } foreach ($urlParameters as $key => $urlParameter) { $urlParameters[$key] = $urlParameter . '=' . $action['parameters'][$key]['example']; } $start = strpos($uriTemplate, '{'); $convertedUrl = substr_replace($uriTemplate, '', $start); foreach ($urlParameters as $key => $urlParameter) { $convertedUrl .= ($key === 0 ? '?' : '&') . $urlParameter; } } else { if (strpos($uriTemplate, '{') !== false) { foreach ($action['parameters'] as $parameter) { $convertedUrl = str_replace('{' . $parameter['name'] . '}', $parameter['example'], $uriTemplate); } } else { $convertedUrl = $uriTemplate; } } return $baseUrl . $convertedUrl; })); // Custom filter for parsing Markdown $this->twig->addFilter(new \Twig_SimpleFilter('markdown', function ($string) { return Markdown::defaultTransform($string); })); // Custom filter for creating a slug with an optional prefix/suffix $this->twig->addFilter(new \Twig_SimpleFilter('slugify', function ($string, $prefix = null, $suffix = null) { $slugify = new Slugify(); return $slugify->slugify($prefix . $string . $suffix); })); // Custom filter for extracting keys from a multidimensional array $this->twig->addFilter(new \Twig_SimpleFilter('arrayFromKey', function ($array, $key) { $result = array(); foreach ($array as $value) { $result[] = $value[$key]; } return $result; })); }
public function docsAction($doc) { if (!in_array($doc, ['contributing', 'customize', 'usage', 'vagrant'])) { throw new NotFoundHttpException(); } $docfile = $this->get('docs.path') . DIRECTORY_SEPARATOR . $doc . '.md'; $content = ""; if (is_file($docfile)) { $content = Markdown::defaultTransform(file_get_contents($docfile)); } return $this->render('docs.html.twig', ['content' => $content]); }
/** * Converts the code to HTML * * @param File $file File to render * @param Tool_Result $res Tool result to integrate * * @return string HTML */ public function toHtml(File $file, Tool_Result $res = null) { if (class_exists('\\Michelf\\Markdown', true)) { //composer-installed version 1.4+ $markdown = \Michelf\Markdown::defaultTransform($file->getContent()); } else { //PEAR-installed version 1.0.2 has a different API require_once 'markdown.php'; $markdown = \markdown($file->getContent()); } return '<div class="markdown">' . $markdown . '</div>'; }
public function get_all_posts($options = array()) { $category = null; $settings = Settings::instance(); if ($handle = opendir($settings->posts_dir)) { $files = array(); $filetimes = array(); while (false !== ($entry = readdir($handle))) { if (substr(strrchr($entry, '.'), 1) == ltrim($settings->get("file_ext"), '.')) { // Define the post file. $fcontents = file($settings->posts_dir . $entry); if (count($fcontents) < 6) { continue; } // Ensure file meets parse requirements // Define the post title. $post_title = \Michelf\Markdown::defaultTransform($fcontents[0]); // Define the post author. $post_author = str_replace(array("\n", '-'), '', $fcontents[1]); // Define the post author Twitter account. $post_author_twitter = str_replace(array("\n", '- '), '', $fcontents[2]); // Define the published date. $post_date = str_replace('-', '', $fcontents[3]); // Define the post category. $post_category = str_replace(array("\n", '-'), '', $fcontents[4]); // Early return if we only want posts from a certain category if (isset($options["category"]) && $options["category"] && $options["category"] != trim(strtolower($post_category))) { continue; } // Define the post status. $post_status = str_replace(array("\n", '- '), '', $fcontents[5]); // Define the post intro. $post_intro = \Michelf\Markdown::defaultTransform($fcontents[7]); // Define the post content $post_content = \Michelf\Markdown::defaultTransform(join('', array_slice($fcontents, 6, count($fcontents) - 1))); // Pull everything together for the loop. $files[] = array('fname' => $entry, 'post_title' => $post_title, 'post_author' => $post_author, 'post_author_twitter' => $post_author_twitter, 'post_date' => $post_date, 'post_category' => $post_category, 'post_status' => $post_status, 'post_intro' => $post_intro, 'post_content' => $post_content); $post_dates[] = $post_date; $post_titles[] = $post_title; $post_authors[] = $post_author; $post_authors_twitter[] = $post_author_twitter; $post_categories[] = $post_category; $post_statuses[] = $post_status; $post_intros[] = $post_intro; $post_contents[] = $post_content; } } array_multisort($post_dates, SORT_DESC, $files); return $files; } else { return false; } }
/** *###Main parsing method. * Uses the php tokenizer to separate comments from code * * @return `array` * * `array("code"=>array of code, "docs"=>array of docs)` * **/ public function parse($file) { $fname = $file; $file = file_get_contents($file); $code = ""; $all_matches = array(); $prev_token = false; /* This is the main parsing technique. It splits a php file into two arrays of comments * and corresponding code. To do this is uses the PHP tokenizer to analyze the file * for comments. */ foreach (token_get_all($file) as $tok) { if (is_array($tok)) { if (in_array(token_name($tok[0]), $this->comment_tokens)) { if (isset($prev_tok[0]) && token_name($prev_tok[0]) == "T_COMMENT" && token_name($tok[0]) == "T_COMMENT") { $last = array_pop($all_matches); $tok[1] = str_replace("\t", " ", $tok[1]); $all_matches[] = $last . preg_replace($this->comment_blocks, "\$1", $tok[1]); } else { $tok[1] = str_replace("\t", " ", $tok[1]); $all_matches[] = preg_replace($this->comment_blocks, "\$1", $tok[1]); $code .= "\n//CODEBLOCK\n"; } } else { $code .= $tok[1]; } } else { $code .= $tok; } $prev_token = $tok; } // Passes code onto pygmentize to add syntax highlighting $pyg = new Pygment(); $code = $pyg->pygmentize("php", $code); $code = explode('<span class="c1">//CODEBLOCK</span>', $code); array_shift($code); foreach ($code as &$val) { $val = rtrim($val); $val = str_replace("\t", " ", $val); $val = '<div class="highlight"><pre>' . trim($val, "\n\r") . '</pre></div>'; } // Adds html markup to identify php docblock parameters $docs = array(); foreach ($all_matches as $match) { $match = preg_replace($this->doc_params, "<em class='docparam'>\$1</em>", $match); $docs[] = Markdown::defaultTransform($match); } // Our final array of code mapped to comments return array("code" => $code, "docs" => $docs); }
public function toHtml(array $data) { $text = $data['text']; $html = '<blockquote>'; $html .= Markdown::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>' . Markdown::defaultTransform($cite) . '</cite>'; } $html .= '</blockquote>'; return $html; }