I have a Python script that constructs a pandas DataFrame from API data, which I then convert to a pretty_html_table that will be the body of an email. In one of the rows, I have data containing an address. It is formatted as follows
Street Address: 123 Street Ave<br>City: City<br>State: ST<br>Postal: 12345<br>
The HTML line breaks are a part of the string and thus aren't encoded, so in the email, it is all in that one line as shown above. I would like to have each element be on its own line within the same row (essentially have those tags actually do what they're supposed to do)
from pretty_html_table import build_table
import pandas
table = pandas.DataFrame({
'Label': ["Name", "Address", "Item", "Contact Email", "Date"],
'Info': ["", "", "", "", ""]
})
table.loc[0, 'Info'] = foo
table.loc[1, 'Info'] = foo
table.loc[2, 'Info'] = foo
table.loc[3, 'Info'] = foo
table.loc[4, 'Info'] = foo
pretty_table = build_table(table, "green_dark")
I can just replace the tags with whitespaces and make the string a little neater, but I would prefer for it to be on separate lines without making 4 separate rows.
<br>becausepandas(usingdf.to_html()in this place in source code) converts to<br>and browser/email displays it as string<br>, and it doesn't treat it as HTML tag. You may test print( table.to_html() ) and you should see <br> instead of <br> in HTMLbuild_table(..., escape=False)and it will not convert<br>to<br>