Browse Source

implement clickable mentions

main
ghost 12 months ago
parent
commit
d64377f3e3
  1. 5
      composer.json
  2. 1
      config/bundles.php
  3. 40
      src/Twig/AppExtension.php
  4. 2
      templates/default/room/index.html.twig

5
composer.json

@ -9,6 +9,7 @@ @@ -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 @@ @@ -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": {

1
config/bundles.php

@ -3,4 +3,5 @@ @@ -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],
];

40
src/Twig/AppExtension.php

@ -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];

2
templates/default/room/index.html.twig

@ -35,7 +35,7 @@ @@ -35,7 +35,7 @@
</span>
{% endif %}
<p>
{{ post.message }}
{{ post.message | message_to_markdown | markdown_to_html }}
</p>
</li>
{% endfor %}

Loading…
Cancel
Save