You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Styler.format could allow a parameter raw_html (bool, False for current behaviour), enabling richer output
For 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 with to_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 on Styler.to_excel.
The text was updated successfully, but these errors were encountered:
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. format(lambda v: f'<a href="https://www.abc.com/{v}">{v}</a>', escape=True) should act as case 4.
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: