Add new Content\Text\MarkdownParser
- Add autolinker to MarkdownParser->doAutoLinks() - Set hashtag_protection and url_filter_func properties of MarkdownParser
This commit is contained in:
parent
184b51ec56
commit
4d70e32829
2 changed files with 29 additions and 5 deletions
|
@ -9,7 +9,6 @@ namespace Friendica\Content\Text;
|
||||||
use Friendica\BaseObject;
|
use Friendica\BaseObject;
|
||||||
use Friendica\Core\System;
|
use Friendica\Core\System;
|
||||||
use Friendica\Model\Contact;
|
use Friendica\Model\Contact;
|
||||||
use Michelf\MarkdownExtra;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Friendica-specific usage of Markdown
|
* Friendica-specific usage of Markdown
|
||||||
|
@ -31,11 +30,18 @@ class Markdown extends BaseObject
|
||||||
public static function convert($text, $hardwrap = true) {
|
public static function convert($text, $hardwrap = true) {
|
||||||
$stamp1 = microtime(true);
|
$stamp1 = microtime(true);
|
||||||
|
|
||||||
$MarkdownParser = new MarkdownExtra();
|
$MarkdownParser = new MarkdownParser();
|
||||||
$MarkdownParser->hard_wrap = $hardwrap;
|
$MarkdownParser->code_class_prefix = 'language-';
|
||||||
$MarkdownParser->code_class_prefix = 'language-';
|
$MarkdownParser->hard_wrap = $hardwrap;
|
||||||
|
$MarkdownParser->hashtag_protection = true;
|
||||||
|
$MarkdownParser->url_filter_func = function ($url) {
|
||||||
|
if (strpos($url, '#') === 0) {
|
||||||
|
$url = ltrim($_SERVER['REQUEST_URI'], '/') . $url;
|
||||||
|
}
|
||||||
|
return $url;
|
||||||
|
};
|
||||||
|
|
||||||
$html = $MarkdownParser->transform($text);
|
$html = $MarkdownParser->transform($text);
|
||||||
$html = preg_replace('/<a(.*?)href="#/is', '<a$1href="' . ltrim($_SERVER['REQUEST_URI'], '/') . '#', $html);
|
|
||||||
|
|
||||||
self::getApp()->getProfiler()->saveTimestamp($stamp1, "parser", System::callstack());
|
self::getApp()->getProfiler()->saveTimestamp($stamp1, "parser", System::callstack());
|
||||||
|
|
||||||
|
|
18
src/Content/Text/MarkdownParser.php
Normal file
18
src/Content/Text/MarkdownParser.php
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
<?php
|
||||||
|
namespace Friendica\Content\Text;
|
||||||
|
|
||||||
|
use Friendica\Util\Strings;
|
||||||
|
use Michelf\MarkdownExtra;
|
||||||
|
|
||||||
|
class MarkdownParser extends MarkdownExtra
|
||||||
|
{
|
||||||
|
protected function doAutoLinks($text)
|
||||||
|
{
|
||||||
|
$text = parent::doAutoLinks($text);
|
||||||
|
|
||||||
|
$text = preg_replace_callback(Strings::autoLinkRegEx(),
|
||||||
|
array($this, '_doAutoLinks_url_callback'), $text);
|
||||||
|
|
||||||
|
return $text;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue