diff options
| author | Albert Krewinkel <[email protected]> | 2022-08-31 23:17:41 +0200 |
|---|---|---|
| committer | Albert Krewinkel <[email protected]> | 2022-09-01 09:06:42 +0200 |
| commit | 635b6e39536c813d1344825ba80c954d560a7d6d (patch) | |
| tree | b0c75db21e6fcf38d6729bc996ada9f4ec476e2e | |
| parent | 751383f33370928c7576f17d1a85d48cc9e8e30e (diff) | |
Use dev version of gridtables
This allows to specify a table foot by enclosing it with part separator
lines, i.e., row separator lines consisting only of `+` and `=`
characters. E.g.:
+------+-------+
| Item | Price |
+======+=======+
| Eggs | 5£ |
+------+-------+
| Spam | 3£ |
+======+=======+
| Sum | 8£ |
+======+=======+
The last row, containing "Sum" and "8£", is the table foot.
Closes: #8257
| -rw-r--r-- | cabal.project | 4 | ||||
| -rw-r--r-- | src/Text/Pandoc/Parsing/GridTable.hs | 12 | ||||
| -rw-r--r-- | test/command/8257.md | 41 |
3 files changed, 53 insertions, 4 deletions
diff --git a/cabal.project b/cabal.project index 8d9bb4062..b2effd0e0 100644 --- a/cabal.project +++ b/cabal.project @@ -15,3 +15,7 @@ source-repository-package tag: 6079d8b0fb6e45c6a03b05501900be1c151701e6 subdir: skylighting-format-blaze-html +source-repository-package + type: git + location: https://github.com/quarto-dev/gridtables + tag: 1dbf2ad311fc7b2d9aded51eb263067b6ff3ae28 diff --git a/src/Text/Pandoc/Parsing/GridTable.hs b/src/Text/Pandoc/Parsing/GridTable.hs index 58ab1494b..d579939b5 100644 --- a/src/Text/Pandoc/Parsing/GridTable.hs +++ b/src/Text/Pandoc/Parsing/GridTable.hs @@ -135,9 +135,13 @@ gridTableWith' normalization blocks = do let caption = B.emptyCaption return $ do rows'' <- mapM sequence rows' - let (hRows, bRows) = - splitAt (maybe 0 GT.fromRowIndex $ GT.arrayTableHead tbl) - (map (B.Row B.nullAttr) rows'') + let headLen = maybe 0 GT.fromRowIndex $ GT.arrayTableHead tbl + let (hRows, bRows') = + splitAt headLen (map (B.Row B.nullAttr) rows'') + let (bRows, fRows) = + case GT.arrayTableFoot tbl of + Just fIdx -> splitAt (GT.fromRowIndex fIdx - headLen - 1) bRows' + Nothing -> (bRows', []) let thead = B.TableHead B.nullAttr $ case (hRows, normalization) of -- normalize header if necessary: remove header if it contains -- only a single row in which all cells are empty. @@ -151,7 +155,7 @@ gridTableWith' normalization blocks = do in [B.Row nullAttr cells | not (null cells) && not (all simple cells)] _ -> hRows - let tfoot = B.TableFoot B.nullAttr [] + let tfoot = B.TableFoot B.nullAttr $ fRows let tbody = B.TableBody B.nullAttr 0 [] bRows return $ TableComponents nullAttr caption colspecs thead [tbody] tfoot diff --git a/test/command/8257.md b/test/command/8257.md new file mode 100644 index 000000000..a284fd38a --- /dev/null +++ b/test/command/8257.md @@ -0,0 +1,41 @@ +``` +% pandoc -f markdown -t html5 ++------+-------+ +| Item | Price | ++======+=======+ +| Eggs | 5£ | ++------+-------+ +| Spam | 3£ | ++======+=======+ +| Sum | 8£ | ++======+=======+ +^D +<table style="width:21%;"> +<colgroup> +<col style="width: 9%" /> +<col style="width: 11%" /> +</colgroup> +<thead> +<tr class="header"> +<th>Item</th> +<th>Price</th> +</tr> +</thead> +<tbody> +<tr class="odd"> +<td>Eggs</td> +<td>5£</td> +</tr> +<tr class="even"> +<td>Spam</td> +<td>3£</td> +</tr> +</tbody><tfoot> +<tr class="odd"> +<td>Sum</td> +<td>8£</td> +</tr> +</tfoot> + +</table> +``` |
