Skip to content

Commit 97b7d48

Browse files
committed
gridTable: fix (3.7) regression with missing cell alignments.
Closes #10853.
1 parent f4c7fcc commit 97b7d48

File tree

6 files changed

+23
-20
lines changed

6 files changed

+23
-20
lines changed

src/Text/Pandoc/Writers/Shared.hs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -438,9 +438,11 @@ gridRows (x:xs) =
438438
rowAndBottom thisRow nextRow =
439439
let isLastRow = null nextRow
440440
border1 = render Nothing (formatBorder cellBottomBorder False thisRow)
441-
border2 = render Nothing (formatBorder cellTopBorder False nextRow)
441+
border2 = render Nothing (formatBorder cellTopBorder True nextRow)
442442
go '+' _ = '+'
443443
go _ '+' = '+'
444+
go ':' _ = ':'
445+
go _ ':' = ':'
444446
go '|' '-' = '+'
445447
go '-' '|' = '+'
446448
go '|' '=' = '+'
@@ -454,7 +456,7 @@ gridRows (x:xs) =
454456
else literal $ T.zipWith go border1 border2
455457
in formatRow thisRow $$ combinedBorder
456458

457-
formatBorder :: (RenderedCell a -> LineStyle) -> Bool -> [RenderedCell a]
459+
formatBorder :: Show a => (RenderedCell a -> LineStyle) -> Bool -> [RenderedCell a]
458460
-> Doc Text
459461
formatBorder borderStyle alignMarkers cs =
460462
borderParts <> if lastBorderStyle == NoLine
@@ -476,7 +478,8 @@ formatBorder borderStyle alignMarkers cs =
476478
DoubleLine -> '='
477479
(leftalign, rightalign) =
478480
case cellAlign c of
479-
_ | not alignMarkers -> (lineChar,lineChar)
481+
_ | not alignMarkers || borderStyle c /= DoubleLine
482+
-> (lineChar,lineChar)
480483
AlignLeft -> (':',lineChar)
481484
AlignCenter -> (':',':')
482485
AlignRight -> (lineChar,':')

test/tables-rstsubset.native

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -462,10 +462,10 @@
462462
, Str "lines."
463463
]
464464
])
465-
[ ( AlignDefault , ColWidth 0.15 )
466-
, ( AlignDefault , ColWidth 0.1375 )
467-
, ( AlignDefault , ColWidth 0.1625 )
468-
, ( AlignDefault , ColWidth 0.35 )
465+
[ ( AlignCenter , ColWidth 0.15 )
466+
, ( AlignLeft , ColWidth 0.1375 )
467+
, ( AlignRight , ColWidth 0.1625 )
468+
, ( AlignLeft , ColWidth 0.35 )
469469
]
470470
(TableHead
471471
( "" , [] , [] )
@@ -606,10 +606,10 @@
606606
, Table
607607
( "" , [] , [] )
608608
(Caption Nothing [])
609-
[ ( AlignDefault , ColWidth 0.15 )
610-
, ( AlignDefault , ColWidth 0.1375 )
611-
, ( AlignDefault , ColWidth 0.1625 )
612-
, ( AlignDefault , ColWidth 0.35 )
609+
[ ( AlignCenter , ColWidth 0.15 )
610+
, ( AlignLeft , ColWidth 0.1375 )
611+
, ( AlignRight , ColWidth 0.1625 )
612+
, ( AlignLeft , ColWidth 0.35 )
613613
]
614614
(TableHead
615615
( "" , [] , [] )

test/tables.haddock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Simple table with caption:
22

33
+-------+------+--------+---------+
44
| Right | Left | Center | Default |
5-
+=======+======+========+=========+
5+
+======:+:=====+:======:+=========+
66
| 12 | 12 | 12 | 12 |
77
+-------+------+--------+---------+
88
| 123 | 123 | 123 | 123 |
@@ -16,7 +16,7 @@ Simple table without caption:
1616

1717
+-------+------+--------+---------+
1818
| Right | Left | Center | Default |
19-
+=======+======+========+=========+
19+
+======:+:=====+:======:+=========+
2020
| 12 | 12 | 12 | 12 |
2121
+-------+------+--------+---------+
2222
| 123 | 123 | 123 | 123 |
@@ -28,7 +28,7 @@ Simple table indented two spaces:
2828

2929
+-------+------+--------+---------+
3030
| Right | Left | Center | Default |
31-
+=======+======+========+=========+
31+
+======:+:=====+:======:+=========+
3232
| 12 | 12 | 12 | 12 |
3333
+-------+------+--------+---------+
3434
| 123 | 123 | 123 | 123 |
@@ -43,7 +43,7 @@ Multiline table with caption:
4343
+-----------+----------+------------+---------------------------+
4444
| Centered | Left | Right | Default aligned |
4545
| Header | Aligned | Aligned | |
46-
+===========+==========+============+===========================+
46+
+:=========:+:=========+===========:+:==========================+
4747
| First | row | 12.0 | Example of a row that |
4848
| | | | spans multiple lines. |
4949
+-----------+----------+------------+---------------------------+
@@ -59,7 +59,7 @@ Multiline table without caption:
5959
+-----------+----------+------------+---------------------------+
6060
| Centered | Left | Right | Default aligned |
6161
| Header | Aligned | Aligned | |
62-
+===========+==========+============+===========================+
62+
+:=========:+:=========+===========:+:==========================+
6363
| First | row | 12.0 | Example of a row that |
6464
| | | | spans multiple lines. |
6565
+-----------+----------+------------+---------------------------+

test/tables.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Multiline table with caption:
3939
+-----------+----------+------------+---------------------------+
4040
| Centered | Left | Right | Default aligned |
4141
| Header | Aligned | Aligned | |
42-
+===========+==========+============+===========================+
42+
+:=========:+:=========+===========:+:==========================+
4343
| First | row | 12.0 | Example of a row that |
4444
| | | | spans multiple lines. |
4545
+-----------+----------+------------+---------------------------+
@@ -53,7 +53,7 @@ Multiline table without caption:
5353
+-----------+----------+------------+---------------------------+
5454
| Centered | Left | Right | Default aligned |
5555
| Header | Aligned | Aligned | |
56-
+===========+==========+============+===========================+
56+
+:=========:+:=========+===========:+:==========================+
5757
| First | row | 12.0 | Example of a row that |
5858
| | | | spans multiple lines. |
5959
+-----------+----------+------------+---------------------------+

test/tables/planets.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
| | Name | Mass | Diameter | Density | Gravity | Length | Distance | Mean | Number | Notes |
33
| | | (10\^24kg) | (km) | (kg/m\^3) | (m/s\^2) | of day | from Sun | temperature | of | |
44
| | | | | | | (hours) | (10\^6km) | (C) | moons | |
5-
+==================+=========+============+==========+===========+==========+=========+===========+=============+========+==============+
5+
+:================:+=========+===========:+=========:+==========:+=========:+========:+==========:+============:+=======:+==============+
66
| Terrestrial | Mercury | 0.330 | 4,879 | 5427 | 3.7 | 4222.6 | 57.9 | 167 | 0 | Closest to |
77
| planets | | | | | | | | | | the Sun |
88
| +---------+------------+----------+-----------+----------+---------+-----------+-------------+--------+--------------+

test/tables/students.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
+-----------------------------------------+-----------------------------------------+
22
| Student ID | Name |
3-
+=========================================+=========================================+
3+
+:========================================+=========================================+
44
| Computer Science |
55
+-----------------------------------------+-----------------------------------------+
66
| 3741255 | Jones, Martha |

0 commit comments

Comments
 (0)