Repository: jazzband/tablib
Pull request #539 (2023-02-16 15:41:35)

Add <tbody> tags to html output
Resolves jazzband/tablib#538

Wrap data rows in `<tbody>` tags to fix minifying (with a header row) when dropping optional end tags.
Otherwise the entire table renders with `<thead>` styling.

claudep: Looks like tests need to be adapted.
codecov[bot]: # [Codecov](https://codecov.io/gh/jazzband/tablib/pull/539?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=jazzband) Report
> Merging [#539](https://codecov.io/gh/jazzband/tablib/pull/539?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=jazzband) (8d5e28b) into [master](https://codecov.io/gh/jazzband/tablib/commit/8b9cf49fe835a0e03c45e729d3d0fc9a0bdaffd1?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=jazzband) (8b9cf49) will **increase** coverage by `0.01%`.
> The diff coverage is `100.00%`.

```diff
@@            Coverage Diff             @@
##           master     #539      +/-   ##
==========================================
+ Coverage   91.13%   91.15%   +0.01%     
==========================================
  Files          28       28              
  Lines        2674     2680       +6     
==========================================
+ Hits         2437     2443       +6     
  Misses        237      237              
```


| [Impacted Files](https://codecov.io/gh/jazzband/tablib/pull/539?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=jazzband) | Coverage Δ | |
|---|---|---|
| [src/tablib/formats/\_html.py](https://codecov.io/gh/jazzband/tablib/pull/539?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=jazzband#diff-c3JjL3RhYmxpYi9mb3JtYXRzL19odG1sLnB5) | `100.00% <100.00%> (ø)` | |
| [tests/test\_tablib.py](https://codecov.io/gh/jazzband/tablib/pull/539?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=jazzband#diff-dGVzdHMvdGVzdF90YWJsaWIucHk=) | `98.66% <100.00%> (+<0.01%)` | :arrow_up: |

:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=jazzband)


Patch:
diff --git a/src/tablib/formats/_html.py b/src/tablib/formats/_html.py
index 8aaf882..b362eae 100644
--- a/src/tablib/formats/_html.py
+++ b/src/tablib/formats/_html.py
@@ -30,11 +30,13 @@ class HTMLFormat:
             page.tr(headers)
             page.thead.close()
 
+        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()
 
         page.table.close()
 


Test patch:
diff --git a/tests/test_tablib.py b/tests/test_tablib.py
index 1d9fab4..29772f3 100755
--- a/tests/test_tablib.py
+++ b/tests/test_tablib.py
@@ -623,8 +623,10 @@ class HTMLTests(BaseTestCase):
         html.tr(markup.oneliner.th(self.founders.headers))
         html.thead.close()
 
+        html.tbody.open()
         for founder in self.founders:
             html.tr(markup.oneliner.td(founder))
+        html.tbody.close()
 
         html.table.close()
         html = str(html)
@@ -641,7 +643,9 @@ class HTMLTests(BaseTestCase):
         html.tr(markup.oneliner.th(['foo', '', 'bar']))
         html.thead.close()
 
+        html.tbody.open()
         html.tr(markup.oneliner.td(['foo', '', 'bar']))
+        html.tbody.close()
 
         html.table.close()
         html = str(html)