]> git.mxchange.org Git - friendica.git/blob - library/markdown.php
Merge pull request #3620 from tobiasd/20170809-issue3592
[friendica.git] / library / markdown.php
1 <?php
2
3 /**
4  * @file library/markdown.php
5  *
6  * @brief Parser for Markdown files
7  */
8
9 require_once "library/php-markdown/Michelf/MarkdownExtra.inc.php";
10 use \Michelf\MarkdownExtra;
11
12 /**
13  * @brief This function parses a text using php-markdown library to render Markdown syntax to HTML
14  *
15  * This function is using the php-markdown library by Michel Fortin to parse a 
16  * string ($text).It returns the rendered HTML code from that text. The optional 
17  * $hardwrap parameter is used to switch between inserting hard breaks after
18  * every linefeed, which is required for Diaspora compatibility, or not. The
19  * later is used for parsing documentation and README.md files.
20  *
21  * @param string $text
22  * @param boolean $hardwrap
23  * @return string
24  */
25
26 function Markdown($text, $hardwrap = true) {
27         $a = get_app();
28
29         $stamp1 = microtime(true);
30
31         $MarkdownParser = new MarkdownExtra();
32         $MarkdownParser->hard_wrap = $hardwrap;
33         $html = $MarkdownParser->transform($text);
34
35         $a->save_timestamp($stamp1, "parser");
36
37         return $html;
38 }