json2html icon indicating copy to clipboard operation
json2html copied to clipboard

Possibly escape apostrophes differently

Open araichev opened this issue 7 years ago • 1 comments

Hi there,

I'm using your library to produce HTML tables to good effect in most cases. However, when the dictionary input involves apostrophes, the output fails to play nice with Folium popups. Using html.escape seems to fix that. For example, running

from json2html import json2html as jh
import html


d = {'stop_name': "Ponsonby Rd & K'Rd"}
dd = {}
for k, v in d.items():
    try:
        vv = html.escape(v)
    except AttributeError:
        vv = v
    dd[k] = vv

jh.convert(d), jh.convert(dd)

produces

'<table border="1"><tr><th>stop_name</th><td>Ponsonby Rd &amp; K\'Rd</td></tr></table>',
 '<table border="1"><tr><th>stop_name</th><td>Ponsonby Rd &amp;amp; K&amp;#x27;Rd</td></tr></table>'

The first output crashes Folium popups, but the second works with them. So would it be better for json2html to escape apostrophes in the same way that html.escape does?

araichev avatar May 23 '18 22:05 araichev