From fabbf810b0b830bab695d957b1f4ebb85afbd990 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 14 Jan 2018 18:59:08 -0500 Subject: [PATCH] Move library/markdown.php to src --- include/bb2diaspora.php | 6 ++---- library/markdown.php | 37 --------------------------------- mod/admin.php | 12 +++++------ mod/babel.php | 6 +++--- mod/help.php | 7 +++---- src/Content/Text/Markdown.php | 39 +++++++++++++++++++++++++++++++++++ 6 files changed, 52 insertions(+), 55 deletions(-) delete mode 100644 library/markdown.php create mode 100644 src/Content/Text/Markdown.php diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php index daa8c5e04..73210860d 100644 --- a/include/bb2diaspora.php +++ b/include/bb2diaspora.php @@ -1,14 +1,12 @@ hard_wrap = $hardwrap; - $html = $MarkdownParser->transform($text); - - $a->save_timestamp($stamp1, "parser"); - - return $html; -} diff --git a/mod/admin.php b/mod/admin.php index e7463a360..81ede51c0 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -4,10 +4,12 @@ * * @brief Friendica admin */ + use Friendica\App; use Friendica\Content\Feature; -use Friendica\Core\System; +use Friendica\Content\Text\Markdown; use Friendica\Core\Config; +use Friendica\Core\System; use Friendica\Core\Worker; use Friendica\Database\DBM; use Friendica\Database\DBStructure; @@ -1777,9 +1779,7 @@ function admin_page_plugins(App $a) $readme = Null; if (is_file("addon/$plugin/README.md")) { - require_once 'library/markdown.php'; - $readme = file_get_contents("addon/$plugin/README.md"); - $readme = Markdown($readme, false); + $readme = Markdown::convert(file_get_contents("addon/$plugin/README.md"), false); } elseif (is_file("addon/$plugin/README")) { $readme = "
" . file_get_contents("addon/$plugin/README") . "
"; } @@ -2028,9 +2028,7 @@ function admin_page_themes(App $a) $readme = null; if (is_file("view/theme/$theme/README.md")) { - require_once 'library/markdown.php'; - $readme = file_get_contents("view/theme/$theme/README.md"); - $readme = Markdown($readme, false); + $readme = Markdown::convert(file_get_contents("view/theme/$theme/README.md"), false); } elseif (is_file("view/theme/$theme/README")) { $readme = "
" . file_get_contents("view/theme/$theme/README") . "
"; } diff --git a/mod/babel.php b/mod/babel.php index 2b8c37901..a4fbd172e 100644 --- a/mod/babel.php +++ b/mod/babel.php @@ -1,11 +1,11 @@ ' . t('bb2diaspora: ') . '' . EOL . EOL; $o .= visible_lf($diaspora) . EOL . EOL; - $html = Markdown($diaspora); + $html = Markdown::convert($diaspora); $o .= '

' . t('bb2diaspora => Markdown: ') . '

' . EOL . EOL; $o .= $html . EOL . EOL; diff --git a/mod/help.php b/mod/help.php index 9a4b275f9..65221165f 100644 --- a/mod/help.php +++ b/mod/help.php @@ -1,10 +1,9 @@ page['title'] = t('Help'); } else { - $a->page['aside'] = Markdown($home, false); + $a->page['aside'] = Markdown::convert($home, false); } if (!strlen($text)) { @@ -61,7 +60,7 @@ function help_content(App $a) { )); } - $html = Markdown($text, false); + $html = Markdown::convert($text, false); if ($filename !== "Home") { // create TOC but not for home diff --git a/src/Content/Text/Markdown.php b/src/Content/Text/Markdown.php new file mode 100644 index 000000000..2615aa411 --- /dev/null +++ b/src/Content/Text/Markdown.php @@ -0,0 +1,39 @@ + + */ +class Markdown extends BaseObject +{ + /** + * Converts a Markdown string into HTML. The hardwrap parameter maximizes + * compatibility with Diaspora in spite of the Markdown standard. + * + * @brief Converts a Markdown string into HTML + * @param string $text + * @param bool $hardwrap + * @return string + */ + public static function convert($text, $hardwrap = true) { + $stamp1 = microtime(true); + + $MarkdownParser = new MarkdownExtra(); + $MarkdownParser->hard_wrap = $hardwrap; + $html = $MarkdownParser->transform($text); + + self::getApp()->save_timestamp($stamp1, "parser"); + + return $html; + } +}