Exemplo n.º 1
0
 /**
  * Handle the command.
  *
  * @param Markdown $markdown
  */
 public function handle(Markdown $markdown)
 {
     $this->command->info(strip_tags($markdown->transform(file_get_contents(base_path('LICENSE.md')))));
     if (!$this->command->confirm('Do you agree to the provided license and terms of service?')) {
         $this->command->error('You must agree to the license and terms of service before continuing.');
         exit;
     }
 }
Exemplo n.º 2
0
 public function getContentHtml()
 {
     if ($this->codeType == 'html') {
         return $this->ContentHtml = $this->content;
     } else {
         $md = new Markdown();
         $md->no_markup = true;
         $md->no_entities = true;
         return $this->ContentHtml = $md->transform($this->content);
     }
 }
Exemplo n.º 3
0
function loadPost($page)
{
    // traduire les donné du markdown en html
    $text = file_get_contents($page);
    $html = Markdown::defaultTransform($text);
    return $html;
}
Exemplo n.º 4
0
 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);
 }
Exemplo n.º 5
0
 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('/(^|\\&quot\\;|\'|\\(|\\[|\\{|\\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;
 }
Exemplo n.º 6
0
function transform($text)
{
    //Transforms a mardown text to LUNI flavored HTML
    //Only compiles Markdown atm
    $my_html = Markdown::defaultTransform($text);
    return $my_html;
}
Exemplo n.º 7
0
 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.");
     }
 }
Exemplo n.º 8
0
 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();
         }
     }
 }
Exemplo n.º 9
0
 /**
  * @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;
 }
Exemplo n.º 10
0
 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>';
             }
         }
     }
 }
 /**
  * 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);
 }
Exemplo n.º 12
0
 /**
  * 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;
 }
Exemplo n.º 13
0
function transform($mysql, $text)
{
    //Transforms a mardown text to LUNI flavored HTML
    $text = linkUsers($mysql, $text);
    $my_html = Markdown::defaultTransform($text);
    return $my_html;
}
Exemplo n.º 14
0
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 __construct()
 {
     $this->span_gamut += array('doAutoSteamLinks' => 5);
     parent::__construct();
     $this->empty_element_suffix = '>';
     $this->no_markup = true;
     $this->no_entities = true;
 }
Exemplo n.º 16
0
function smarty_block_markdown($params, $content, $template, &$repeat)
{
    if (!$repeat) {
        if (isset($content)) {
            return Markdown::defaultTransform($content);
        }
    }
}
Exemplo n.º 17
0
 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)]];
 }
Exemplo n.º 18
0
 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));
 }
Exemplo n.º 19
0
function process_body($b)
{
    $columns = explode("++", $b);
    foreach ($columns as &$b) {
        $b = trim($b);
        $b = Markdown::defaultTransform($b);
    }
    return $columns;
}
Exemplo n.º 20
0
 protected function loadCopy()
 {
     $copy = @file_get_contents($this->path . '/README.md');
     if ($copy) {
         return \Michelf\Markdown::defaultTransform($copy);
     } else {
         return false;
     }
 }
Exemplo n.º 21
0
 /**
  * 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;
     }
 }
Exemplo n.º 22
0
 /**
  * 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);
 }
Exemplo n.º 23
0
function process_event($b)
{
	$b_arr = explode("##", $b);
	foreach($b_arr as &$b)
	{
		$b = trim($b);
		$b = \Michelf\Markdown::defaultTransform($b);
	}
	return $b_arr;
}
Exemplo n.º 24
0
 /**
  * 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);
     }
 }
Exemplo n.º 25
0
 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;
 }
Exemplo n.º 26
0
 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 __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;
     }));
 }
Exemplo n.º 28
0
 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));
 }
Exemplo n.º 29
0
 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]);
 }
Exemplo n.º 30
0
 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;
     }
 }