|
|
|
@ -31,6 +31,13 @@ class AppExtension extends AbstractExtension
@@ -31,6 +31,13 @@ class AppExtension extends AbstractExtension
|
|
|
|
|
'formatAgo' |
|
|
|
|
] |
|
|
|
|
), |
|
|
|
|
new TwigFilter( |
|
|
|
|
'message_to_markdown', |
|
|
|
|
[ |
|
|
|
|
$this, |
|
|
|
|
'messageToMarkdown' |
|
|
|
|
] |
|
|
|
|
), |
|
|
|
|
new TwigFilter( |
|
|
|
|
'url_to_markdown', |
|
|
|
|
[ |
|
|
|
@ -38,6 +45,13 @@ class AppExtension extends AbstractExtension
@@ -38,6 +45,13 @@ class AppExtension extends AbstractExtension
|
|
|
|
|
'urlToMarkdown' |
|
|
|
|
] |
|
|
|
|
), |
|
|
|
|
new TwigFilter( |
|
|
|
|
'mention_to_markdown', |
|
|
|
|
[ |
|
|
|
|
$this, |
|
|
|
|
'mentionToMarkdown' |
|
|
|
|
] |
|
|
|
|
), |
|
|
|
|
new TwigFilter( |
|
|
|
|
'keva_namespace_value', |
|
|
|
|
[ |
|
|
|
@ -119,6 +133,21 @@ class AppExtension extends AbstractExtension
@@ -119,6 +133,21 @@ class AppExtension extends AbstractExtension
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function messageToMarkdown( |
|
|
|
|
string $text |
|
|
|
|
): string |
|
|
|
|
{ |
|
|
|
|
$text = $this->urlToMarkdown( |
|
|
|
|
$text |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
$text = $this->mentionToMarkdown( |
|
|
|
|
$text |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
return $text; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function urlToMarkdown( |
|
|
|
|
string $text |
|
|
|
|
): string |
|
|
|
@ -130,6 +159,17 @@ class AppExtension extends AbstractExtension
@@ -130,6 +159,17 @@ class AppExtension extends AbstractExtension
|
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function mentionToMarkdown( |
|
|
|
|
string $text |
|
|
|
|
): string |
|
|
|
|
{ |
|
|
|
|
return preg_replace( |
|
|
|
|
'~(@[A-z0-9]{64})~i', |
|
|
|
|
'[$1](#$1)', |
|
|
|
|
$text |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private function plural(int $number, array $texts) |
|
|
|
|
{ |
|
|
|
|
$cases = [2, 0, 1, 1, 1, 2]; |
|
|
|
|