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