Ejemplo n.º 1
0
 /**
  * @param $markdown
  *
  * @return string
  */
 public function getHtmlFromMarkdown($markdown)
 {
     if (!isset($this->_markdownParser) || !$this->_markdownParser instanceof MarkdownParser) {
         $this->_markdownParser = new MarkdownParser();
     }
     return $this->_markdownParser->transformMarkdown($markdown);
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function parse($file, array $data = [])
 {
     $contents = $file;
     if (file_exists($file)) {
         $contents = file_get_contents($file);
     }
     return $this->markdown->transformMarkdown($contents);
 }
Ejemplo n.º 3
0
function get_posts($page = 1, $perpage = 0)
{
    if ($perpage == 0) {
        $perpage = config('posts.perpage');
    }
    $posts = get_post_names();
    // Extract a specific page with results
    $posts = array_slice($posts, ($page - 1) * $perpage, $perpage);
    $tmp = array();
    // Create a new instance of the markdown parser
    $md = new MarkdownParser();
    foreach ($posts as $k => $v) {
        $post = new stdClass();
        // Extract the date
        $arr = explode('_', $v);
        $post->date = strtotime(str_replace('posts/', '', $arr[0]));
        // The post URL
        $post->url = site_url() . date('Y/m', $post->date) . '/' . str_replace('.md', '', $arr[1]);
        // Get the contents and convert it to HTML
        $content = $md->transformMarkdown(file_get_contents($v));
        // Extract the title and body
        $arr = explode('</h1>', $content);
        $post->title = str_replace('<h1>', '', $arr[0]);
        $post->body = $arr[1];
        $tmp[] = $post;
    }
    return $tmp;
}
Ejemplo n.º 4
0
 public function _render($out, $args)
 {
     parent::_render($out, $args);
     $parser = new MarkdownParser();
     $html = $parser->transformMarkdown($out);
     $this->response->header('Content-Type', 'text/html; charset=' . $this->charset);
     $this->response->body($html);
     $this->response->send();
 }
Ejemplo n.º 5
0
 public function showDocs($chapter = null)
 {
     // Show installation page by default.
     if ($chapter === null) {
         $chapter = Config::get('doc::home', 'home');
     }
     // Build an array of file stubs to load from disk and
     // include the documentation index by default.
     $data = array('chapter' => $chapter, 'index' => Config::get('doc::index', 'documentation'));
     // Laravel promotes best practice, please handle Exceptions
     // wisely with appropriate try{}catch{} statements.
     try {
         // We use Markdown Extra for parsing, this library has been
         // included from the package composer.json.
         $markdown = new Markdown();
         // Walk through the data array, loading documentation from
         // the filesystem and converting it to markdown for display
         // on the documentation pages.
         array_walk($data, function (&$raw) use($markdown) {
             $path = public_path() . Config::get('doc::path', '/docs');
             $raw = File::get($path . "/{$raw}.md");
             $raw = $markdown->transformMarkdown($raw);
         });
     } catch (Exception $e) {
         // Catch all exceptions and abort the application with the 404
         // status command which will show our 404 page.
         App::abort(404);
     }
     // Parse the index to find out the next and previous pages and add links to them in the footer
     $dom = new DOMDocument();
     $dom->loadHTML($data['index']);
     $data['prev'] = false;
     $data['next'] = false;
     $foundCurrent = false;
     $data['title'] = '';
     $domLinks = $dom->getElementsByTagName('a');
     foreach ($domLinks as $domLink) {
         $link['URI'] = $domLink->getAttribute('href');
         $link['title'] = $domLink->nodeValue;
         if ($foundCurrent) {
             $data['next'] = $link;
             break;
         } else {
             $foundCurrent = str_replace(Config::get('doc::basehref', '/docs/'), '', $link['URI']) == $chapter;
             if (!$foundCurrent) {
                 $data['prev'] = $link;
             } else {
                 $data['title'] = $link['title'];
             }
         }
     }
     // Show the documentation template, which extends our master template
     // and provides a documentation index within the sidebar section.
     return View::make('doc::docs', $data);
 }
Ejemplo n.º 6
0
 /**
  *
  * @param Options $options
  *
  * @throws \Debril\RssAtomBundle\Exception\FeedNotFoundException
  *
  * @return FeedContent
  */
 public function getFeedContent(Options $options)
 {
     $feed = new FeedContent();
     $feed->setTitle('Symfony Sverige');
     $maxModified = null;
     foreach ($this->blogContentProvider->getAllEntries() as $entry) {
         $markdown = $this->markdownParser->transformMarkdown($entry->getContent());
         $url = $this->router->generate('blog', ['permalink' => $entry->getPermalink()], Router::ABSOLUTE_URL);
         $item = new FeedItem();
         $item->setUpdated($entry->getModifiedAt());
         $item->setTitle($entry->getTitle());
         $item->setDescription($this->excerpt->getExcerpt($markdown));
         $item->setLink($url);
         $feed->addItem($item);
         if (!$maxModified || $entry->getModifiedAt() > $maxModified) {
             $maxModified = $entry->getModifiedAt();
         }
     }
     if ($maxModified) {
         $feed->setLastModified($maxModified);
     }
     return $feed;
 }
 private function buildReadme(Addon $addon, $path)
 {
     $candidates = array('README.md', 'README.markdown', 'README.mdown', 'docs/en/index.md');
     foreach ($candidates as $candidate) {
         $lower = strtolower($candidate);
         $paths = array("{$path}/{$candidate}", "{$path}/{$lower}");
         foreach ($paths as $path) {
             if (!file_exists($path)) {
                 return;
             }
             $parser = new MarkdownParser();
             $readme = $parser->transformMarkdown(file_get_contents($path));
             $purifier = new HTMLPurifier();
             $readme = $purifier->purify($readme, array('Cache.SerializerPath' => TEMP_FOLDER));
             $addon->Readme = $readme;
             return;
         }
     }
 }
Ejemplo n.º 8
0
 public function renderPdf($id, $platformId)
 {
     $article = new Article($id);
     if (!$article->exists()) {
         return $this->renderNotFound();
     }
     $markdown = new MarkdownParser();
     $pdf = new \mPDF();
     $pdf->WriteHTML(sprintf('<h1>%s</h1>', $article->title));
     if ($article->title) {
         $pdf->WriteHTML(sprintf('<h2>%s</h2>', $article->subTitle));
     }
     foreach ($article->getArticleSections() as $section) {
         foreach ($section->getBlocks($platformId) as $block) {
             $pdf->WriteHTML($markdown->transformMarkdown($block->content));
             $pdf->WriteHTML('<br/>');
         }
     }
     $pdf->Output();
     exit;
 }
Ejemplo n.º 9
0
 public function parseMarkdown($markdown, array $context = array())
 {
     $parser = new MarkdownParser();
     $rendered = $this->renderString($markdown, $context);
     return $parser->transformMarkdown($rendered);
 }
Ejemplo n.º 10
0
 public function showPrivate($sl)
 {
     $chapter = Chapter::where('secret_link', '=', $sl)->first();
     if ($chapter->public_state == true && Book::where('id', '=', $chapter->book_id)->first()->public_state == true) {
         return Redirect::to('/chapter/' . $chapter->slug);
     }
     $markdownParser = new MarkdownParser();
     $markdownText = $markdownParser->transformMarkdown($chapter->text);
     return View::make('chapter.single', array('chapter' => $chapter, 'chapter_text' => $markdownText, 'pageTitle' => 'Chapter: ' . $chapter->title));
 }
Ejemplo n.º 11
0
// $markdownText = $markdownParser->transformMarkdown($chapter->text);
// return PDF::load($markdownText, 'A4', 'portrait')->show();
// }
// else
// {
// return Redirect::to('/')->with('global_error', 'You can\'t access private resources without a secret link, which can be received from creation\'s authSentryor.');
// }
// }
// return Redirect::to('/')->with('global_error', 'Sorry, chapter you are trying to reach doesn\'t exist.');
// }
// ));
//Blog scraps
Route::get('/libribook', array('as' => 'libribook', function () {
    $recent = Chapter::whereRaw('author_id = ? AND book_id = ? AND public_state = ?', array('1', '1', true))->orderBy('created_at', 'desc')->first();
    $markdownParser = new MarkdownParser();
    $markdownText = $markdownParser->transformMarkdown($recent->text);
    $chapters = Chapter::whereRaw('author_id = ? AND book_id = ? AND public_state = ?', array('1', '1', true))->orderBy('created_at', 'desc')->paginate(10);
    return View::make('allround.libribook', array('pageTitle' => 'Libri-book', 'recent' => $recent, 'recent_text' => $markdownText, 'chapters' => $chapters));
}));
//Route::group(array('https' => 'true', 'before' => 'ssl'), function() Use for SSL
//{
Route::get('user', 'UserController');
Route::get('register', 'UserController@create');
Route::post('register', array('before' => 'csrf', 'uses' => 'UserController@registerUser'));
Route::get('dashboard', array('before' => 'authSentry', 'uses' => 'UserController@dashboard'));
Route::get('profile/{nick}', array('uses' => 'UserController@profile'));
Route::get('profile_edit', array('before' => 'authSentry', 'uses' => 'UserController@edit'));
Route::put('profile_edit', array('before' => 'authSentry, csrf', 'uses' => 'UserController@editUser'));
Route::get('pass_change', array('before' => 'authSentry', 'uses' => 'UserController@passChange'));
Route::put('pass_change', array('before' => 'authSentry, csrf', 'uses' => 'UserController@passChangeAction'));
Route::get('profile/follow/{id}', array('before' => 'authSentry', 'uses' => 'UserController@follow'));
Ejemplo n.º 12
0
    $files = array();
    foreach ($matches[1] as $file) {
        $body = file_get_contents('articles/' . $file . '.md');
        $body = str_replace('%date%', time(), $body);
        file_put_contents('articles/' . $file . '.md', $body);
        $raw_body = $body;
        $body = explode("\n</info>\n", $body);
        $info = explode("\n", $body[0]);
        unset($info[0]);
        foreach ($info as $key => $value) {
            $value = explode(': ', $value, 2);
            $info[$value[0]] = $value[1];
            unset($info[$key]);
        }
        $info['raw_body'] = $raw_body;
        $info['body'] = $markdownParser->transformMarkdown($body[1]);
        $info['tags'] = explode(', ', $info['tags']);
        $info['slug'] = $file;
        // Cache
        $filename = 'cache/articles/' . $file . '.json';
        file_put_contents($filename, json_encode($info));
        $article = array('title' => $info['title'], 'slug' => $info['slug'], 'author' => $info['author'], 'date' => $info['date'], 'tags' => $info['tags'], 'summary' => $info['summary']);
        array_unshift($articles, $article);
        echo "Added {$file}." . PHP_EOL;
        $files[] = $file;
    }
    file_put_contents('articles/articles.json', json_encode($articles));
    echo PHP_EOL . shell_exec('git commit -am "[auto] Deployed articles.

' . implode(PHP_EOL, $files) . '" && git push origin master');
} else {
Ejemplo n.º 13
0
 /**
  * Parse the given documentation blocks with a Markdown parser and return
  * the resulting formatted blocks as HTML snippets.
  *
  * @param  array $rawDocBlocks The raw documentation blocks to parse.
  *
  * @return array
  */
 protected function parseDocblocks($rawDocBlocks)
 {
     $parsedDocBlocks = array();
     $docBlockParser = new MarkdownParser();
     foreach ($rawDocBlocks as $docBlock) {
         $docBlock = preg_replace(self::REGEX_DOCBLOCK_TYPE, '$1$2 `$4` ', $docBlock);
         $docBlock = preg_replace(self::REGEX_DOCBLOCK_VAR, '$1`$2`', $docBlock);
         $docBlock = preg_replace(self::REGEX_DOCBLOCK_ARG, "\n<em class=\"docparam\">\$1</em>", $docBlock);
         $parsedDocBlocks[] = $docBlockParser->transformMarkdown($docBlock);
     }
     return $parsedDocBlocks;
 }