README.rst 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. MarkupSafe
  2. ==========
  3. MarkupSafe implements a text object that escapes characters so it is
  4. safe to use in HTML and XML. Characters that have special meanings are
  5. replaced so that they display as the actual characters. This mitigates
  6. injection attacks, meaning untrusted user input can safely be displayed
  7. on a page.
  8. Installing
  9. ----------
  10. Install and update using `pip`_:
  11. .. code-block:: text
  12. pip install -U MarkupSafe
  13. .. _pip: https://pip.pypa.io/en/stable/quickstart/
  14. Examples
  15. --------
  16. .. code-block:: pycon
  17. >>> from markupsafe import Markup, escape
  18. >>> # escape replaces special characters and wraps in Markup
  19. >>> escape('<script>alert(document.cookie);</script>')
  20. Markup(u'&lt;script&gt;alert(document.cookie);&lt;/script&gt;')
  21. >>> # wrap in Markup to mark text "safe" and prevent escaping
  22. >>> Markup('<strong>Hello</strong>')
  23. Markup('<strong>hello</strong>')
  24. >>> escape(Markup('<strong>Hello</strong>'))
  25. Markup('<strong>hello</strong>')
  26. >>> # Markup is a text subclass (str on Python 3, unicode on Python 2)
  27. >>> # methods and operators escape their arguments
  28. >>> template = Markup("Hello <em>%s</em>")
  29. >>> template % '"World"'
  30. Markup('Hello <em>&#34;World&#34;</em>')
  31. Donate
  32. ------
  33. The Pallets organization develops and supports MarkupSafe and other
  34. libraries that use it. In order to grow the community of contributors
  35. and users, and allow the maintainers to devote more time to the
  36. projects, `please donate today`_.
  37. .. _please donate today: https://palletsprojects.com/donate
  38. Links
  39. -----
  40. * Website: https://palletsprojects.com/p/markupsafe/
  41. * Documentation: https://markupsafe.palletsprojects.com/
  42. * License: `BSD-3-Clause <https://github.com/pallets/markupsafe/blob/master/LICENSE.rst>`_
  43. * Releases: https://pypi.org/project/MarkupSafe/
  44. * Code: https://github.com/pallets/markupsafe
  45. * Issue tracker: https://github.com/pallets/markupsafe/issues
  46. * Test status:
  47. * Linux, Mac: https://travis-ci.org/pallets/markupsafe
  48. * Windows: https://ci.appveyor.com/project/pallets/markupsafe
  49. * Test coverage: https://codecov.io/gh/pallets/markupsafe