2011-04-11 08:59:26 -04:00
|
|
|
<?php
|
2017-08-09 10:04:53 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @file library/markdown.php
|
|
|
|
*
|
|
|
|
* @brief Parser for Markdown files
|
|
|
|
*/
|
|
|
|
|
2017-03-25 02:03:47 -04:00
|
|
|
require_once "library/php-markdown/Michelf/MarkdownExtra.inc.php";
|
2015-02-23 02:27:35 -05:00
|
|
|
use \Michelf\MarkdownExtra;
|
2015-02-22 14:06:13 -05:00
|
|
|
|
2017-08-09 10:04:53 -04:00
|
|
|
/**
|
|
|
|
* @brief This function parses a text using php-markdown library to render Markdown syntax to HTML
|
|
|
|
*
|
|
|
|
* This function is using the php-markdown library by Michel Fortin to parse a
|
|
|
|
* string ($text).It returns the rendered HTML code from that text. The optional
|
2017-08-09 10:10:09 -04:00
|
|
|
* $hardwrap parameter is used to switch between inserting hard breaks after
|
2017-08-09 10:04:53 -04:00
|
|
|
* every linefeed, which is required for Diaspora compatibility, or not. The
|
|
|
|
* later is used for parsing documentation and README.md files.
|
|
|
|
*
|
|
|
|
* @param string $text
|
2017-08-09 10:10:09 -04:00
|
|
|
* @param boolean $hardwrap
|
|
|
|
* @return string
|
2017-08-09 10:04:53 -04:00
|
|
|
*/
|
|
|
|
|
2017-08-09 10:10:09 -04:00
|
|
|
function Markdown($text, $hardwrap=true) {
|
2015-02-23 18:08:17 -05:00
|
|
|
$a = get_app();
|
|
|
|
|
|
|
|
$stamp1 = microtime(true);
|
|
|
|
|
2017-03-23 21:23:00 -04:00
|
|
|
$MarkdownParser = new MarkdownExtra();
|
2017-08-09 10:10:09 -04:00
|
|
|
if ($hardwrap) {
|
2017-08-09 10:04:53 -04:00
|
|
|
$MarkdownParser->hard_wrap = true;
|
|
|
|
} else {
|
|
|
|
$MarkdownParser->hard_wrap = false;
|
|
|
|
}
|
2017-03-23 21:23:00 -04:00
|
|
|
$html = $MarkdownParser->transform($text);
|
2015-02-22 14:06:13 -05:00
|
|
|
|
2015-02-24 04:21:09 -05:00
|
|
|
$a->save_timestamp($stamp1, "parser");
|
2015-02-23 18:08:17 -05:00
|
|
|
|
2015-02-23 02:27:35 -05:00
|
|
|
return $html;
|
2011-04-11 08:59:26 -04:00
|
|
|
}
|