add markdown filter

This commit is contained in:
ghost 2024-02-22 09:03:02 +02:00
parent efbef3a41c
commit 20039728f0

View File

@ -326,6 +326,33 @@ class AppExtension extends AbstractExtension
string $text
): string
{
$lines = [];
foreach (explode(PHP_EOL, $text) as $line)
{
$lines[] = preg_replace(
[
'/^(\s?)([#]{1,6})(.*)/',
'/^(\s?)([*]+)(.*)/',
'/^(\s?)([`]+)(.*)/',
'/^(\s?)([\d]+\.)(.*)/',
'/^(\s?)(>)(.*)/',
'/(\s?)(!)(.*)/',
'/(\s?)(\[)(.*)/',
'/(\s?)(\])(.*)/',
'/(\s?)(\()(.*)/',
'/(\s?)(\))(.*)/',
],
'$1\\\$2$3',
$line
);
}
$text = implode(
PHP_EOL,
$lines
);
$text = $this->urlToMarkdown(
$text
);