README.rst 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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/getting-started/
  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('&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 str subclass
  27. >>> # methods and operators escape their arguments
  28. >>> template = Markup("Hello <em>{name}</em>")
  29. >>> template.format(name='"World"')
  30. Markup('Hello <em>&#34;World&#34;</em>')
  31. Donate
  32. ------
  33. The Pallets organization develops and supports MarkupSafe and other
  34. popular packages. In order to grow the community of contributors and
  35. users, and allow the maintainers to devote more time to the projects,
  36. `please donate today`_.
  37. .. _please donate today: https://palletsprojects.com/donate
  38. Links
  39. -----
  40. - Documentation: https://markupsafe.palletsprojects.com/
  41. - Changes: https://markupsafe.palletsprojects.com/changes/
  42. - PyPI Releases: https://pypi.org/project/MarkupSafe/
  43. - Source Code: https://github.com/pallets/markupsafe/
  44. - Issue Tracker: https://github.com/pallets/markupsafe/issues/
  45. - Chat: https://discord.gg/pallets