Commits

Andrey Vlasovskikh committed f408b2d

Plugins can set their own Jinja2 template filters

  • Participants
  • Parent commits e02f669

Comments (0)

Files changed (4)

 
 loaders = []
 processors = []
-filters = {
+file_filters = {
     '.md':          markdown,
     '.markdown':    markdown,
 }
+template_filters = {
+    'markdownify':  markdown,
+}
 retcode = 0
 
 
 def render_string(basedir, s, context, filename, offset=0):
     includes = os.path.join(basedir, '_includes')
     env = Environment(loader=FileSystemLoader(includes))
+    env.filters.update(template_filters)
     try:
         t = env.from_string(s)
         return t.render(**context)
     if not page:
         return None
     page['url'] = url
-    filter = filters.get(file_suffix(filename))
+    filter = file_filters.get(file_suffix(filename))
     if filter:
         page['content'] = filter(page['content'])
     return page
     if not is_file_visible(filename, exclude):
         return None
     name, suffix = os.path.splitext(filename)
-    if suffix in filters:
+    if suffix in file_filters:
         dst = '{0}.html'.format(name)
     else:
         dst = filename

File test/data/markdown_pages/after/_site/index.html

 <h1>Hello</h1>
-<p>Hello, <em>World</em>!</p>
+<p>Hello, <em>World</em>!</p>
+<div>
+  <p>This <strong>is</strong> Markdown.</p>
+</div>

File test/data/markdown_pages/after/index.md

 ---
+markdown_data: |
+  This **is** Markdown.
 ---
 
 Hello
 =====
 
 Hello, *World*!
+
+<div>
+  {{ page.markdown_data | markdownify }}
+</div>

File test/data/markdown_pages/before/index.md

 ---
+markdown_data: |
+  This **is** Markdown.
 ---
 
 Hello
 =====
 
 Hello, *World*!
+
+<div>
+  {{ page.markdown_data | markdownify }}
+</div>