mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Ali Ijaz Sheikh
507c65d94a
|
9 years ago | |
---|---|---|
.. | ||
bench | 9 years ago | |
markupsafe | 9 years ago | |
.gitignore | 9 years ago | |
.travis.yml | 9 years ago | |
AUTHORS | 9 years ago | |
CHANGES | 9 years ago | |
LICENSE | 9 years ago | |
MANIFEST.in | 9 years ago | |
Makefile | 9 years ago | |
README.rst | 9 years ago | |
setup.py | 9 years ago | |
tox.ini | 9 years ago |
README.rst
MarkupSafe
==========
Implements a unicode subclass that supports HTML strings:
>>> from markupsafe import Markup, escape
>>> escape("<script>alert(document.cookie);</script>")
Markup(u'<script>alert(document.cookie);</script>')
>>> tmpl = Markup("<em>%s</em>")
>>> tmpl % "Peter > Lustig"
Markup(u'<em>Peter > Lustig</em>')
If you want to make an object unicode that is not yet unicode
but don't want to lose the taint information, you can use the
`soft_unicode` function. (On Python 3 you can also use `soft_str` which
is a different name for the same function).
>>> from markupsafe import soft_unicode
>>> soft_unicode(42)
u'42'
>>> soft_unicode(Markup('foo'))
Markup(u'foo')
HTML Representations
--------------------
Objects can customize their HTML markup equivalent by overriding
the `__html__` function:
>>> class Foo(object):
... def __html__(self):
... return '<strong>Nice</strong>'
...
>>> escape(Foo())
Markup(u'<strong>Nice</strong>')
>>> Markup(Foo())
Markup(u'<strong>Nice</strong>')