Move library/markdown.php to src

This commit is contained in:
Hypolite Petovan 2018-01-14 18:59:08 -05:00
parent 903b960d4c
commit fabbf810b0
6 changed files with 52 additions and 55 deletions

View File

@ -1,14 +1,12 @@
<?php
use Friendica\App;
use Friendica\Content\Text\Markdown;
use Friendica\Core\System;
use Friendica\Model\Contact;
use Friendica\Network\Probe;
use League\HTMLToMarkdown\HtmlConverter;
require_once 'include/event.php';
require_once 'library/markdown.php';
require_once 'include/html2bbcode.php';
require_once 'include/bbcode.php';
@ -58,7 +56,7 @@ function diaspora2bb($s) {
// Escaping the hash tags
$s = preg_replace('/\#([^\s\#])/', '&#35;$1', $s);
$s = Markdown($s);
$s = Markdown::convert($s);
$regexp = "/@\{(?:([^\}]+?); )?([^\} ]+)\}/";
$s = preg_replace_callback($regexp, 'diaspora_mention2bb', $s);

View File

@ -1,37 +0,0 @@
<?php
/**
* @file library/markdown.php
*
* @brief Parser for Markdown files
*/
use \Michelf\MarkdownExtra;
/**
* @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
* $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
* @param boolean $hardwrap
* @return string
*/
function Markdown($text, $hardwrap = true) {
$a = get_app();
$stamp1 = microtime(true);
$MarkdownParser = new MarkdownExtra();
$MarkdownParser->hard_wrap = $hardwrap;
$html = $MarkdownParser->transform($text);
$a->save_timestamp($stamp1, "parser");
return $html;
}

View File

@ -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 = "<pre>" . file_get_contents("addon/$plugin/README") . "</pre>";
}
@ -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 = "<pre>" . file_get_contents("view/theme/$theme/README") . "</pre>";
}

View File

@ -1,11 +1,11 @@
<?php
use Friendica\App;
use Friendica\Content\Text\Markdown;
require_once 'include/bbcode.php';
require_once 'library/markdown.php';
require_once 'include/bb2diaspora.php';
require_once 'include/html2bbcode.php';
require_once 'include/pgettext.php';
function visible_lf($s)
{
@ -51,7 +51,7 @@ function babel_content()
$o .= '<h2>' . t('bb2diaspora: ') . '</h2>' . EOL . EOL;
$o .= visible_lf($diaspora) . EOL . EOL;
$html = Markdown($diaspora);
$html = Markdown::convert($diaspora);
$o .= '<h2>' . t('bb2diaspora => Markdown: ') . '</h2>' . EOL . EOL;
$o .= $html . EOL . EOL;

View File

@ -1,10 +1,9 @@
<?php
use Friendica\App;
use Friendica\Content\Text\Markdown;
use Friendica\Core\System;
require_once('library/markdown.php');
if (!function_exists('load_doc_file')) {
function load_doc_file($s) {
@ -50,7 +49,7 @@ function help_content(App $a) {
$filename = "Home";
$a->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

View File

@ -0,0 +1,39 @@
<?php
/**
* @file src/Content/Text/Markdown.php
*/
namespace Friendica\Content\Text;
use Friendica\BaseObject;
use Michelf\MarkdownExtra;
/**
* Friendica-specific usage of Markdown
*
* @author Hypolite Petovan <mrpetovan@gmail.com>
*/
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;
}
}