Skip to content

Commit cdcc393

Browse files
TomAugspurgerpmhatre1
authored andcommitted
Update Styler documentation for escaping HTML (pandas-dev#57365)
* Added note for Styler * Fixup
1 parent b6a9005 commit cdcc393

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

doc/source/user_guide/style.ipynb

+3-1
Original file line numberDiff line numberDiff line change
@@ -1621,7 +1621,9 @@
16211621
"source": [
16221622
"### HTML Escaping\n",
16231623
"\n",
1624-
"Suppose you have to display HTML within HTML, that can be a bit of pain when the renderer can't distinguish. You can use the `escape` formatting option to handle this, and even use it within a formatter that contains HTML itself."
1624+
"Suppose you have to display HTML within HTML, that can be a bit of pain when the renderer can't distinguish. You can use the `escape` formatting option to handle this, and even use it within a formatter that contains HTML itself.\n",
1625+
"\n",
1626+
"Note that if you're using `Styler` on untrusted, user-provided input to serve HTML then you should escape the input to prevent security vulnerabilities. See the Jinja2 documentation for more."
16251627
]
16261628
},
16271629
{

pandas/io/formats/style.py

+8
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ class Styler(StylerRenderer):
178178
escape : str, optional
179179
Use 'html' to replace the characters ``&``, ``<``, ``>``, ``'``, and ``"``
180180
in cell display string with HTML-safe sequences.
181+
181182
Use 'latex' to replace the characters ``&``, ``%``, ``$``, ``#``, ``_``,
182183
``{``, ``}``, ``~``, ``^``, and ``\`` in the cell display string with
183184
LaTeX-safe sequences. Use 'latex-math' to replace the characters
@@ -209,6 +210,13 @@ class Styler(StylerRenderer):
209210
210211
Notes
211212
-----
213+
.. warning::
214+
215+
``Styler`` is primarily intended for use on safe input that you control.
216+
When using ``Styler`` on untrusted, user-provided input to serve HTML,
217+
you should set ``escape="html"`` to prevent security vulnerabilities.
218+
See the Jinja2 documentation on escaping HTML for more.
219+
212220
Most styling will be done by passing style functions into
213221
``Styler.apply`` or ``Styler.map``. Style functions should
214222
return values with strings containing CSS ``'attr: value'`` that will

0 commit comments

Comments
 (0)