Skip to content
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

Make escaping data in an HTML table optional #40

Closed
CameronLonsdale opened this issue Mar 28, 2020 · 9 comments · Fixed by #305
Closed

Make escaping data in an HTML table optional #40

CameronLonsdale opened this issue Mar 28, 2020 · 9 comments · Fixed by #305
Labels
enhancement New feature or request

Comments

@CameronLonsdale
Copy link

CameronLonsdale commented Mar 28, 2020

For certain rows, I require the data to be augmented with HTML, and that unfortunately gets escaped here: https://github.com/jazzband/prettytable/blob/master/prettytable.py#L1622

Would you consider adding an option to get_html_string to disable data escaping?

Happy to contribute a PR

@hugovk
Copy link
Collaborator

hugovk commented Nov 1, 2020

Hi, sounds like a good idea, would also solve things like kxxoling/PTable#15 in the fork.

PR welcome!

@hugovk hugovk added the enhancement New feature or request label Nov 14, 2020
@hugovk hugovk changed the title Make escaping data in an HTML table optional. Make escaping data in an HTML table optional Nov 14, 2020
@CameronLonsdale
Copy link
Author

Yeah I believe it would. Really, it would be nice to be able to specify a transformation function for the data, with the default being your escape function. I've sub classed and written my own _get_simple_html_string so that I can render every row as markdown, rather than it doing the default "escape" behaviour. So being able to specify that transformation function would be epic.

@loganmarchione
Copy link

+1 for this, would like to be able to use HTML inside a cell (example below)
<progress class="progress" value="15" max="100">15%</progress>

@klauer
Copy link

klauer commented Apr 13, 2021

👍 for this as well. My use case is nested html-rendered prettytables.

If no one else is looking to jump on this, I might find some time in the nearish future.

@gilbh
Copy link

gilbh commented May 17, 2021

Asking if this feature is available already? I am trying to wrap values in one column with <a href> tags, but am getting this with get_html_string() this:

&lt;a href=&#x27;google.com&#x27; ...

Perhaps a switch or parameter to get_html_string() to disable escaping?

I tried _get_simple_html_string but it requires many options (and throws KeyError exceptions, e.g. line 1643).

Thanks
Gil

@hugovk
Copy link
Collaborator

hugovk commented May 18, 2021

Asking if this feature is available already?

Not yet, PRs welcome!

Perhaps a switch or parameter to get_html_string() to disable escaping?

Yes, this is the original suggestion.

I tried _get_simple_html_string but it requires many options (and throws KeyError exceptions, e.g. line 1643).

Yep, in general not a good idea to use functions beginning with an underscore, they're private/internal and liable to change or removal with no warning.

@gilbh
Copy link

gilbh commented May 18, 2021

Yup! Thanks!

@JackSlateur
Copy link

JackSlateur commented May 22, 2021

You can always apply a workaround, and monkeypatch the html module:

import html
html.escape = lambda *args, **kwargs: args[0]
from prettytable import PrettyTable

@gilbh
Copy link

gilbh commented May 22, 2021

Amazing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
6 participants