jazzband / tablib

Python Module for Tabular Datasets in XLS, CSV, JSON, YAML, &c.
https://tablib.readthedocs.io/
MIT License
4.58k stars 589 forks source link

Add <tbody> tags to html output #538

Closed krowbar closed 1 year ago

krowbar commented 1 year ago

A table exported to html with a header row no longer renders properly (on recent chrome, edge and firefox) if passed through a minifier that drops optional end tags. The table renders styled as all header rows.

Wrapping the rows with tbody.open/tbody.close fixes the rendering problem.

page.tbody.open()
for row in dataset:
    new_row = [item if item is not None else "" for item in row]
    html_row = markup.oneliner.td(new_row)
    page.tr(html_row)
page.tbody.close()

In the case I noticed, the table was 12K minified, but 19K minified if the end tags were included -- about a hundred rows and 9 columns.

claudep commented 1 year ago

Thanks for the report, could you please suggest a patch?

krowbar commented 1 year ago

tablib_html.patch

Let me know if you want something different.

claudep commented 1 year ago

Ideally if you could make it a pull request, would be nice! Tell us if you need any help.

krowbar commented 1 year ago

Pull request submitted.

krowbar commented 1 year ago

Updated the html test generation in my version.