diff --git a/composer.json b/composer.json index a91504c..0126d61 100644 --- a/composer.json +++ b/composer.json @@ -15,6 +15,7 @@ "doctrine/doctrine-migrations-bundle": "^3.2", "doctrine/orm": "^2.16", "jdenticon/jdenticon": "^1.0", + "league/commonmark": "^2.4", "phpdocumentor/reflection-docblock": "^5.3", "phpstan/phpdoc-parser": "^1.24", "rhilip/bencode": "^2.3", @@ -45,8 +46,9 @@ "symfony/validator": "6.3.*", "symfony/web-link": "6.3.*", "symfony/yaml": "6.3.*", - "twig/extra-bundle": "^2.12|^3.0", + "twig/extra-bundle": "^3.7", "twig/intl-extra": "^3.7", + "twig/markdown-extra": "^3.7", "twig/string-extra": "^3.7", "twig/twig": "^2.12|^3.0", "yggverse/scrapeer": "^0.5.4" diff --git a/src/Twig/AppExtension.php b/src/Twig/AppExtension.php index 6cf5813..6d4e987 100644 --- a/src/Twig/AppExtension.php +++ b/src/Twig/AppExtension.php @@ -39,6 +39,13 @@ class AppExtension extends AbstractExtension 'formatAgo' ] ), + new TwigFilter( + 'url_to_markdown', + [ + $this, + 'urlToMarkdown' + ] + ), ]; } @@ -135,6 +142,17 @@ class AppExtension extends AbstractExtension } } + public function urlToMarkdown( + string $text + ) : string + { + return preg_replace( + '~(https?://(?:www\.)?[^\s]+)~i', + '[$1]($1)', + $text + ); + } + private function plural(int $number, array $texts) { $cases = [2, 0, 1, 1, 1, 2]; diff --git a/templates/default/torrent/info.html.twig b/templates/default/torrent/info.html.twig index 3488f23..5aebc08 100644 --- a/templates/default/torrent/info.html.twig +++ b/templates/default/torrent/info.html.twig @@ -226,7 +226,7 @@ {{ 'Source' | trans }}