From 20039728f0361ec3eb118924f26f34b921518939 Mon Sep 17 00:00:00 2001 From: ghost Date: Thu, 22 Feb 2024 09:03:02 +0200 Subject: [PATCH] add markdown filter --- src/Twig/AppExtension.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/Twig/AppExtension.php b/src/Twig/AppExtension.php index bba94f1..1ea376a 100644 --- a/src/Twig/AppExtension.php +++ b/src/Twig/AppExtension.php @@ -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 );