diff --git a/BER/mitte.py b/BER/mitte.py index a93c7ea..63af78f 100644 --- a/BER/mitte.py +++ b/BER/mitte.py @@ -79,11 +79,13 @@ def theme_image_url(self, name): def strftime(self, time_struct, format): return strftime(format, time_struct) - def markdown(self, text): + def markdown(self, text, ctx=dict()): md = misaka.Markdown( misaka.HtmlRenderer(), extensions=('fenced-code',)) - return Markup(md(text)) + tpl = JinjaEnvironment().from_string(text) + print(ctx) + return Markup(md(tpl.render(**ctx))) def get_globals(self): globals = { diff --git a/tests/site/data/test_markdown_tpl.yaml b/tests/site/data/test_markdown_tpl.yaml new file mode 100644 index 0000000..d314178 --- /dev/null +++ b/tests/site/data/test_markdown_tpl.yaml @@ -0,0 +1 @@ +text: "# Markdown {{ test_variable }}" diff --git a/tests/site/site.yaml b/tests/site/site.yaml index 5029dcc..3151ce1 100644 --- a/tests/site/site.yaml +++ b/tests/site/site.yaml @@ -130,3 +130,10 @@ pages: format: "yaml" src: "test_markdown.yaml" tpl_name: "/test-markdown.html" + /markdown-with-ctx: + test_variable: TEST-CTX + data_sources: + entry: + format: "yaml" + src: "test_markdown_tpl.yaml" + tpl_name: "/test-markdown-ctx.html" diff --git a/tests/site/templates/test-markdown-ctx.html b/tests/site/templates/test-markdown-ctx.html new file mode 100644 index 0000000..9bc2b20 --- /dev/null +++ b/tests/site/templates/test-markdown-ctx.html @@ -0,0 +1 @@ +{{ entry.text | markdown(ctx=page) }} diff --git a/tests/test.py b/tests/test.py index 885bab7..2f80150 100644 --- a/tests/test.py +++ b/tests/test.py @@ -118,6 +118,12 @@ def test_markdown_filter(self): self.assertEqual(200, response.code) self.assertEqual(b'