Debian Codegraph @

README.md

raw
1 <div align="center"><img src="https://raw.githubusercontent.com/pallets/markupsafe/refs/heads/stable/docs/_static/markupsafe-name.svg" alt="" height="150"></div>
2
3 # MarkupSafe
4
5 MarkupSafe implements a text object that escapes characters so it is
6 safe to use in HTML and XML. Characters that have special meanings are
7 replaced so that they display as the actual characters. This mitigates
8 injection attacks, meaning untrusted user input can safely be displayed
9 on a page.
10
11
12 ## Examples
13
14 ```pycon
15 >>> from markupsafe import Markup, escape
16
17 >>> # escape replaces special characters and wraps in Markup
18 >>> escape("<script>alert(document.cookie);</script>")
19 Markup('&lt;script&gt;alert(document.cookie);&lt;/script&gt;')
20
21 >>> # wrap in Markup to mark text "safe" and prevent escaping
22 >>> Markup("<strong>Hello</strong>")
23 Markup('<strong>hello</strong>')
24
25 >>> escape(Markup("<strong>Hello</strong>"))
26 Markup('<strong>hello</strong>')
27
28 >>> # Markup is a str subclass
29 >>> # methods and operators escape their arguments
30 >>> template = Markup("Hello <em>{name}</em>")
31 >>> template.format(name='"World"')
32 Markup('Hello <em>&#34;World&#34;</em>')
33 ```
34
35 ## Donate
36
37 The Pallets organization develops and supports MarkupSafe and other
38 popular packages. In order to grow the community of contributors and
39 users, and allow the maintainers to devote more time to the projects,
40 [please donate today][].
41
42 [please donate today]: https://palletsprojects.com/donate
43
44 ## Contributing
45
46 See our [detailed contributing documentation][contrib] for many ways to
47 contribute, including reporting issues, requesting features, asking or answering
48 questions, and making PRs.
49
50 [contrib]: https://palletsprojects.com/contributing/