posit-dev / great-tables

Make awesome display tables using Python.
https://posit-dev.github.io/great-tables/
MIT License
1.43k stars 48 forks source link

Ensure that group label rows have valid HTML #308

Closed rich-iannone closed 2 months ago

rich-iannone commented 2 months ago

From a simple rendering of:

from great_tables import GT, exibble

GT(exibble, rowname_col="row", groupname_col="group").as_raw_html()

the following invalid HTML is generated for a group label row and the row below:

<tbody class="gt_table_body">
<tr>
<tr class=gt_group_heading_row>  <th class="gt_group_heading" colspan="8">grp_a</th></tr>
  <th class="gt_row gt_left gt_stub">row_1</th>
  <td class="gt_row gt_right">0.1111</td>
  <td class="gt_row gt_left">apricot</td>
  <td class="gt_row gt_left">one</td>
  <td class="gt_row gt_right">2015-01-15</td>
  <td class="gt_row gt_right">13:35</td>
  <td class="gt_row gt_right">2018-01-01 02:22</td>
  <td class="gt_row gt_right">49.95</td>
</tr>

The first <tr> should instead be opening tag for the collection of <th> and <td> tags. Browsers could handle this invalid code and generate a suitable table display but not Quarto/Pandoc (requires that the HTML be valid in order for it to be parsed).

With this PR, the HTML generated should instead be:

<tbody class="gt_table_body">
  <tr class="gt_group_heading_row">
    <th class="gt_group_heading" colspan="8">grp_a</th>
  </tr>
  <tr>
    <th class="gt_row gt_left gt_stub">row_1</th>
    <td class="gt_row gt_right">0.1111</td>
    <td class="gt_row gt_left">apricot</td>
    <td class="gt_row gt_left">one</td>
    <td class="gt_row gt_right">2015-01-15</td>
    <td class="gt_row gt_right">13:35</td>
    <td class="gt_row gt_right">2018-01-01 02:22</td>
    <td class="gt_row gt_right">49.95</td>
  </tr>

Fixes: https://github.com/posit-dev/great-tables/issues/306

codecov-commenter commented 2 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 81.72%. Comparing base (14ce2c5) to head (9a1634b).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #308 +/- ## ======================================= Coverage 81.71% 81.72% ======================================= Files 41 41 Lines 4321 4323 +2 ======================================= + Hits 3531 3533 +2 Misses 790 790 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.