mirror of
https://github.com/kevachat/webapp.git
synced 2025-03-10 04:21:01 +00:00
implement clickable mentions
This commit is contained in:
parent
eecf2c6a67
commit
d64377f3e3
@ -9,6 +9,7 @@
|
||||
"ext-iconv": "*",
|
||||
"jdenticon/jdenticon": "^1.0",
|
||||
"kevachat/kevacoin": "^1.0",
|
||||
"league/commonmark": "^2.4",
|
||||
"symfony/console": "7.0.*",
|
||||
"symfony/dotenv": "7.0.*",
|
||||
"symfony/flex": "^2",
|
||||
@ -16,7 +17,9 @@
|
||||
"symfony/runtime": "7.0.*",
|
||||
"symfony/translation": "7.0.*",
|
||||
"symfony/twig-bundle": "7.0.*",
|
||||
"symfony/yaml": "7.0.*"
|
||||
"symfony/yaml": "7.0.*",
|
||||
"twig/extra-bundle": "^3.8",
|
||||
"twig/markdown-extra": "^3.8"
|
||||
},
|
||||
"config": {
|
||||
"allow-plugins": {
|
||||
|
@ -3,4 +3,5 @@
|
||||
return [
|
||||
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
|
||||
Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
|
||||
Twig\Extra\TwigExtraBundle\TwigExtraBundle::class => ['all' => true],
|
||||
];
|
||||
|
@ -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
|
||||
'urlToMarkdown'
|
||||
]
|
||||
),
|
||||
new TwigFilter(
|
||||
'mention_to_markdown',
|
||||
[
|
||||
$this,
|
||||
'mentionToMarkdown'
|
||||
]
|
||||
),
|
||||
new TwigFilter(
|
||||
'keva_namespace_value',
|
||||
[
|
||||
@ -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
|
||||
);
|
||||
}
|
||||
|
||||
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];
|
||||
|
@ -35,7 +35,7 @@
|
||||
</span>
|
||||
{% endif %}
|
||||
<p>
|
||||
{{ post.message }}
|
||||
{{ post.message | message_to_markdown | markdown_to_html }}
|
||||
</p>
|
||||
</li>
|
||||
{% endfor %}
|
||||
|
Loading…
x
Reference in New Issue
Block a user