Skip to content

Commit

Permalink
Don't emit unnecessary classes in HTML tables (#9376)
Browse files Browse the repository at this point in the history
Pandoc used to emit a `header` class on the `tr` element that forms the table header. This is no longer needed, because `head > tr` will do the same thing.

Similarly, pandoc used to emit `even` and `odd` classes on `tr`s, allowing striped styling.  This is no longer needed, because one can use e.g. `tbody tr:nth-child(2n)`.

We now omit these classes, which have a good chance of conflicting with classes used for other things.

Closes #9325.
  • Loading branch information
ThomasSoeiro authored Jun 7, 2024
1 parent bfb0475 commit cd15313
Show file tree
Hide file tree
Showing 35 changed files with 197 additions and 203 deletions.
6 changes: 0 additions & 6 deletions src/Text/Pandoc/Writers/HTML.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1264,12 +1264,6 @@ tableRowToHtml :: PandocMonad m
-> TableRow
-> StateT WriterState m Html
tableRowToHtml opts (TableRow tblpart attr rownum rowhead rowbody) = do
let rowclass = case rownum of
Ann.RowNumber x | x `rem` 2 == 1 -> "odd"
_ | tblpart /= Thead -> "even"
_ -> "header"
let attr' = case attr of
(id', classes, rest) -> (id', rowclass:classes, rest)
let celltype = case tblpart of
Thead -> HeaderCell
_ -> BodyCell
Expand Down
10 changes: 5 additions & 5 deletions test/command/1166.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,28 @@ col 1 col 2
^D
<table>
<thead>
<tr class="header">
<tr>
<th>col 1</th>
<th>col 2</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<tr>
<td>1</td>
<td>Second column of row 1.</td>
</tr>
<tr class="even">
<tr>
<td><p>2</p></td>
<td><p>Second column of row 2. Second line of paragraph.</p></td>
</tr>
<tr class="odd">
<tr>
<td><p>3</p></td>
<td><ul>
<li>Second column of row 3.</li>
<li>Second item in bullet list (row 3, column 2).</li>
</ul></td>
</tr>
<tr class="even">
<tr>
<td></td>
<td>Row 4; column 1 will be empty.</td>
</tr>
Expand Down
6 changes: 3 additions & 3 deletions test/command/1881.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
<table>
<caption>Demonstration of simple table syntax.</caption>
<thead>
<tr class="header">
<tr>
<th align="right">Right</th>
<th align="left">Left</th>
<th align="center">Center</th>
<th>Default</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<tr>
<td align="right">12</td>
<td align="left">12</td>
<td align="center">12</td>
Expand Down Expand Up @@ -111,7 +111,7 @@
```
% pandoc -f html -t native
<table>
<tr class="odd">
<tr>
<td style="text-align: right;">12</td>
<td style="text-align:left;">12</td>
<td style="text-align: center">12</td>
Expand Down
6 changes: 3 additions & 3 deletions test/command/2606.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
^D
<table>
<tbody>
<tr class="odd">
<tr>
<td><p>* hello</p></td>
</tr>
</tbody>
Expand All @@ -22,7 +22,7 @@
^D
<table>
<tbody>
<tr class="odd">
<tr>
<td><ul>
<li>hello</li>
</ul></td>
Expand All @@ -40,7 +40,7 @@
^D
<table>
<tbody>
<tr class="odd">
<tr>
<td><p><code>* hello</code></p></td>
</tr>
</tbody>
Expand Down
18 changes: 9 additions & 9 deletions test/command/2649.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
^D
<table>
<tbody>
<tr class="odd">
<tr>
</tr>
</tbody>
</table>
Expand All @@ -31,24 +31,24 @@
^D
<table>
<tbody>
<tr class="odd">
<tr>
<td><p>peildatum Simbase</p></td>
<td><p>november 2005</p></td>
<td colspan="2"><p><strong>uitslagen Flohrgambiet</strong></p></td>
</tr>
<tr class="even">
<tr>
<td><p>totaal aantal partijen Simbase</p></td>
<td><p>7.316.773</p></td>
<td><p>wit wint</p></td>
<td><p>53%</p></td>
</tr>
<tr class="odd">
<tr>
<td><p>percentage (en partijen) Flohrgambiet</p></td>
<td><p>0.023 % (1.699)</p></td>
<td><p>zwart wint</p></td>
<td><p>27%</p></td>
</tr>
<tr class="even">
<tr>
<td><p>percentage Flohrgambiet in aug 2003</p></td>
<td><p>0.035 %</p></td>
<td><p>remise</p></td>
Expand Down Expand Up @@ -80,26 +80,26 @@
^D
<table>
<thead>
<tr class="header">
<tr>
<th><p>Plaats</p></th>
<th><p>Rijder</p></th>
<th><p>Aantal</p></th>
</tr>
</thead>
<tbody>
<tr class="odd">
<tr>
<td><p>1</p></td>
<td style="text-align: left;"><p><a href="Sébastien_Loeb"
title="wikilink">Sébastien Loeb</a></p></td>
<td><p>78</p></td>
</tr>
<tr class="even">
<tr>
<td><p>2</p></td>
<td style="text-align: left;"><p><strong><a href="Sébastien_Ogier"
title="wikilink">Sébastien Ogier</a></strong></p></td>
<td><p>38</p></td>
</tr>
<tr class="odd">
<tr>
<td><p>10</p></td>
<td style="text-align: left;"><p><a href="Hannu_Mikkola"
title="wikilink">Hannu Mikkola</a></p></td>
Expand Down
4 changes: 2 additions & 2 deletions test/command/3314.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ See #3315 and <http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.htm
<col style="width: 15%" />
</colgroup>
<tbody>
<tr class="odd">
<tr>
<td>First</td>
<td>12.0</td>
<td>Example row spanning lines</td>
</tr>
<tr class="even">
<tr>
<td>Second</td>
<td>5.0</td>
<td>Another</td>
Expand Down
44 changes: 22 additions & 22 deletions test/command/3432.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,24 @@ List-table with header-rows and widths options.
<col style="width: 54%" />
</colgroup>
<thead>
<tr class="header">
<tr>
<th>Treat</th>
<th>Quantity</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<tr>
<td>Albatross</td>
<td>2.99</td>
<td>On a stick!</td>
</tr>
<tr class="even">
<tr>
<td>Crunchy Frog</td>
<td>1.49</td>
<td>If we took the bones out, it wouldn't be crunchy, now would it?</td>
</tr>
<tr class="odd">
<tr>
<td>Gannet Ripple</td>
<td>1.99</td>
<td>On a stick!</td>
Expand Down Expand Up @@ -79,24 +79,24 @@ List-table whose widths is "auto".
<table>
<caption>Frozen Delights!</caption>
<thead>
<tr class="header">
<tr>
<th>Treat</th>
<th>Quantity</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<tr>
<td>Albatross</td>
<td>2.99</td>
<td>On a stick!</td>
</tr>
<tr class="even">
<tr>
<td>Crunchy Frog</td>
<td>1.49</td>
<td>If we took the bones out, it wouldn't be crunchy, now would it?</td>
</tr>
<tr class="odd">
<tr>
<td>Gannet Ripple</td>
<td>1.99</td>
<td>On a stick!</td>
Expand Down Expand Up @@ -130,24 +130,24 @@ List-table with header-rows which is bigger than 1. Only the first row is treate
<table>
<caption>Frozen Delights!</caption>
<thead>
<tr class="header">
<tr>
<th>Treat</th>
<th>Quantity</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<tr>
<td>Albatross</td>
<td>2.99</td>
<td>On a stick!</td>
</tr>
<tr class="even">
<tr>
<td>Crunchy Frog</td>
<td>1.49</td>
<td>If we took the bones out, it wouldn't be crunchy, now would it?</td>
</tr>
<tr class="odd">
<tr>
<td>Gannet Ripple</td>
<td>1.99</td>
<td>On a stick!</td>
Expand Down Expand Up @@ -176,17 +176,17 @@ List-table without header-rows.
<table>
<caption>Frozen Delights!</caption>
<tbody>
<tr class="odd">
<tr>
<td>Albatross</td>
<td>2.99</td>
<td>On a stick!</td>
</tr>
<tr class="even">
<tr>
<td>Crunchy Frog</td>
<td>1.49</td>
<td>If we took the bones out, it wouldn't be crunchy, now would it?</td>
</tr>
<tr class="odd">
<tr>
<td>Gannet Ripple</td>
<td>1.99</td>
<td>On a stick!</td>
Expand Down Expand Up @@ -219,24 +219,24 @@ List-table with empty cells. You need a space after '-', otherwise the row will
<table>
<caption>Frozen Delights!</caption>
<thead>
<tr class="header">
<tr>
<th>Treat</th>
<th>Quantity</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<tr>
<td>Albatross</td>
<td>2.99</td>
<td></td>
</tr>
<tr class="even">
<tr>
<td>Crunchy Frog</td>
<td></td>
<td>If we took the bones out, it wouldn't be crunchy, now would it?</td>
</tr>
<tr class="odd">
<tr>
<td>Gannet Ripple</td>
<td>1.99</td>
<td>On a stick!</td>
Expand Down Expand Up @@ -266,20 +266,20 @@ List-table with a cell having a bulletlist
<table>
<caption>Frozen Delights!</caption>
<tbody>
<tr class="odd">
<tr>
<td>Albatross</td>
<td>2.99</td>
<td><ul>
<li>On a stick!</li>
<li>In a cup!</li>
</ul></td>
</tr>
<tr class="even">
<tr>
<td>Crunchy Frog</td>
<td>1.49</td>
<td>If we took the bones out, it wouldn't be crunchy, now would it?</td>
</tr>
<tr class="odd">
<tr>
<td>Gannet Ripple</td>
<td>1.99</td>
<td>On a stick!</td>
Expand Down
8 changes: 4 additions & 4 deletions test/command/3494.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@
^D
<table>
<tbody>
<tr class="odd">
<tr>
<td style="text-align: right;"><span><strong>ﺍ</strong></span></td>
<td style="text-align: left;"></td>
<td style="text-align: left;"></td>
</tr>
<tr class="even">
<tr>
<td style="text-align: right;"><strong>ﺄﺤﺴﻨﺘـ(ﻭﺍ) IV</strong></td>
<td style="text-align: left;"><em><span>ʾaḥsant(ū)</span></em></td>
<td style="text-align: left;">thank you</td>
</tr>
<tr class="odd">
<tr>
<td style="text-align: right;"><em>blah</em></td>
<td style="text-align: left;"><em>blah</em></td>
<td style="text-align: left;"><em>blah</em></td>
</tr>
<tr class="even">
<tr>
<td style="text-align: right;">blah</td>
<td style="text-align: left;">blah</td>
<td style="text-align: left;">blah</td>
Expand Down
2 changes: 1 addition & 1 deletion test/command/3499.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Org-mode tables can't be on the same line as list markers:
<li>|something|</li>
<li><table>
<tbody>
<tr class="odd">
<tr>
<td>else</td>
</tr>
</tbody>
Expand Down
2 changes: 1 addition & 1 deletion test/command/3667.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
^D
<table>
<tbody>
<tr class="odd">
<tr>
<td><a href="http://example.com/">link text</a></td>
</tr>
</tbody>
Expand Down
Loading

0 comments on commit cd15313

Please sign in to comment.