posit-dev / great-tables

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

Wrap header rows in `<thead>` #403

Closed cwickham closed 2 months ago

cwickham commented 4 months ago

Prework

Description

Header rows should always be wrapped in <thead>. In particular, this will mean tables output to Typst that break over pages get the header rows repeated on each page.

Reproducible example

Consider the following example:

from great_tables import GT, md, html
from great_tables.data import islands

gt_tbl = GT(islands)
# Show the output table
gt_tbl

This results in the following (partial) HTML:

<table class="gt_table" data-quarto-disable-processing="false" data-quarto-bootstrap="false">

<tr class="gt_col_headings">
  <th class="gt_col_heading gt_columns_bottom_border gt_left" rowspan="1" colspan="1" scope="col" id="name">name</th>
  <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1" scope="col" id="size">size</th>
</tr>
<tbody class="gt_table_body">
...

If this table is used in Quarto with format: typst and is allowed to break over pages, the header rows are not repeated on the second page:

Screenshot 2024-07-18 at 11 01 42 AM
QMD ````markdown --- title: "Untitled" format: typst keep-md: true --- ```{=typst} #show figure: set block(breakable: true) ``` ```{python} from great_tables import GT, md, html from great_tables.data import islands gt_tbl = GT(islands) # Show the output table gt_tbl ``` ````

Expected result

E.g. in gt the header rows are nested inside <thead>,

<table class="gt_table" data-quarto-disable-processing="false" data-quarto-bootstrap="false">
  <thead>
    <tr class="gt_col_headings">
      <th class="gt_col_heading gt_columns_bottom_border gt_left" rowspan="1" colspan="1" scope="col" id="name">name</th>
      <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1" scope="col" id="size">size</th>
    </tr>
  </thead>
  <tbody class="gt_table_body">

Then the header rows are repeated on the second page:

Screenshot 2024-07-18 at 11 05 32 AM

Development environment

machow commented 2 months ago

@cwickham we are adding thead in #421 -- does this look okay for the typst work?

Here's a snapshot showing the new thead placement (note that thead now closes on line 66 in the new code in the diff)

cwickham commented 2 months ago

Yeah, that looks great!