Browse Source

make description links clickable #30

main
ghost 1 year ago
parent
commit
6dcbd6de40
  1. 4
      composer.json
  2. 18
      src/Twig/AppExtension.php
  3. 4
      templates/default/torrent/info.html.twig

4
composer.json

@ -15,6 +15,7 @@ @@ -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 @@ @@ -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"

18
src/Twig/AppExtension.php

@ -39,6 +39,13 @@ class AppExtension extends AbstractExtension @@ -39,6 +39,13 @@ class AppExtension extends AbstractExtension
'formatAgo'
]
),
new TwigFilter(
'url_to_markdown',
[
$this,
'urlToMarkdown'
]
),
];
}
@ -135,6 +142,17 @@ class AppExtension extends AbstractExtension @@ -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];

4
templates/default/torrent/info.html.twig

@ -226,7 +226,7 @@ @@ -226,7 +226,7 @@
{{ 'Source' | trans }}
</td>
<td>
{{ file.source }}
{{ file.source | url_to_markdown | markdown_to_html }}
</td>
</tr>
{% endif %}
@ -246,7 +246,7 @@ @@ -246,7 +246,7 @@
{{ 'Comment' | trans }}
</td>
<td>
{{ file.comment | nl2br }}
{{ file.comment | url_to_markdown | markdown_to_html }}
</td>
</tr>
{% endif %}

Loading…
Cancel
Save