Fix for extended image url handling in markdown

This commit is contained in:
Andy Miller
2014-10-10 15:57:29 -06:00
parent 9310c3f12f
commit cc68065f94
2 changed files with 21 additions and 1 deletions

View File

@@ -5,6 +5,7 @@ use Grav\Common\Config\Config;
use Grav\Common\Debugger;
use Grav\Common\GravTrait;
use Grav\Common\Page\Medium;
use Grav\Common\Uri;
/**
* A trait to add some custom processing to the identifyLink() method in Parsedown and ParsedownExtra
@@ -97,7 +98,7 @@ trait MarkdownGravLinkTrait
}
} else {
// not a current page media file, see if it needs converting to relative
$Excerpt['element']['attributes']['src'] = $this->convertUrl($url['path']);
$Excerpt['element']['attributes']['src'] = $this->convertUrl(Uri::build_url($url));
}
}
}

View File

@@ -333,4 +333,23 @@ class Uri
return $ipaddress;
}
/**
* The opposite of built-in PHP method parse_url()
*
* @param $parsed_url
* @return string
*/
public static function build_url($parsed_url) {
$scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : '';
$host = isset($parsed_url['host']) ? $parsed_url['host'] : '';
$port = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '';
$user = isset($parsed_url['user']) ? $parsed_url['user'] : '';
$pass = isset($parsed_url['pass']) ? ':' . $parsed_url['pass'] : '';
$pass = ($user || $pass) ? "$pass@" : '';
$path = isset($parsed_url['path']) ? $parsed_url['path'] : '';
$query = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : '';
$fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : '';
return "$scheme$user$pass$host$port$path$query$fragment";
}
}