From 1ffd1cb6e7e908fda82092754aef171b7543178a Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 20 Apr 2015 21:40:06 -0600 Subject: [PATCH] Fixes for absolute images --- .../Common/Markdown/ParsedownGravTrait.php | 25 ++++++++++++------- .../Common/Page/Medium/ParsedownHtmlTrait.php | 2 +- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php index 927cf8a9d..2b17974df 100644 --- a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php +++ b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php @@ -239,20 +239,27 @@ trait ParsedownGravTrait $url_bits = parse_url($normalized_path); $full_path = $url_bits['path']; + // if this file exits, get the page and work with that if (file_exists($full_path)) { - $page_path = pathinfo($full_path, PATHINFO_DIRNAME); + $path_info = pathinfo($full_path); + $page_path = $path_info['dirname']; + $filename = ''; + + // save the filename if a file is part of the path + $filename_regex = "/([\w\d-_]+\.([a-zA-Z]{2,4}))$/"; + if (preg_match($filename_regex, $full_path, $matches)) { + if ($matches[2] != 'md') { + $filename = '/' . $matches[1]; + } + } else { + $page_path = $full_path; + } // get page instances and try to find one that fits $instances = $this->pages->instances(); - if (isset($instances[$full_path])) { - $target = $instances[$full_path]; - } elseif (isset($instances[$page_path])) { + if (isset($instances[$page_path])) { $target = $instances[$page_path]; - } - - // if a page target is found... - if ($target) { - $url_bits['path'] = $this->base_url . $target->route(); + $url_bits['path'] = $this->base_url . $target->route() . $filename; return Uri::buildUrl($url_bits); } } diff --git a/system/src/Grav/Common/Page/Medium/ParsedownHtmlTrait.php b/system/src/Grav/Common/Page/Medium/ParsedownHtmlTrait.php index 2567705d7..7052dea82 100644 --- a/system/src/Grav/Common/Page/Medium/ParsedownHtmlTrait.php +++ b/system/src/Grav/Common/Page/Medium/ParsedownHtmlTrait.php @@ -23,7 +23,7 @@ trait ParsedownHtmlTrait $element = $this->parsedownElement($title, $alt, $class, $reset); if (!$this->parsedown) { - $this->parsedown = new Parsedown(null); + $this->parsedown = new Parsedown(null, null); } return $this->parsedown->elementToHtml($element);