diff --git a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php index 8b0c4d144..539f9336d 100644 --- a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php +++ b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php @@ -111,6 +111,7 @@ trait ParsedownGravTrait $excerpt['extent'] = $excerpt['extent'] + strlen($matches[1]) - 1; return $excerpt; } else { + $excerpt['type'] = 'image'; $excerpt = parent::inlineImage($excerpt); } @@ -186,6 +187,12 @@ trait ParsedownGravTrait protected function inlineLink($excerpt) { + if (isset($excerpt['type'])) { + $type = $excerpt['type']; + } else { + $type = 'link'; + } + // do some trickery to get around Parsedown requirement for valid URL if its Twig in there if (preg_match($this->twig_link_regex, $excerpt['text'], $matches)) { $excerpt['text'] = str_replace($matches[1], '/', $excerpt['text']); @@ -204,7 +211,7 @@ trait ParsedownGravTrait // if there is no scheme, the file is local if (!isset($url['scheme']) && (count($url) > 0)) { // convert the URl is required - $excerpt['element']['attributes']['href'] = Uri::convertUrl($this->page, Uri::buildUrl($url)); + $excerpt['element']['attributes']['href'] = Uri::convertUrl($this->page, Uri::buildUrl($url), $type); } } diff --git a/system/src/Grav/Common/Uri.php b/system/src/Grav/Common/Uri.php index 563f4232b..f479f297b 100644 --- a/system/src/Grav/Common/Uri.php +++ b/system/src/Grav/Common/Uri.php @@ -482,12 +482,20 @@ class Uri * * @return string the more friendly formatted url */ - public static function convertUrl(Page $page, $markdown_url) + public static function convertUrl(Page $page, $markdown_url, $type = 'link') { $grav = Grav::instance(); + // Link processing should prepend language + $language_append = ''; + if ($type == 'link') { + $active_language = $grav['language']->getActive(); + $language_append = $active_language ? '/'.$active_language : ''; + } + + $pages_dir = $grav['locator']->findResource('page://'); - $base_url = rtrim($grav['base_url'] . $grav['pages']->base(), '/'); + $base_url = rtrim($grav['base_url'] . $grav['pages']->base(), '/') . $language_append; // if absolute and starts with a base_url move on if (pathinfo($markdown_url, PATHINFO_DIRNAME) == '.' && $page->url() == '/') {