friendica_2021-01/library/markdown.php

39 lines
1,020 B
PHP
Raw Normal View History

2011-04-11 14:59:26 +02:00
<?php
/**
* @file library/markdown.php
*
* @brief Parser for Markdown files
*/
require_once "library/php-markdown/Michelf/MarkdownExtra.inc.php";
2015-02-23 08:27:35 +01:00
use \Michelf\MarkdownExtra;
2015-02-22 20:06:13 +01: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 16:10:09 +02:00
* $hardwrap parameter is used to switch between inserting hard breaks after
* 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 16:10:09 +02:00
* @param boolean $hardwrap
* @return string
*/
2017-08-09 19:18:38 +02:00
function Markdown($text, $hardwrap = true) {
$a = get_app();
$stamp1 = microtime(true);
$MarkdownParser = new MarkdownExtra();
2017-08-09 19:19:42 +02:00
$MarkdownParser->hard_wrap = $hardwrap;
$html = $MarkdownParser->transform($text);
2015-02-22 20:06:13 +01:00
$a->save_timestamp($stamp1, "parser");
2015-02-23 08:27:35 +01:00
return $html;
2011-04-11 14:59:26 +02:00
}