diff --git a/CHANGELOG.md b/CHANGELOG.md index c13809729..fc648fcfc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -72,6 +72,7 @@ 1. [](#improved) * Use new `Utils::getSupportedPageTypes()` to enforce `html,htm` at the front of the list [#2531](https://github.com/getgrav/grav/issues/2531) * Updated vendor libraries + * Markdown filter is now page-aware so that it works with modular references [admin#1731](https://github.com/getgrav/grav-plugin-admin/issues/1731) 1. [](#bugfix) * Fixed some potential issues when `$grav['user']` is not set * Fixed error when calling `Media::add($name, null)` diff --git a/system/src/Grav/Common/Twig/TwigExtension.php b/system/src/Grav/Common/Twig/TwigExtension.php index aee1f080b..d53bcc963 100644 --- a/system/src/Grav/Common/Twig/TwigExtension.php +++ b/system/src/Grav/Common/Twig/TwigExtension.php @@ -91,7 +91,7 @@ class TwigExtension extends AbstractExtension implements GlobalsInterface new TwigFilter('fieldName', [$this, 'fieldNameFilter']), new TwigFilter('ksort', [$this, 'ksortFilter']), new TwigFilter('ltrim', [$this, 'ltrimFilter']), - new TwigFilter('markdown', [$this, 'markdownFunction'], ['is_safe' => ['html']]), + new TwigFilter('markdown', [$this, 'markdownFunction'], ['needs_context' => true, 'is_safe' => ['html']]), new TwigFilter('md5', [$this, 'md5Filter']), new TwigFilter('base32_encode', [$this, 'base32EncodeFilter']), new TwigFilter('base32_decode', [$this, 'base32DecodeFilter']), @@ -623,9 +623,10 @@ class TwigExtension extends AbstractExtension implements GlobalsInterface * @param bool $block Block or Line processing * @return mixed|string */ - public function markdownFunction($string, $block = true) + public function markdownFunction($context = false, $string, $block = true) { - return Utils::processMarkdown($string, $block); + $page = $context['page'] ?? null; + return Utils::processMarkdown($string, $block, $page); } /** diff --git a/system/src/Grav/Common/Utils.php b/system/src/Grav/Common/Utils.php index b085c28d1..6f5f302f1 100644 --- a/system/src/Grav/Common/Utils.php +++ b/system/src/Grav/Common/Utils.php @@ -1526,13 +1526,15 @@ abstract class Utils * * @param string $string * - * @param bool $block Block or Line processing + * @param bool $block Block or Line processing + * @param null $page * @return string + * @throws \Exception */ - public static function processMarkdown($string, $block = true) + public static function processMarkdown($string, $block = true, $page = null) { $grav = Grav::instance(); - $page = $grav['page'] ?? null; + $page = $page ?? $grav['page'] ?? null; $defaults = [ 'markdown' => $grav['config']->get('system.pages.markdown', []), 'images' => $grav['config']->get('system.images', [])