diff --git a/lektor_pythonmarkdown.py b/lektor_pythonmarkdown.py index ddec0b21509f2578a7e1693476c0feccd1ea8213..9028d5b320b11617e7ba4eaaa484b8e639690d01 100644 --- a/lektor_pythonmarkdown.py +++ b/lektor_pythonmarkdown.py @@ -10,7 +10,7 @@ from markdown.inlinepatterns import LinkPattern import types from weakref import ref as weakref -from lektor.context import get_ctx, url_to +from lektor.context import get_ctx from lektor.pluginsystem import Plugin from lektor.types import Type from lektor.utils import bool_from_string @@ -18,6 +18,7 @@ from markupsafe import Markup from werkzeug.urls import url_parse + SECTION_EXTENSIONS = "extensions" SECTION_MARKDOWN = "markdown" DEFAULT_EXTENTIONS = { @@ -29,13 +30,11 @@ def sanitize_url(self, link): """ Patched function to resolve the url using Lektor. """ - try: + if get_ctx() and get_ctx().record is not None: url = url_parse(link) if not url.scheme: - link = url_to(link) - except: - # Do not fail if something went wrong during the url parsing. - pass + link = get_ctx().record.url_to(link, + base_url=get_ctx().base_url) return LinkPattern.sanitize_url(self, link)