add a switch to the Markdown parser for using hard line breaks (issue 3592)
This commit is contained in:
parent
4d77c8a90a
commit
6504156508
3 changed files with 31 additions and 6 deletions
|
@ -1,14 +1,39 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file library/markdown.php
|
||||||
|
*
|
||||||
|
* @brief Parser for Markdown files
|
||||||
|
*/
|
||||||
|
|
||||||
require_once "library/php-markdown/Michelf/MarkdownExtra.inc.php";
|
require_once "library/php-markdown/Michelf/MarkdownExtra.inc.php";
|
||||||
use \Michelf\MarkdownExtra;
|
use \Michelf\MarkdownExtra;
|
||||||
|
|
||||||
function Markdown($text) {
|
/**
|
||||||
|
* @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
|
||||||
|
* $hardbreak 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
|
||||||
|
* @param boolean $hardbreak
|
||||||
|
* @returns string
|
||||||
|
*/
|
||||||
|
|
||||||
|
function Markdown($text, $hardbreak=true) {
|
||||||
$a = get_app();
|
$a = get_app();
|
||||||
|
|
||||||
$stamp1 = microtime(true);
|
$stamp1 = microtime(true);
|
||||||
|
|
||||||
$MarkdownParser = new MarkdownExtra();
|
$MarkdownParser = new MarkdownExtra();
|
||||||
|
if ($hardbreak) {
|
||||||
$MarkdownParser->hard_wrap = true;
|
$MarkdownParser->hard_wrap = true;
|
||||||
|
} else {
|
||||||
|
$MarkdownParser->hard_wrap = false;
|
||||||
|
}
|
||||||
$html = $MarkdownParser->transform($text);
|
$html = $MarkdownParser->transform($text);
|
||||||
|
|
||||||
$a->save_timestamp($stamp1, "parser");
|
$a->save_timestamp($stamp1, "parser");
|
||||||
|
|
|
@ -1687,7 +1687,7 @@ function admin_page_plugins(App $a) {
|
||||||
$readme=Null;
|
$readme=Null;
|
||||||
if (is_file("addon/$plugin/README.md")) {
|
if (is_file("addon/$plugin/README.md")) {
|
||||||
$readme = file_get_contents("addon/$plugin/README.md");
|
$readme = file_get_contents("addon/$plugin/README.md");
|
||||||
$readme = Markdown($readme);
|
$readme = Markdown($readme, false);
|
||||||
} elseif (is_file("addon/$plugin/README")) {
|
} elseif (is_file("addon/$plugin/README")) {
|
||||||
$readme = "<pre>". file_get_contents("addon/$plugin/README") ."</pre>";
|
$readme = "<pre>". file_get_contents("addon/$plugin/README") ."</pre>";
|
||||||
}
|
}
|
||||||
|
@ -1939,7 +1939,7 @@ function admin_page_themes(App $a) {
|
||||||
$readme = Null;
|
$readme = Null;
|
||||||
if (is_file("view/theme/$theme/README.md")) {
|
if (is_file("view/theme/$theme/README.md")) {
|
||||||
$readme = file_get_contents("view/theme/$theme/README.md");
|
$readme = file_get_contents("view/theme/$theme/README.md");
|
||||||
$readme = Markdown($readme);
|
$readme = Markdown($readme, false);
|
||||||
} elseif (is_file("view/theme/$theme/README")) {
|
} elseif (is_file("view/theme/$theme/README")) {
|
||||||
$readme = "<pre>". file_get_contents("view/theme/$theme/README") ."</pre>";
|
$readme = "<pre>". file_get_contents("view/theme/$theme/README") ."</pre>";
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ function help_content(App $a) {
|
||||||
$filename = "Home";
|
$filename = "Home";
|
||||||
$a->page['title'] = t('Help');
|
$a->page['title'] = t('Help');
|
||||||
} else {
|
} else {
|
||||||
$a->page['aside'] = Markdown($home);
|
$a->page['aside'] = Markdown($home, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strlen($text)) {
|
if (!strlen($text)) {
|
||||||
|
@ -60,7 +60,7 @@ function help_content(App $a) {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
$html = Markdown($text);
|
$html = Markdown($text, false);
|
||||||
|
|
||||||
if ($filename !== "Home") {
|
if ($filename !== "Home") {
|
||||||
// create TOC but not for home
|
// create TOC but not for home
|
||||||
|
|
Loading…
Reference in a new issue