|
@@ -110,6 +110,18 @@ def markdown(env, value): |
|
|
|
|
|
|
|
|
return marked.convert(output) |
|
|
return marked.convert(output) |
|
|
|
|
|
|
|
|
|
|
|
@environmentfilter |
|
|
|
|
|
def restructuredtext(env, value): |
|
|
|
|
|
""" |
|
|
|
|
|
RestructuredText filter |
|
|
|
|
|
""" |
|
|
|
|
|
try: |
|
|
|
|
|
from docutils.core import publish_parts |
|
|
|
|
|
except ImportError: |
|
|
|
|
|
print u"Requires docutils library to use restructuredtext tag." |
|
|
|
|
|
raise |
|
|
|
|
|
parts = publish_parts(source=value, writer_name="html") |
|
|
|
|
|
return parts['html_body'] |
|
|
|
|
|
|
|
|
@environmentfilter |
|
|
@environmentfilter |
|
|
def syntax(env, value, lexer=None, filename=None): |
|
|
def syntax(env, value, lexer=None, filename=None): |
|
@@ -200,6 +212,31 @@ class Markdown(Extension): |
|
|
output = caller().strip() |
|
|
output = caller().strip() |
|
|
return markdown(self.environment, output) |
|
|
return markdown(self.environment, output) |
|
|
|
|
|
|
|
|
|
|
|
class restructuredText(Extension): |
|
|
|
|
|
""" |
|
|
|
|
|
A wrapper around the restructuredtext filter for syntactic sugar |
|
|
|
|
|
""" |
|
|
|
|
|
tags = set(['restructuredtext']) |
|
|
|
|
|
|
|
|
|
|
|
def parse(self, parser): |
|
|
|
|
|
""" |
|
|
|
|
|
Simply extract our content |
|
|
|
|
|
""" |
|
|
|
|
|
lineno = parser.stream.next().lineno |
|
|
|
|
|
body = parser.parse_statements(['name:endrestructuredtext'], drop_needle=True) |
|
|
|
|
|
|
|
|
|
|
|
return nodes.CallBlock(self.call_method('_render_rst'), [], [], body |
|
|
|
|
|
).set_lineno(lineno) |
|
|
|
|
|
|
|
|
|
|
|
def _render_rst(self, caller=None): |
|
|
|
|
|
""" |
|
|
|
|
|
call our restructuredtext filter |
|
|
|
|
|
""" |
|
|
|
|
|
if not caller: |
|
|
|
|
|
return '' |
|
|
|
|
|
output = caller().strip() |
|
|
|
|
|
return restructuredtext(self.environment, output) |
|
|
|
|
|
|
|
|
class YamlVar(Extension): |
|
|
class YamlVar(Extension): |
|
|
""" |
|
|
""" |
|
|
An extension that converts the content between the tags |
|
|
An extension that converts the content between the tags |
|
@@ -524,6 +561,7 @@ class Jinja2Template(Template): |
|
|
IncludeText, |
|
|
IncludeText, |
|
|
Spaceless, |
|
|
Spaceless, |
|
|
Markdown, |
|
|
Markdown, |
|
|
|
|
|
restructuredText, |
|
|
Syntax, |
|
|
Syntax, |
|
|
Reference, |
|
|
Reference, |
|
|
Refer, |
|
|
Refer, |
|
@@ -572,6 +610,7 @@ class Jinja2Template(Template): |
|
|
self.env.globals['engine'] = engine |
|
|
self.env.globals['engine'] = engine |
|
|
self.env.globals['deps'] = {} |
|
|
self.env.globals['deps'] = {} |
|
|
self.env.filters['markdown'] = markdown |
|
|
self.env.filters['markdown'] = markdown |
|
|
|
|
|
self.env.filters['restructuredtext'] = restructuredtext |
|
|
self.env.filters['syntax'] = syntax |
|
|
self.env.filters['syntax'] = syntax |
|
|
self.env.filters['date_format'] = date_format |
|
|
self.env.filters['date_format'] = date_format |
|
|
self.env.filters['xmldatetime'] = xmldatetime |
|
|
self.env.filters['xmldatetime'] = xmldatetime |
|
|