Created
September 17, 2014 22:38
-
-
Save DonnchaC/2bbf56521c35eef1523f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from jinja2 import Markup, escape | |
print 'Filter Test.\n---' | |
value = """ | |
a test <strong>string</strong> | |
new line test. | |
""" | |
print 'Escape() give Markup Object:' | |
print type(escape(value)) | |
print '\nMarkup object cast to unicode string in .join():' | |
formatted = u'<br>\n'.join(escape(value).split('\n')) | |
print type(formatted) | |
# In evalcontextfilter block | |
print '\nRecreating Markup object:' | |
formatted = Markup(formatted) | |
print type(formatted) | |
# Output | |
# Filter Test. | |
# --- | |
# Escape() give Markup Object: | |
# <class 'markupsafe.Markup'> | |
# | |
# Markup object cast to unicode string in .join(): | |
# <type 'unicode'> | |
# | |
# Recreating Markup object: | |
# <class 'markupsafe.Markup'> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment