use Friendica\BaseObject;
use Friendica\Core\System;
use Friendica\Model\Contact;
-use Michelf\MarkdownExtra;
/**
* Friendica-specific usage of Markdown
public static function convert($text, $hardwrap = true) {
$stamp1 = microtime(true);
- $MarkdownParser = new MarkdownExtra();
- $MarkdownParser->hard_wrap = $hardwrap;
- $MarkdownParser->code_class_prefix = 'language-';
+ $MarkdownParser = new MarkdownParser();
+ $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 = preg_replace('/<a(.*?)href="#/is', '<a$1href="' . ltrim($_SERVER['REQUEST_URI'], '/') . '#', $html);
self::getApp()->getProfiler()->saveTimestamp($stamp1, "parser", System::callstack());
--- /dev/null
+<?php\r
+namespace Friendica\Content\Text;\r
+\r
+use Friendica\Util\Strings;\r
+use Michelf\MarkdownExtra;\r
+\r
+class MarkdownParser extends MarkdownExtra\r
+{\r
+ protected function doAutoLinks($text)\r
+ {\r
+ $text = parent::doAutoLinks($text);\r
+\r
+ $text = preg_replace_callback(Strings::autoLinkRegEx(),\r
+ array($this, '_doAutoLinks_url_callback'), $text);\r
+\r
+ return $text;\r
+ }\r
+}
\ No newline at end of file