mirror of
https://github.com/kevachat/webapp.git
synced 2025-03-11 04:51:04 +00:00
implement clickable mentions
This commit is contained in:
parent
eecf2c6a67
commit
d64377f3e3
@ -9,6 +9,7 @@
|
|||||||
"ext-iconv": "*",
|
"ext-iconv": "*",
|
||||||
"jdenticon/jdenticon": "^1.0",
|
"jdenticon/jdenticon": "^1.0",
|
||||||
"kevachat/kevacoin": "^1.0",
|
"kevachat/kevacoin": "^1.0",
|
||||||
|
"league/commonmark": "^2.4",
|
||||||
"symfony/console": "7.0.*",
|
"symfony/console": "7.0.*",
|
||||||
"symfony/dotenv": "7.0.*",
|
"symfony/dotenv": "7.0.*",
|
||||||
"symfony/flex": "^2",
|
"symfony/flex": "^2",
|
||||||
@ -16,7 +17,9 @@
|
|||||||
"symfony/runtime": "7.0.*",
|
"symfony/runtime": "7.0.*",
|
||||||
"symfony/translation": "7.0.*",
|
"symfony/translation": "7.0.*",
|
||||||
"symfony/twig-bundle": "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": {
|
"config": {
|
||||||
"allow-plugins": {
|
"allow-plugins": {
|
||||||
|
@ -3,4 +3,5 @@
|
|||||||
return [
|
return [
|
||||||
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
|
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
|
||||||
Symfony\Bundle\TwigBundle\TwigBundle::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'
|
'formatAgo'
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
|
new TwigFilter(
|
||||||
|
'message_to_markdown',
|
||||||
|
[
|
||||||
|
$this,
|
||||||
|
'messageToMarkdown'
|
||||||
|
]
|
||||||
|
),
|
||||||
new TwigFilter(
|
new TwigFilter(
|
||||||
'url_to_markdown',
|
'url_to_markdown',
|
||||||
[
|
[
|
||||||
@ -38,6 +45,13 @@ class AppExtension extends AbstractExtension
|
|||||||
'urlToMarkdown'
|
'urlToMarkdown'
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
|
new TwigFilter(
|
||||||
|
'mention_to_markdown',
|
||||||
|
[
|
||||||
|
$this,
|
||||||
|
'mentionToMarkdown'
|
||||||
|
]
|
||||||
|
),
|
||||||
new TwigFilter(
|
new TwigFilter(
|
||||||
'keva_namespace_value',
|
'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(
|
public function urlToMarkdown(
|
||||||
string $text
|
string $text
|
||||||
): string
|
): 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)
|
private function plural(int $number, array $texts)
|
||||||
{
|
{
|
||||||
$cases = [2, 0, 1, 1, 1, 2];
|
$cases = [2, 0, 1, 1, 1, 2];
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
</span>
|
</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<p>
|
<p>
|
||||||
{{ post.message }}
|
{{ post.message | message_to_markdown | markdown_to_html }}
|
||||||
</p>
|
</p>
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user