Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pallets/markupsafe
Safely add untrusted strings to HTML/XML markup.
https://github.com/pallets/markupsafe
html html-escape jinja markupsafe pallets python template-engine
Last synced: about 1 month ago
JSON representation
Safely add untrusted strings to HTML/XML markup.
- Host: GitHub
- URL: https://github.com/pallets/markupsafe
- Owner: pallets
- License: bsd-3-clause
- Created: 2010-06-22T17:22:58.000Z (over 14 years ago)
- Default Branch: main
- Last Pushed: 2024-04-24T00:39:34.000Z (7 months ago)
- Last Synced: 2024-05-01T11:39:57.485Z (6 months ago)
- Topics: html, html-escape, jinja, markupsafe, pallets, python, template-engine
- Language: Python
- Homepage: https://markupsafe.palletsprojects.com
- Size: 700 KB
- Stars: 598
- Watchers: 26
- Forks: 150
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.rst
- Contributing: CONTRIBUTING.rst
- License: LICENSE.txt
Awesome Lists containing this project
- awesome-python-resources - GitHub
- best-of-web-python - GitHub - 0% open · ⏱️ 03.06.2024): (HTML Processing)
README
# MarkupSafe
MarkupSafe implements a text object that escapes characters so it is
safe to use in HTML and XML. Characters that have special meanings are
replaced so that they display as the actual characters. This mitigates
injection attacks, meaning untrusted user input can safely be displayed
on a page.## Examples
```pycon
>>> from markupsafe import Markup, escape>>> # escape replaces special characters and wraps in Markup
>>> escape("alert(document.cookie);")
Markup('<script>alert(document.cookie);</script>')>>> # wrap in Markup to mark text "safe" and prevent escaping
>>> Markup("Hello")
Markup('hello')>>> escape(Markup("Hello"))
Markup('hello')>>> # Markup is a str subclass
>>> # methods and operators escape their arguments
>>> template = Markup("Hello {name}")
>>> template.format(name='"World"')
Markup('Hello "World"')
```## Donate
The Pallets organization develops and supports MarkupSafe and other
popular packages. In order to grow the community of contributors and
users, and allow the maintainers to devote more time to the projects,
[please donate today][].[please donate today]: https://palletsprojects.com/donate