-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Add raw_html parameter to Styler.format, enabling richer output #40388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
does using jinja2 safe keyword help here? |
The jinja2 safe keyword would be necessary for this feature to work. But complementary functionally in pandas to distinguish between safe and unsafe formats would be necessary |
@jnothman, OK ignore my comment I misunderstood I think I now understand what you are trying to achieve, correct me if I am wrong, but of the following:
Will only render correctly in the final case. So basically it eliminates no-escaping (case 1), selective display value escaping (case 2) and post-formatting escaping (case 3). We need to escape the display value before the formatter acts on it. i.e. |
yes, it seems as though I was mistaken about the current behaviour. I had thought it would already escape the content for me. I had presumed so just because of the use of jinja templates. Now I need to go back and look at where in my code I'd thought I'd needed this! In the context of my confusion, your PR seems appropriate @attack68! |
Styler.format
could allow a parameterraw_html
(bool, False for current behaviour), enabling richer outputFor example,
df.style.format(lambda s: f"<a href='https://en.wikipedia.org/wiki/{html.escape(s)}'>{html.escape(s)}</a>", raw_html=True)
could be used to turn a column of values into a column of links to English Wikipedia articles, when exported withto_html
.To achieve this, we would need to always pass raw HTML to the jina templates, changing how formatting is currently done in
Styler.to_html
.Formats performed with
raw_html=True
would have no effect onStyler.to_excel
.The text was updated successfully, but these errors were encountered: