Here are the examples of the python api django.template.Node taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
1 Examples
0
View Complete Implementation : notification_helpers.py
Copyright GNU General Public License v3.0
Author : GovReady
Copyright GNU General Public License v3.0
Author : GovReady
def render_markdown_instead_of_escaping(parser, token):
clast Node(template.Node):
def __init__(self, variable_name):
self.variable = template.Variable(variable_name)
def render(self, context):
md = self.variable.resolve(context)
if not context.autoescape:
# Auto-escaping is off, so we're in the text portion
# of a notification email. Return the raw markdown.
return md
else:
# Auto-escaping is on, so we're in the HTML portion
# of a notification email. Rather than returning the
# raw Markdown, which will look funny because e.g.
# line breaks will be ignored when it is placed within
# HTML, render the Markdown to HTML. Turn on safe mode
# since the content can't be trusted.
import commonmark
return commonmark.HtmlRenderer({ "safe": True })\
.render(commonmark.Parser().parse(md))
try:
tag_name, variable_name = token.split_contents()
except ValueError:
raise template.TemplateSyntaxError(
"%r tag requires a single argument naming a variable" % token.contents.split()[0]
)
return Node(variable_name)