| 1 |
.. currentmodule:: markupsafe |
| 2 |
.. rst-class:: hide-header |
| 3 |
|
| 4 |
MarkupSafe |
| 5 |
========== |
| 6 |
|
| 7 |
.. image:: _static/markupsafe-name.svg |
| 8 |
:align: center |
| 9 |
:height: 200px |
| 10 |
|
| 11 |
MarkupSafe escapes characters so text is safe to use in HTML and XML. |
| 12 |
Characters that have special meanings are replaced so that they display |
| 13 |
as the actual characters. This mitigates injection attacks, meaning |
| 14 |
untrusted user input can safely be displayed on a page. |
| 15 |
|
| 16 |
The :func:`escape` function escapes text and returns a :class:`Markup` |
| 17 |
object. The object won't be escaped anymore, but any text that is used |
| 18 |
with it will be, ensuring that the result remains safe to use in HTML. |
| 19 |
|
| 20 |
>>> from markupsafe import escape |
| 21 |
>>> hello = escape("<em>Hello</em>") |
| 22 |
>>> hello |
| 23 |
Markup('<em>Hello</em>') |
| 24 |
>>> escape(hello) |
| 25 |
Markup('<em>Hello</em>') |
| 26 |
>>> hello + " <strong>World</strong>" |
| 27 |
Markup('<em>Hello</em> <strong>World</strong>') |
| 28 |
|
| 29 |
|
| 30 |
Installing |
| 31 |
---------- |
| 32 |
|
| 33 |
Install and update using `pip`_: |
| 34 |
|
| 35 |
.. code-block:: text |
| 36 |
|
| 37 |
pip install -U MarkupSafe |
| 38 |
|
| 39 |
.. _pip: https://pip.pypa.io/en/stable/quickstart/ |
| 40 |
|
| 41 |
|
| 42 |
Table of Contents |
| 43 |
----------------- |
| 44 |
|
| 45 |
.. toctree:: |
| 46 |
:maxdepth: 2 |
| 47 |
|
| 48 |
escaping |
| 49 |
html |
| 50 |
formatting |
| 51 |
license |
| 52 |
changes |