From b9458b91ba63efa5723c0d47328ff48ab8df4787 Mon Sep 17 00:00:00 2001 From: ghost Date: Sat, 9 Dec 2023 21:46:44 +0200 Subject: [PATCH] add namespaceToMarkdown filter --- src/Twig/AppExtension.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/Twig/AppExtension.php b/src/Twig/AppExtension.php index 642a841..5ba5c1f 100644 --- a/src/Twig/AppExtension.php +++ b/src/Twig/AppExtension.php @@ -52,6 +52,13 @@ class AppExtension extends AbstractExtension 'mentionToMarkdown' ] ), + new TwigFilter( + 'namespace_to_markdown', + [ + $this, + 'namespaceToMarkdown' + ] + ), new TwigFilter( 'keva_namespace_value', [ @@ -145,6 +152,10 @@ class AppExtension extends AbstractExtension $text ); + $text = $this->namespaceToMarkdown( + $text + ); + return $text; } @@ -170,6 +181,17 @@ class AppExtension extends AbstractExtension ); } + public function namespaceToMarkdown( + string $text + ): string + { + return preg_replace( + '~(N[A-z0-9]{33})~i', + '[$1]($1)', + $text + ); + } + private function plural(int $number, array $texts) { $cases = [2, 0, 1, 1, 1, 2];