Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions BER/mitte.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
1 change: 1 addition & 0 deletions tests/site/data/test_markdown_tpl.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
text: "# Markdown {{ test_variable }}"
7 changes: 7 additions & 0 deletions tests/site/site.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
1 change: 1 addition & 0 deletions tests/site/templates/test-markdown-ctx.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ entry.text | markdown(ctx=page) }}
6 changes: 6 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ def test_markdown_filter(self):
self.assertEqual(200, response.code)
self.assertEqual(b'<h1>Markdown Test</h1>\n', response.body)

def test_markdown_filter_with_context(self):
response = self.fetch('/markdown-with-ctx', method='GET')

self.assertEqual(200, response.code)
self.assertEqual(b'<h1>Markdown TEST-CTX</h1>\n', response.body)

def test_unpublished_page(self):
""" test that pages marked as unpublished return 404 """

Expand Down