python3 = True
+#
+# Helper functions
+#
+
+def _html_escape(string):
+ """HTML escape all of these " & < >"""
+
+ html_codes = {
+ '"': '"',
+ '<': '<',
+ '>': '>',
+ }
+
+ # & must be handled first
+ string = string.replace('&', '&')
+ for char in html_codes:
+ string = string.replace(char, html_codes[char])
+ return string
+
def render(template='', data={}, partials_path='.', partials_ext='mustache',
partials_dict={}, padding=0, def_ldel='{{', def_rdel='}}',
scopes=None):
A string containing the rendered template.
"""
- def html_escape(string):
- """HTML escape all of these " & < >"""
-
- html_codes = {
- '"': '"',
- '<': '<',
- '>': '>',
- }
-
- # & must be handled first
- string = string.replace('&', '&')
- for char in html_codes:
- string = string.replace(char, html_codes[char])
- return string
-
def get_key(key):
"""Get a key from the current scope"""
thing = get_key(key)
if type(thing) != unicode:
thing = unicode(str(thing), 'utf-8')
- output += html_escape(thing)
+ output += _html_escape(thing)
# If we're a no html escape tag
elif tag == 'no escape':