Browse Source

add markdown filter

main 1.12.1
ghost 10 months ago
parent
commit
20039728f0
  1. 27
      src/Twig/AppExtension.php

27
src/Twig/AppExtension.php

@ -326,6 +326,33 @@ class AppExtension extends AbstractExtension @@ -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
);

Loading…
Cancel
Save