Commit 0d4c7f72 authored by Patrik Dufresne's avatar Patrik Dufresne

Merge branch 'develop/fix-link' into 'master'

Rebuild the html when context changes

See merge request !7
parents 4b26b3b0 0593bc1b
Pipeline #315 passed with stages
in 1 minute and 16 seconds
......@@ -117,6 +117,7 @@ class PythonMarkdown(object):
def __init__(self, source, record=None):
self.source = source
self.__record = weakref(record) if record is not None else lambda: None
self.__cached_for_ctx = None
self.__html = None
self.__meta = None
......@@ -126,9 +127,16 @@ class PythonMarkdown(object):
__nonzero__ = __bool__
def __render(self):
if self.__html is None:
self.__html = pythonmarkdown_to_html(self.source, self.__record())
self.__meta = None
# When the markdown instance is attached to a cached object we can
# end up in the situation where the context changed from the time
# we were put into the cache to the time where we got referenced
# by something elsewhere. In that case we need to re-process our
# markdown. For instance this affects relative links.
if self.__html is None or \
self.__cached_for_ctx != get_ctx():
self.__html = pythonmarkdown_to_html(
self.source, self.__record())
self.__cached_for_ctx = get_ctx()
def meta(self):
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment