git.iko.soy/typeable/pandoc
on master help sign in
[API change] Rename Writers.Tables and its contents (#6679)

Writers.Tables is now Writers.AnnotatedTable. All of the types and functions in it have had the "Ann" removed from them. Now it is expected that the module be imported qualified.

commit22babd5382c21d32e9d73984c5d5ff3d83ba715b authorChristian Despres <50160106+despresc@users.noreply.github.com> dateSat 12 Sep 2020, 11:50 (6 years ago) parent6fda8cf
6 files changed+390−379
pandoc.cabal+2−2 src/Text/Pandoc/Writers/AnnotatedTable.hs+300 src/Text/Pandoc/Writers/HTML.hs+20−20 src/Text/Pandoc/Writers/Tables.hs−291 test/Tests/Writers/Tables.hs → test/Tests/Writers/AnnotatedTable.hs+66−64 test/test-pandoc.hs+2−2
pandoc.cabal+2−2
@@ -553,7 +553,7 @@ library
553553 Text.Pandoc.Writers.Math,
554554 Text.Pandoc.Writers.Shared,
555555 Text.Pandoc.Writers.OOXML,
556− Text.Pandoc.Writers.Tables,
556+ Text.Pandoc.Writers.AnnotatedTable,
557557 Text.Pandoc.Lua,
558558 Text.Pandoc.PDF,
559559 Text.Pandoc.UTF8,
@@ -821,7 +821,7 @@ test-suite test-pandoc
821821 Tests.Writers.Powerpoint
822822 Tests.Writers.OOXML
823823 Tests.Writers.Ms
824− Tests.Writers.Tables
824+ Tests.Writers.AnnotatedTable
825825 if os(windows)
826826 cpp-options: -D_WINDOWS
827827 default-language: Haskell2010
src/Text/Pandoc/Writers/AnnotatedTable.hsnew file+300
@@ -0,0 +1,300 @@
1+{-# LANGUAGE BangPatterns #-}
2+{-# LANGUAGE DeriveDataTypeable #-}
3+{-# LANGUAGE DeriveGeneric #-}
4+{-# LANGUAGE GeneralizedNewtypeDeriving #-}
5+{-# LANGUAGE TupleSections #-}
6+
7+{- |
8+ Module : Text.Pandoc.Writers.AnnotatedTable
9+ Copyright : Copyright 2020 Christian Despres
10+ License : GNU GPL, version 2 or above
11+
12+ Maintainer : Christian Despres <christian.j.j.despres@gmail.com>
13+ Stability : alpha
14+ Portability : portable
15+
16+Definitions and conversion functions for an intermediate 'Table' and
17+related types, which annotates the existing Pandoc 'B.Table' types
18+with additional inferred information. For use in writers that need to
19+know the details of columns that cells span, row numbers, and the
20+cells that are in the row head.
21+-}
22+
23+module Text.Pandoc.Writers.AnnotatedTable
24+ ( toTable
25+ , fromTable
26+ , Table(..)
27+ , TableHead(..)
28+ , TableBody(..)
29+ , TableFoot(..)
30+ , HeaderRow(..)
31+ , BodyRow(..)
32+ , RowNumber(..)
33+ , RowHead
34+ , RowBody
35+ , Cell(..)
36+ , ColNumber(..)
37+ )
38+where
39+
40+import Control.Monad.RWS.Strict
41+ hiding ( (<>) )
42+import Data.Generics ( Data
43+ , Typeable
44+ )
45+import Data.List.NonEmpty ( NonEmpty(..) )
46+import GHC.Generics ( Generic )
47+import qualified Text.Pandoc.Builder as B
48+
49+-- | An annotated table type, corresponding to the Pandoc 'B.Table'
50+-- constructor and the HTML @\<table\>@ element. It records the data
51+-- of the columns that cells span, the cells in the row head, the row
52+-- numbers of rows, and the column numbers of cells, in addition to
53+-- the data in a 'B.Table'. The type itself does not enforce any
54+-- guarantees about the consistency of this data. Use 'toTable' to
55+-- produce a 'Table' from a Pandoc 'B.Table'.
56+data Table = Table B.Attr B.Caption [B.ColSpec] TableHead [TableBody] TableFoot
57+ deriving (Eq, Ord, Read, Show, Typeable, Data, Generic)
58+
59+-- | An annotated table head, corresponding to a Pandoc 'B.TableHead'
60+-- and the HTML @\<thead\>@ element.
61+data TableHead = TableHead B.Attr [HeaderRow]
62+ deriving (Eq, Ord, Read, Show, Typeable, Data, Generic)
63+
64+-- | An annotated table body, with an intermediate head and body,
65+-- corresponding to a Pandoc 'B.TableBody' and the HTML @\<tbody\>@
66+-- element.
67+data TableBody = TableBody B.Attr B.RowHeadColumns [HeaderRow] [BodyRow]
68+ deriving (Eq, Ord, Read, Show, Typeable, Data, Generic)
69+
70+-- | An annotated table foot, corresponding to a Pandoc 'B.TableFoot'
71+-- and the HTML @\<tfoot\>@ element.
72+data TableFoot = TableFoot B.Attr [HeaderRow]
73+ deriving (Eq, Ord, Read, Show, Typeable, Data, Generic)
74+
75+-- | An annotated header row, corresponding to a Pandoc 'B.Row' and
76+-- the HTML @\<tr\>@ element, and also recording the row number of the
77+-- row. All the cells in a 'HeaderRow' are header (@\<th\>@) cells.
78+data HeaderRow = HeaderRow B.Attr RowNumber [Cell]
79+ deriving (Eq, Ord, Read, Show, Typeable, Data, Generic)
80+
81+-- | An annotated body row, corresponding to a Pandoc 'B.Row' and the
82+-- HTML @\<tr\>@ element, and also recording its row number and
83+-- separating the row head cells from the row body cells.
84+data BodyRow = BodyRow B.Attr RowNumber RowHead RowBody
85+ deriving (Eq, Ord, Read, Show, Typeable, Data, Generic)
86+
87+-- | The row number of a row. Note that rows are numbered continuously
88+-- from zero from the start of the table, so the first row in a table
89+-- body, for instance, may have a large 'RowNumber'.
90+newtype RowNumber = RowNumber Int
91+ deriving (Eq, Ord, Read, Show, Typeable, Data, Generic, Num, Enum)
92+
93+-- | The head of a body row; the portion of the row lying in the stub
94+-- of the 'TableBody'. Its cells correspond to HTML @\<th\>@ cells.
95+type RowHead = [Cell]
96+
97+-- | The body of a body row; the portion of the row lying after the
98+-- stub of the 'TableBody'. Its cells correspond to HTML @\<td\>@
99+-- cells.
100+type RowBody = [Cell]
101+
102+-- | An annotated table cell, wrapping a Pandoc 'B.Cell' with its
103+-- 'ColNumber' and the 'B.ColSpec' data for the columns that the cell
104+-- spans.
105+data Cell = Cell (NonEmpty B.ColSpec) ColNumber B.Cell
106+ deriving (Eq, Ord, Read, Show, Typeable, Data, Generic)
107+
108+-- | The column number of a cell, meaning the column number of the
109+-- first column that the cell spans, if the table were laid on a
110+-- grid. Columns are numbered starting from zero.
111+newtype ColNumber = ColNumber Int
112+ deriving (Eq, Ord, Read, Show, Typeable, Data, Generic, Num, Enum)
113+
114+-- | Convert a Pandoc 'B.Table' to an annotated 'Table'. This function
115+-- also performs the same normalization that the 'B.table' builder
116+-- does (fixing overlapping cells, cells that protrude out of their
117+-- table section, and so on). If the input table happens to satisfy
118+-- the conditions that 'B.table' guarantees, then the resulting
119+-- 'Table' will be identical, save for the addition of the inferred
120+-- table information.
121+toTable
122+ :: B.Attr
123+ -> B.Caption
124+ -> [B.ColSpec]
125+ -> B.TableHead
126+ -> [B.TableBody]
127+ -> B.TableFoot
128+ -> Table
129+toTable attr cap cs th tbs tf = Table attr cap cs th' tbs' tf'
130+ where
131+ (th', tbs', tf') = fst $ evalRWS (annotateTable th tbs tf) (cs, length cs) 0
132+
133+-- | Internal monad for annotating a table, passing in the 'B.ColSpec'
134+-- data for the table, the grid width, and the current 'RowNumber' to
135+-- be referenced or updated.
136+type AnnM a = RWS ([B.ColSpec], Int) () RowNumber a
137+
138+incRowNumber :: AnnM RowNumber
139+incRowNumber = do
140+ rn <- get
141+ put $ rn + 1
142+ return rn
143+
144+annotateTable
145+ :: B.TableHead
146+ -> [B.TableBody]
147+ -> B.TableFoot
148+ -> AnnM (TableHead, [TableBody], TableFoot)
149+annotateTable th tbs tf = do
150+ th' <- annotateTableHead th
151+ tbs' <- traverse annotateTableBody tbs
152+ tf' <- annotateTableFoot tf
153+ return (th', tbs', tf')
154+
155+annotateTableHead :: B.TableHead -> AnnM TableHead
156+annotateTableHead (B.TableHead attr rows) =
157+ TableHead attr <$> annotateHeaderSection rows
158+
159+annotateTableBody :: B.TableBody -> AnnM TableBody
160+annotateTableBody (B.TableBody attr rhc th tb) = do
161+ twidth <- asks snd
162+ let rhc' = max 0 $ min (B.RowHeadColumns twidth) rhc
163+ th' <- annotateHeaderSection th
164+ tb' <- annotateBodySection rhc' tb
165+ return $ TableBody attr rhc' th' tb'
166+
167+annotateTableFoot :: B.TableFoot -> AnnM TableFoot
168+annotateTableFoot (B.TableFoot attr rows) =
169+ TableFoot attr <$> annotateHeaderSection rows
170+
171+annotateHeaderSection :: [B.Row] -> AnnM [HeaderRow]
172+annotateHeaderSection rows = do
173+ colspec <- asks fst
174+ let hangcolspec = (1, ) <$> colspec
175+ annotateHeaderSection' hangcolspec id $ B.clipRows rows
176+ where
177+ annotateHeaderSection' oldHang acc (B.Row attr cells : rs) = do
178+ let (_, newHang, cells', _) =
179+ annotateRowSection 0 oldHang $ cells <> repeat B.emptyCell
180+ n <- incRowNumber
181+ let annRow = HeaderRow attr n cells'
182+ annotateHeaderSection' newHang (acc . (annRow :)) rs
183+ annotateHeaderSection' _ acc [] = return $ acc []
184+
185+annotateBodySection :: B.RowHeadColumns -> [B.Row] -> AnnM [BodyRow]
186+annotateBodySection (B.RowHeadColumns rhc) rows = do
187+ colspec <- asks fst
188+ let colspec' = (1, ) <$> colspec
189+ let (stubspec, bodyspec) = splitAt rhc colspec'
190+ normalizeBodySection' stubspec bodyspec id $ B.clipRows rows
191+ where
192+ normalizeBodySection' headHang bodyHang acc (B.Row attr cells : rs) = do
193+ let (colnum, headHang', rowStub, cells') =
194+ annotateRowSection 0 headHang $ cells <> repeat B.emptyCell
195+ let (_, bodyHang', rowBody, _) = annotateRowSection colnum bodyHang cells'
196+ n <- incRowNumber
197+ let annRow = BodyRow attr n rowStub rowBody
198+ normalizeBodySection' headHang' bodyHang' (acc . (annRow :)) rs
199+ normalizeBodySection' _ _ acc [] = return $ acc []
200+
201+-- | Lay out a section of a 'Table' row on a grid row, annotating the
202+-- cells with the 'B.ColSpec' data for the columns that they
203+-- span. Performs the same normalization as 'B.placeRowSection'.
204+annotateRowSection
205+ :: ColNumber -- ^ The current column number
206+ -> [(B.RowSpan, B.ColSpec)] -- ^ The overhang of the previous grid row,
207+ -- with column data
208+ -> [B.Cell] -- ^ The cells to annotate
209+ -> (ColNumber, [(B.RowSpan, B.ColSpec)], [Cell], [B.Cell]) -- ^ The new
210+ -- column
211+ -- number,
212+ -- overhang,
213+ -- annotated
214+ -- cells,
215+ -- and
216+ -- remaining
217+ -- cells
218+annotateRowSection !colnum oldHang cells
219+ -- If the grid has overhang at our position, try to re-lay in
220+ -- the next position.
221+ | (o, colspec) : os <- oldHang
222+ , o > 1
223+ = let (colnum', newHang, newCell, cells') =
224+ annotateRowSection (colnum + 1) os cells
225+ in (colnum', (o - 1, colspec) : newHang, newCell, cells')
226+ -- Otherwise if there is any available width, place the cell and
227+ -- continue.
228+ | c : cells' <- cells
229+ , (h, w) <- getDim c
230+ , w' <- max 1 w
231+ , (w'', cellHang@(chStart : chRest), oldHang') <- splitCellHang h w' oldHang
232+ = let c' = setW w'' c
233+ annCell = Cell (snd <$> chStart :| chRest) colnum c'
234+ colnum' = colnum + ColNumber (getColSpan w'')
235+ (colnum'', newHang, newCells, remainCells) =
236+ annotateRowSection colnum' oldHang' cells'
237+ in (colnum'', cellHang <> newHang, annCell : newCells, remainCells)
238+ -- Otherwise there is no room in the section
239+ | otherwise
240+ = (colnum, [], [], cells)
241+ where
242+ getColSpan (B.ColSpan x) = x
243+ getDim (B.Cell _ _ h w _) = (h, w)
244+ setW w (B.Cell a b h _ c) = B.Cell a b h w c
245+
246+-- | In @'splitCellHang' rs cs coldata@, with @rs@ the height of a
247+-- cell that lies at the beginning of @coldata@, and @cs@ its width
248+-- (which is not assumed to fit in the available space), return the
249+-- actual width of the cell (what will fit in the available space),
250+-- the data for the columns that the cell spans (including updating
251+-- the overhang to equal @rs@), and the remaining column data.
252+splitCellHang
253+ :: B.RowSpan
254+ -> B.ColSpan
255+ -> [(B.RowSpan, B.ColSpec)]
256+ -> (B.ColSpan, [(B.RowSpan, B.ColSpec)], [(B.RowSpan, B.ColSpec)])
257+splitCellHang h n = go 0
258+ where
259+ go acc ((1, spec) : ls) | acc < n =
260+ let (acc', hang, ls') = go (acc + 1) ls in (acc', (h, spec) : hang, ls')
261+ go acc l = (acc, [], l)
262+
263+-- | Convert an annotated 'Table' to a Pandoc
264+-- 'B.Table'. This is the inverse of 'toTable' on
265+-- well-formed tables (i.e. tables satisfying the guarantees of
266+-- 'B.table').
267+fromTable
268+ :: Table
269+ -> ( B.Attr
270+ , B.Caption
271+ , [B.ColSpec]
272+ , B.TableHead
273+ , [B.TableBody]
274+ , B.TableFoot
275+ )
276+fromTable (Table attr cap cs th tbs tf) = (attr, cap, cs, th', tbs', tf')
277+ where
278+ th' = fromTableHead th
279+ tbs' = map fromTableBody tbs
280+ tf' = fromTableFoot tf
281+
282+fromTableHead :: TableHead -> B.TableHead
283+fromTableHead (TableHead attr rows) = B.TableHead attr $ fromHeaderRow <$> rows
284+
285+fromTableBody :: TableBody -> B.TableBody
286+fromTableBody (TableBody attr rhc th tb) =
287+ B.TableBody attr rhc (fromHeaderRow <$> th) (fromBodyRow <$> tb)
288+
289+fromTableFoot :: TableFoot -> B.TableFoot
290+fromTableFoot (TableFoot attr rows) = B.TableFoot attr $ fromHeaderRow <$> rows
291+
292+fromHeaderRow :: HeaderRow -> B.Row
293+fromHeaderRow (HeaderRow attr _ cells) = B.Row attr $ fromCell <$> cells
294+
295+fromBodyRow :: BodyRow -> B.Row
296+fromBodyRow (BodyRow attr _ rh rb) =
297+ B.Row attr ((fromCell <$> rh) <> (fromCell <$> rb))
298+
299+fromCell :: Cell -> B.Cell
300+fromCell (Cell _ _ c) = c
src/Text/Pandoc/Writers/HTML.hs+20−20
@@ -56,7 +56,7 @@ import Text.Pandoc.Templates (renderTemplate)
5656import Text.Pandoc.Walk
5757import Text.Pandoc.Writers.Math
5858import Text.Pandoc.Writers.Shared
59−import Text.Pandoc.Writers.Tables
59+import qualified Text.Pandoc.Writers.AnnotatedTable as Ann
6060import Text.Pandoc.XML (escapeStringForXML, fromEntities, toEntities,
6161 html5Attributes, html4Attributes, rdfaAttributes)
6262import qualified Text.Blaze.XHtml5 as H5
@@ -904,13 +904,13 @@ blockToHtml opts (DefinitionList lst) = do
904904 intersperse (nl opts) defs') lst
905905 defList opts contents
906906blockToHtml opts (Table attr caption colspecs thead tbody tfoot) =
907− tableToHtml opts (toAnnTable attr caption colspecs thead tbody tfoot)
907+ tableToHtml opts (Ann.toTable attr caption colspecs thead tbody tfoot)
908908
909909tableToHtml :: PandocMonad m
910910 => WriterOptions
911− -> AnnTable
911+ -> Ann.Table
912912 -> StateT WriterState m Html
913−tableToHtml opts (AnnTable attr caption colspecs thead tbodies _tfoot) = do
913+tableToHtml opts (Ann.Table attr caption colspecs thead tbodies _tfoot) = do
914914 captionDoc <- case caption of
915915 Caption _ [] -> return mempty
916916 Caption _ longCapt -> do
@@ -941,16 +941,16 @@ tableToHtml opts (AnnTable attr caption colspecs thead tbodies _tfoot) = do
941941
942942tableBodyToHtml :: PandocMonad m
943943 => WriterOptions
944− -> AnnTableBody
944+ -> Ann.TableBody
945945 -> StateT WriterState m Html
946−tableBodyToHtml opts (AnnTableBody _attr _rowHeadCols _intm rows) =
946+tableBodyToHtml opts (Ann.TableBody _attr _rowHeadCols _intm rows) =
947947 H.tbody <$> bodyRowsToHtml opts rows
948948
949949tableHeadToHtml :: PandocMonad m
950950 => WriterOptions
951− -> AnnTableHead
951+ -> Ann.TableHead
952952 -> StateT WriterState m Html
953−tableHeadToHtml opts (AnnTableHead attr rows) =
953+tableHeadToHtml opts (Ann.TableHead attr rows) =
954954 if null rows || all isEmptyRow rows
955955 then return mempty
956956 else do
@@ -960,8 +960,8 @@ tableHeadToHtml opts (AnnTableHead attr rows) =
960960 headElement
961961 nl opts
962962 where
963− isEmptyRow (AnnHeaderRow _attr _rownum cells) = all isEmptyCell cells
964− isEmptyCell (AnnCell _colspecs _colnum cell) =
963+ isEmptyRow (Ann.HeaderRow _attr _rownum cells) = all isEmptyCell cells
964+ isEmptyCell (Ann.Cell _colspecs _colnum cell) =
965965 cell == Cell nullAttr AlignDefault (RowSpan 1) (ColSpan 1) []
966966
967967
@@ -970,26 +970,26 @@ data RowType = HeaderRow | FooterRow | BodyRow
970970
971971data CellType = HeaderCell | BodyCell
972972
973−data TableRow = TableRow RowType Attr RowNumber AnnRowHead AnnRowBody
973+data TableRow = TableRow RowType Attr Ann.RowNumber Ann.RowHead Ann.RowBody
974974
975975headerRowsToHtml :: PandocMonad m
976976 => WriterOptions
977− -> [AnnHeaderRow]
977+ -> [Ann.HeaderRow]
978978 -> StateT WriterState m Html
979979headerRowsToHtml opts =
980980 rowListToHtml opts . map toTableRow
981981 where
982− toTableRow (AnnHeaderRow attr rownum rowbody) =
982+ toTableRow (Ann.HeaderRow attr rownum rowbody) =
983983 TableRow HeaderRow attr rownum [] rowbody
984984
985985bodyRowsToHtml :: PandocMonad m
986986 => WriterOptions
987− -> [AnnBodyRow]
987+ -> [Ann.BodyRow]
988988 -> StateT WriterState m Html
989989bodyRowsToHtml opts =
990990 rowListToHtml opts . zipWith toTableRow [1..]
991991 where
992− toTableRow rownum (AnnBodyRow attr _rownum rowhead rowbody) =
992+ toTableRow rownum (Ann.BodyRow attr _rownum rowhead rowbody) =
993993 TableRow BodyRow attr rownum rowhead rowbody
994994
995995
@@ -1036,9 +1036,9 @@ tableRowToHtml :: PandocMonad m
10361036 -> StateT WriterState m Html
10371037tableRowToHtml opts (TableRow rowtype _attr rownum rowhead rowbody) = do
10381038 let rowclass = A.class_ $ case rownum of
1039− RowNumber x | x `rem` 2 == 1 -> "odd"
1040− _ | rowtype /= HeaderRow -> "even"
1041− _ -> "header"
1039+ Ann.RowNumber x | x `rem` 2 == 1 -> "odd"
1040+ _ | rowtype /= HeaderRow -> "even"
1041+ _ -> "header"
10421042 let celltype = case rowtype of
10431043 HeaderRow -> HeaderCell
10441044 _ -> BodyCell
@@ -1068,9 +1068,9 @@ rowspanAttrib = \case
10681068cellToHtml :: PandocMonad m
10691069 => WriterOptions
10701070 -> CellType
1071− -> AnnCell
1071+ -> Ann.Cell
10721072 -> StateT WriterState m Html
1073−cellToHtml opts celltype (AnnCell (colspec :| _) _colNum cell) =
1073+cellToHtml opts celltype (Ann.Cell (colspec :| _) _colNum cell) =
10741074 let align = fst colspec
10751075 in tableCellToHtml opts celltype align cell
10761076
src/Text/Pandoc/Writers/Tables.hsdeleted−291
@@ -1,291 +0,0 @@
1−{-# LANGUAGE BangPatterns #-}
2−{-# LANGUAGE DeriveDataTypeable #-}
3−{-# LANGUAGE DeriveGeneric #-}
4−{-# LANGUAGE GeneralizedNewtypeDeriving #-}
5−{-# LANGUAGE TupleSections #-}
6−
7−{- |
8− Module : Text.Pandoc.Writers.Tables
9− Copyright : Copyright 2020 Christian Despres
10− License : GNU GPL, version 2 or above
11−
12− Maintainer : Christian Despres <christian.j.j.despres@gmail.com>
13− Stability : alpha
14− Portability : portable
15−
16−Definitions and helper functions for an intermediate 'AnnTable' type,
17−which annotates the existing 'Table' types with additional inferred
18−information. For use in writers that need to know the details of
19−columns that cells span, row numbers, and the cells that are in the
20−row head.
21−-}
22−
23−module Text.Pandoc.Writers.Tables
24− ( toAnnTable
25− , fromAnnTable
26− , AnnTable(..)
27− , AnnTableHead(..)
28− , AnnTableBody(..)
29− , AnnTableFoot(..)
30− , AnnHeaderRow(..)
31− , AnnBodyRow(..)
32− , RowNumber(..)
33− , AnnRowHead
34− , AnnRowBody
35− , AnnCell(..)
36− , ColNumber(..)
37− )
38−where
39−
40−import Control.Monad.RWS.Strict
41− hiding ( (<>) )
42−import Data.Generics ( Data
43− , Typeable
44− )
45−import Data.List.NonEmpty ( NonEmpty(..) )
46−import GHC.Generics ( Generic )
47−import Text.Pandoc.Builder
48−
49−-- | An annotated table type, corresponding to the 'Table' constructor
50−-- and the HTML @\<table\>@ element. It records the data of the
51−-- columns that cells span, the cells in the row head, the row numbers
52−-- of rows, and the column numbers of cells, in addition to the data
53−-- in a 'Table'. The type itself does not enforce any guarantees about
54−-- the consistency of this data. Use 'toAnnTable' to produce an
55−-- 'AnnTable' from a pandoc 'Table'.
56−data AnnTable = AnnTable Attr Caption [ColSpec] AnnTableHead [AnnTableBody] AnnTableFoot
57− deriving (Eq, Ord, Read, Show, Typeable, Data, Generic)
58−
59−-- | An annotated table head, corresponding to 'TableHead' and the
60−-- HTML @\<thead\>@ element.
61−data AnnTableHead = AnnTableHead Attr [AnnHeaderRow]
62− deriving (Eq, Ord, Read, Show, Typeable, Data, Generic)
63−
64−-- | An annotated table body, with an intermediate head and body,
65−-- corresponding to 'TableBody' and the HTML @\<tbody\>@ element.
66−data AnnTableBody = AnnTableBody Attr RowHeadColumns [AnnHeaderRow] [AnnBodyRow]
67− deriving (Eq, Ord, Read, Show, Typeable, Data, Generic)
68−
69−-- | An annotated table foot, corresponding to 'TableFoot' and the
70−-- HTML @\<tfoot\>@ element.
71−data AnnTableFoot = AnnTableFoot Attr [AnnHeaderRow]
72− deriving (Eq, Ord, Read, Show, Typeable, Data, Generic)
73−
74−-- | An annotated header row, corresponding to 'Row' and the HTML
75−-- @\<tr\>@ element, and also recording the row number of the row. All
76−-- the cells in an 'AnnHeaderRow' are header (@\<th\>@) cells.
77−data AnnHeaderRow = AnnHeaderRow Attr RowNumber [AnnCell]
78− deriving (Eq, Ord, Read, Show, Typeable, Data, Generic)
79−
80−-- | An annotated body row, corresponding to 'Row' and the HTML
81−-- @\<tr\>@ element, and also recording its row number and separating
82−-- the row head cells from the row body cells.
83−data AnnBodyRow = AnnBodyRow Attr RowNumber AnnRowHead AnnRowBody
84− deriving (Eq, Ord, Read, Show, Typeable, Data, Generic)
85−
86−-- | The row number of a row. Note that rows are numbered continuously
87−-- from zero from the start of the table, so the first row in a table
88−-- body, for instance, may have a large 'RowNumber'.
89−newtype RowNumber = RowNumber Int
90− deriving (Eq, Ord, Read, Show, Typeable, Data, Generic, Num, Enum)
91−
92−-- | The head of a body row; the portion of the row lying in the stub
93−-- of the 'TableBody'. Its cells correspond to HTML @\<th\>@ cells.
94−type AnnRowHead = [AnnCell]
95−
96−-- | The body of a body row; the portion of the row lying after the
97−-- stub of the 'TableBody'. Its cells correspond to HTML @\<td\>@
98−-- cells.
99−type AnnRowBody = [AnnCell]
100−
101−-- | An annotated table cell, wrapping a 'Cell' with its 'ColNumber'
102−-- and the 'ColSpec' data for the columns that the cell spans.
103−data AnnCell = AnnCell (NonEmpty ColSpec) ColNumber Cell
104− deriving (Eq, Ord, Read, Show, Typeable, Data, Generic)
105−
106−-- | The column number of a cell, meaning the column number of the
107−-- first column that the cell spans, if the table were laid on a
108−-- grid. Columns are numbered starting from zero.
109−newtype ColNumber = ColNumber Int
110− deriving (Eq, Ord, Read, Show, Typeable, Data, Generic, Num, Enum)
111−
112−-- | Convert a 'Table' to an 'AnnTable'. This function also performs
113−-- the same normalization that the 'table' builder does (fixing
114−-- overlapping cells, cells that protrude out of their table section,
115−-- and so on). If the input table happens to satisfy the conditions
116−-- that 'table' guarantees, then the resulting 'AnnTable' will be
117−-- identical, save for the addition of the inferred table information.
118−toAnnTable
119− :: Attr
120− -> Caption
121− -> [ColSpec]
122− -> TableHead
123− -> [TableBody]
124− -> TableFoot
125− -> AnnTable
126−toAnnTable attr cap cs th tbs tf = AnnTable attr cap cs th' tbs' tf'
127− where
128− (th', tbs', tf') = fst $ evalRWS (annotateTable th tbs tf) (cs, length cs) 0
129−
130−-- | Internal monad for annotating a table, passing in the 'ColSpec'
131−-- data for the table, the grid width, and the current 'RowNumber' to
132−-- be referenced or updated.
133−type AnnM a = RWS ([ColSpec], Int) () RowNumber a
134−
135−incRowNumber :: AnnM RowNumber
136−incRowNumber = do
137− rn <- get
138− put $ rn + 1
139− return rn
140−
141−annotateTable
142− :: TableHead
143− -> [TableBody]
144− -> TableFoot
145− -> AnnM (AnnTableHead, [AnnTableBody], AnnTableFoot)
146−annotateTable th tbs tf = do
147− th' <- annotateTableHead th
148− tbs' <- traverse annotateTableBody tbs
149− tf' <- annotateTableFoot tf
150− return (th', tbs', tf')
151−
152−annotateTableHead :: TableHead -> AnnM AnnTableHead
153−annotateTableHead (TableHead attr rows) =
154− AnnTableHead attr <$> annotateHeaderSection rows
155−
156−annotateTableBody :: TableBody -> AnnM AnnTableBody
157−annotateTableBody (TableBody attr rhc th tb) = do
158− twidth <- asks snd
159− let rhc' = max 0 $ min (RowHeadColumns twidth) rhc
160− th' <- annotateHeaderSection th
161− tb' <- annotateBodySection rhc' tb
162− return $ AnnTableBody attr rhc' th' tb'
163−
164−annotateTableFoot :: TableFoot -> AnnM AnnTableFoot
165−annotateTableFoot (TableFoot attr rows) =
166− AnnTableFoot attr <$> annotateHeaderSection rows
167−
168−annotateHeaderSection :: [Row] -> AnnM [AnnHeaderRow]
169−annotateHeaderSection rows = do
170− colspec <- asks fst
171− let hangcolspec = (1, ) <$> colspec
172− annotateHeaderSection' hangcolspec id $ clipRows rows
173− where
174− annotateHeaderSection' oldHang acc (Row attr cells : rs) = do
175− let (_, newHang, cells', _) =
176− annotateRowSection 0 oldHang $ cells <> repeat emptyCell
177− n <- incRowNumber
178− let annRow = AnnHeaderRow attr n cells'
179− annotateHeaderSection' newHang (acc . (annRow :)) rs
180− annotateHeaderSection' _ acc [] = return $ acc []
181−
182−annotateBodySection :: RowHeadColumns -> [Row] -> AnnM [AnnBodyRow]
183−annotateBodySection (RowHeadColumns rhc) rows = do
184− colspec <- asks fst
185− let colspec' = (1, ) <$> colspec
186− let (stubspec, bodyspec) = splitAt rhc colspec'
187− normalizeBodySection' stubspec bodyspec id $ clipRows rows
188− where
189− normalizeBodySection' headHang bodyHang acc (Row attr cells : rs) = do
190− let (colnum, headHang', rowStub, cells') =
191− annotateRowSection 0 headHang $ cells <> repeat emptyCell
192− let (_, bodyHang', rowBody, _) = annotateRowSection colnum bodyHang cells'
193− n <- incRowNumber
194− let annRow = AnnBodyRow attr n rowStub rowBody
195− normalizeBodySection' headHang' bodyHang' (acc . (annRow :)) rs
196− normalizeBodySection' _ _ acc [] = return $ acc []
197−
198−-- | Lay out a section of a 'Table' row on a grid row, annotating the
199−-- cells with the 'ColSpec' data for the columns that they
200−-- span. Performs the same normalization as 'placeRowSection'.
201−annotateRowSection
202− :: ColNumber -- ^ The current column number
203− -> [(RowSpan, ColSpec)] -- ^ The overhang of the previous grid row,
204− -- with column data
205− -> [Cell] -- ^ The cells to annotate
206− -> (ColNumber, [(RowSpan, ColSpec)], [AnnCell], [Cell]) -- ^ The new
207− -- column
208− -- number,
209− -- overhang,
210− -- annotated
211− -- cells,
212− -- and
213− -- remaining
214− -- cells
215−annotateRowSection !colnum oldHang cells
216− -- If the grid has overhang at our position, try to re-lay in
217− -- the next position.
218− | (o, colspec) : os <- oldHang
219− , o > 1
220− = let (colnum', newHang, newCell, cells') =
221− annotateRowSection (colnum + 1) os cells
222− in (colnum', (o - 1, colspec) : newHang, newCell, cells')
223− -- Otherwise if there is any available width, place the cell and
224− -- continue.
225− | c : cells' <- cells
226− , (h, w) <- getDim c
227− , w' <- max 1 w
228− , (w'', cellHang@(chStart : chRest), oldHang') <- splitCellHang h w' oldHang
229− = let c' = setW w'' c
230− annCell = AnnCell (snd <$> chStart :| chRest) colnum c'
231− colnum' = colnum + ColNumber (getColSpan w'')
232− (colnum'', newHang, newCells, remainCells) =
233− annotateRowSection colnum' oldHang' cells'
234− in (colnum'', cellHang <> newHang, annCell : newCells, remainCells)
235− -- Otherwise there is no room in the section
236− | otherwise
237− = (colnum, [], [], cells)
238− where
239− getColSpan (ColSpan x) = x
240− getDim (Cell _ _ h w _) = (h, w)
241− setW w (Cell a b h _ c) = Cell a b h w c
242−
243−-- | In @'splitCellHang' rs cs coldata@, with @rs@ the height of a
244−-- cell that lies at the beginning of @coldata@, and @cs@ its width
245−-- (which is not assumed to fit in the available space), return the
246−-- actual width of the cell (what will fit in the available space),
247−-- the data for the columns that the cell spans (including updating
248−-- the overhang to equal @rs@), and the remaining column data.
249−splitCellHang
250− :: RowSpan
251− -> ColSpan
252− -> [(RowSpan, ColSpec)]
253− -> (ColSpan, [(RowSpan, ColSpec)], [(RowSpan, ColSpec)])
254−splitCellHang h n = go 0
255− where
256− go acc ((1, spec) : ls) | acc < n =
257− let (acc', hang, ls') = go (acc + 1) ls in (acc', (h, spec) : hang, ls')
258− go acc l = (acc, [], l)
259−
260−-- | Convert an 'AnnTable' to a 'Table'. This is the inverse of
261−-- 'toAnnTable' on well-formed tables (i.e. tables satisfying the
262−-- guarantees of 'table').
263−fromAnnTable
264− :: AnnTable -> (Attr, Caption, [ColSpec], TableHead, [TableBody], TableFoot)
265−fromAnnTable (AnnTable attr cap cs th tbs tf) = (attr, cap, cs, th', tbs', tf')
266− where
267− th' = fromAnnTableHead th
268− tbs' = map fromAnnTableBody tbs
269− tf' = fromAnnTableFoot tf
270−
271−fromAnnTableHead :: AnnTableHead -> TableHead
272−fromAnnTableHead (AnnTableHead attr rows) =
273− TableHead attr $ fromAnnHeaderRow <$> rows
274−
275−fromAnnTableBody :: AnnTableBody -> TableBody
276−fromAnnTableBody (AnnTableBody attr rhc th tb) =
277− TableBody attr rhc (fromAnnHeaderRow <$> th) (fromAnnBodyRow <$> tb)
278−
279−fromAnnTableFoot :: AnnTableFoot -> TableFoot
280−fromAnnTableFoot (AnnTableFoot attr rows) =
281− TableFoot attr $ fromAnnHeaderRow <$> rows
282−
283−fromAnnHeaderRow :: AnnHeaderRow -> Row
284−fromAnnHeaderRow (AnnHeaderRow attr _ cells) = Row attr $ fromAnnCell <$> cells
285−
286−fromAnnBodyRow :: AnnBodyRow -> Row
287−fromAnnBodyRow (AnnBodyRow attr _ rh rb) =
288− Row attr ((fromAnnCell <$> rh) <> (fromAnnCell <$> rb))
289−
290−fromAnnCell :: AnnCell -> Cell
291−fromAnnCell (AnnCell _ _ c) = c
test/Tests/Writers/Tables.hs → test/Tests/Writers/AnnotatedTable.hsrenamed+66−64
@@ -1,7 +1,7 @@
11{-# LANGUAGE NoImplicitPrelude #-}
22{-# LANGUAGE OverloadedStrings #-}
33{- |
4− Module : Tests.Writers.Tables
4+ Module : Tests.Writers.AnnotatedTable
55 Copyright : 2020 Christian Despres
66 License : GNU GPL, version 2 or above
77
@@ -11,7 +11,7 @@
1111
1212Tests for the table helper functions.
1313-}
14−module Tests.Writers.Tables
14+module Tests.Writers.AnnotatedTable
1515 ( tests
1616 )
1717where
@@ -37,19 +37,20 @@ import Test.Tasty.QuickCheck ( QuickCheckTests(..)
3737 )
3838import Text.Pandoc.Arbitrary ( )
3939import Text.Pandoc.Builder
40−import Text.Pandoc.Writers.Tables
40+import qualified Text.Pandoc.Writers.AnnotatedTable
41+ as Ann
4142
4243tests :: [TestTree]
43−tests = [testGroup "toAnnTable" $ testAnnTable <> annTableProps]
44+tests = [testGroup "toTable" $ testAnnTable <> annTableProps]
4445
45−getSpec :: AnnCell -> [ColSpec]
46−getSpec (AnnCell colspec _ _) = F.toList colspec
46+getSpec :: Ann.Cell -> [ColSpec]
47+getSpec (Ann.Cell colspec _ _) = F.toList colspec
4748
48−catHeaderSpec :: AnnHeaderRow -> [ColSpec]
49−catHeaderSpec (AnnHeaderRow _ _ x) = concatMap getSpec x
49+catHeaderSpec :: Ann.HeaderRow -> [ColSpec]
50+catHeaderSpec (Ann.HeaderRow _ _ x) = concatMap getSpec x
5051
51−catBodySpec :: AnnBodyRow -> [ColSpec]
52−catBodySpec (AnnBodyRow _ _ x y) = concatMap getSpec x <> concatMap getSpec y
52+catBodySpec :: Ann.BodyRow -> [ColSpec]
53+catBodySpec (Ann.BodyRow _ _ x y) = concatMap getSpec x <> concatMap getSpec y
5354
5455-- Test if the first list can be obtained from the second by deleting
5556-- elements from it.
@@ -78,21 +79,21 @@ testAnnTable =
7879 [[], [cl "e" 5 1, cl "f" (-7) 0]]
7980 [[cl "g" 4 3, cl "h" 4 3], [], [emptyCell]]
8081 initialTB2 = tb 2 [] [[cl "i" 4 3, cl "j" 4 3]]
81− generated = toAnnTable nullAttr
82− emptyCaption
83− spec
84− (th initialHeads)
85− [initialTB1, initialTB2]
86− (tf initialHeads)
82+ generated = Ann.toTable nullAttr
83+ emptyCaption
84+ spec
85+ (th initialHeads)
86+ [initialTB1, initialTB2]
87+ (tf initialHeads)
8788
8889 acl al n a h w =
89− AnnCell (NonEmpty.fromList al) n $ Cell (a, [], []) AlignDefault h w []
90+ Ann.Cell (NonEmpty.fromList al) n $ Cell (a, [], []) AlignDefault h w []
9091 emptyAnnCell al n = acl al n "" 1 1
91− ahrw = AnnHeaderRow nullAttr
92− abrw = AnnBodyRow nullAttr
93− ath = AnnTableHead nullAttr
94− atb = AnnTableBody nullAttr
95− atf = AnnTableFoot nullAttr
92+ ahrw = Ann.HeaderRow nullAttr
93+ abrw = Ann.BodyRow nullAttr
94+ ath = Ann.TableHead nullAttr
95+ atb = Ann.TableBody nullAttr
96+ atf = Ann.TableFoot nullAttr
9697
9798 finalTH = ath
9899 [ ahrw 0 [acl [spec1] 0 "a" 1 1, acl [spec2, spec3] 1 "b" 2 2]
@@ -118,7 +119,7 @@ testAnnTable =
118119 , ahrw 9 [acl [spec1] 0 "c" 1 1]
119120 ]
120121 expected =
121− AnnTable nullAttr emptyCaption spec finalTH [finalTB1, finalTB2] finalTF
122+ Ann.Table nullAttr emptyCaption spec finalTH [finalTB1, finalTB2] finalTF
122123
123124withColSpec :: Testable prop => ([ColSpec] -> prop) -> Property
124125withColSpec = forAll arbColSpec
@@ -134,49 +135,48 @@ withColSpec = forAll arbColSpec
134135annTableProps :: [TestTree]
135136annTableProps =
136137 localOption (QuickCheckTests 50)
137− <$> [ testProperty "normalizes like the table builder" propBuilderAnnTable
138− , testProperty "has valid final cell columns" propColNumber
139− , testProperty "has valid first row column data" propFirstRowCols
140− , testProperty "has valid all row column data" propColSubsets
141− , testProperty "has valid cell column data lengths"
142− propCellColLengths
138+ <$> [ testProperty "normalizes like the table builder" propBuilderAnnTable
139+ , testProperty "has valid final cell columns" propColNumber
140+ , testProperty "has valid first row column data" propFirstRowCols
141+ , testProperty "has valid all row column data" propColSubsets
142+ , testProperty "has valid cell column data lengths" propCellColLengths
143143 ]
144144
145−-- The property that toAnnTable will normalize a table identically to
146−-- the table builder. This should mean that toAnnTable is at least as
145+-- The property that Ann.toTable will normalize a table identically to
146+-- the table builder. This should mean that Ann.toTable is at least as
147147-- rigorous as Builder.table in that respect without repeating those
148148-- tests here (see the pandoc-types Table tests for examples).
149149propBuilderAnnTable :: TableHead -> [TableBody] -> TableFoot -> Property
150150propBuilderAnnTable th tbs tf = withColSpec $ \cs ->
151151 convertTable (table emptyCaption cs th tbs tf)
152− === convertAnnTable (toAnnTable nullAttr emptyCaption cs th tbs tf)
152+ === convertAnnTable (Ann.toTable nullAttr emptyCaption cs th tbs tf)
153153 where
154154 convertTable blks = case toList blks of
155155 [Table _ _ colspec a b c] -> Right (colspec, a, b, c)
156156 x -> Left x
157− convertAnnTable x = case fromAnnTable x of
157+ convertAnnTable x = case Ann.fromTable x of
158158 (_, _, colspec, a, b, c) -> Right (colspec, a, b, c)
159159
160−-- The property of toAnnTable that if the last cell in the first row
160+-- The property of Ann.toTable that if the last cell in the first row
161161-- of a table section has ColSpan w and ColNumber n, then w + n is the
162162-- width of the table.
163163propColNumber :: TableHead -> [TableBody] -> TableFoot -> Property
164164propColNumber th tbs tf = withColSpec $ \cs ->
165165 let twidth = length cs
166− AnnTable _ _ _ ath atbs atf =
167− toAnnTable nullAttr emptyCaption cs th tbs tf
166+ Ann.Table _ _ _ ath atbs atf =
167+ Ann.toTable nullAttr emptyCaption cs th tbs tf
168168 in conjoin
169169 $ [colNumTH twidth ath]
170170 <> (colNumTB twidth <$> atbs)
171171 <> [colNumTF twidth atf]
172172 where
173− colNumTH n (AnnTableHead _ rs) = firstly (isHeaderValid n) rs
174− colNumTB n (AnnTableBody _ _ rs ts) =
173+ colNumTH n (Ann.TableHead _ rs) = firstly (isHeaderValid n) rs
174+ colNumTB n (Ann.TableBody _ _ rs ts) =
175175 firstly (isHeaderValid n) rs && firstly (isBodyValid n) ts
176− colNumTF n (AnnTableFoot _ rs) = firstly (isHeaderValid n) rs
176+ colNumTF n (Ann.TableFoot _ rs) = firstly (isHeaderValid n) rs
177177
178− isHeaderValid n (AnnHeaderRow _ _ x) = isSegmentValid n x
179− isBodyValid n (AnnBodyRow _ _ _ x) = isSegmentValid n x
178+ isHeaderValid n (Ann.HeaderRow _ _ x) = isSegmentValid n x
179+ isBodyValid n (Ann.BodyRow _ _ _ x) = isSegmentValid n x
180180
181181 firstly f (x : _) = f x
182182 firstly _ [] = True
@@ -184,17 +184,19 @@ propColNumber th tbs tf = withColSpec $ \cs ->
184184 lastly f (_ : xs) = lastly f xs
185185 lastly _ [] = True
186186
187− isSegmentValid twidth cs = flip lastly cs
188− $ \(AnnCell _ (ColNumber n) (Cell _ _ _ (ColSpan w) _)) -> n + w == twidth
187+ isSegmentValid twidth cs =
188+ flip lastly cs
189+ $ \(Ann.Cell _ (Ann.ColNumber n) (Cell _ _ _ (ColSpan w) _)) ->
190+ n + w == twidth
189191
190−-- The property of an AnnTable from toAnnTable that if the NonEmpty
192+-- The property of an Ann.Table from Ann.toTable that if the NonEmpty
191193-- ColSpec data of the cells in the first row of a table section are
192194-- concatenated, the result should equal the [ColSpec] of the entire
193195-- table.
194196propFirstRowCols :: TableHead -> [TableBody] -> TableFoot -> Property
195197propFirstRowCols th tbs tf = withColSpec $ \cs ->
196− let AnnTable _ _ _ ath atbs atf =
197− toAnnTable nullAttr emptyCaption cs th tbs tf
198+ let Ann.Table _ _ _ ath atbs atf =
199+ Ann.toTable nullAttr emptyCaption cs th tbs tf
198200 in conjoin
199201 $ [firstRowTH cs ath]
200202 <> (firstRowTB cs <$> atbs)
@@ -206,47 +208,47 @@ propFirstRowCols th tbs tf = withColSpec $ \cs ->
206208 firstHeaderValid cs = firstly $ \r -> cs == catHeaderSpec r
207209 firstBodyValid cs = firstly $ \r -> cs == catBodySpec r
208210
209− firstRowTH cs (AnnTableHead _ rs) = firstHeaderValid cs rs
210− firstRowTB cs (AnnTableBody _ _ rs ts) =
211+ firstRowTH cs (Ann.TableHead _ rs) = firstHeaderValid cs rs
212+ firstRowTB cs (Ann.TableBody _ _ rs ts) =
211213 firstHeaderValid cs rs && firstBodyValid cs ts
212− firstRowTF cs (AnnTableFoot _ rs) = firstHeaderValid cs rs
214+ firstRowTF cs (Ann.TableFoot _ rs) = firstHeaderValid cs rs
213215
214−-- The property that in any row in an AnnTable from toAnnTable, the
216+-- The property that in any row in an Ann.Table from Ann.toTable, the
215217-- NonEmpty ColSpec annotations on cells, when concatenated, form a
216218-- subset (really sublist) of the [ColSpec] of the entire table.
217219propColSubsets :: TableHead -> [TableBody] -> TableFoot -> Property
218220propColSubsets th tbs tf = withColSpec $ \cs ->
219− let AnnTable _ _ _ ath atbs atf =
220− toAnnTable nullAttr emptyCaption cs th tbs tf
221+ let Ann.Table _ _ _ ath atbs atf =
222+ Ann.toTable nullAttr emptyCaption cs th tbs tf
221223 in conjoin
222224 $ subsetTH cs ath
223225 <> concatMap (subsetTB cs) atbs
224226 <> subsetTF cs atf
225227 where
226− subsetTH cs (AnnTableHead _ rs) = map (subsetHeader cs) rs
227− subsetTB cs (AnnTableBody _ _ rs ts) =
228+ subsetTH cs (Ann.TableHead _ rs) = map (subsetHeader cs) rs
229+ subsetTB cs (Ann.TableBody _ _ rs ts) =
228230 map (subsetHeader cs) rs <> map (subsetBody cs) ts
229− subsetTF cs (AnnTableFoot _ rs) = map (subsetHeader cs) rs
231+ subsetTF cs (Ann.TableFoot _ rs) = map (subsetHeader cs) rs
230232
231233 subsetHeader cs r = catHeaderSpec r `isSubsetOf` cs
232234 subsetBody cs r = catBodySpec r `isSubsetOf` cs
233235
234−-- The property that in any cell in an AnnTable from toAnnTable, the
236+-- The property that in any cell in an Ann.Table from Ann.toTable, the
235237-- NonEmpty ColSpec annotation on a cell is equal in length to its
236238-- ColSpan.
237239propCellColLengths :: TableHead -> [TableBody] -> TableFoot -> Property
238240propCellColLengths th tbs tf = withColSpec $ \cs ->
239− let AnnTable _ _ _ ath atbs atf =
240− toAnnTable nullAttr emptyCaption cs th tbs tf
241+ let Ann.Table _ _ _ ath atbs atf =
242+ Ann.toTable nullAttr emptyCaption cs th tbs tf
241243 in conjoin $ cellColTH ath <> concatMap cellColTB atbs <> cellColTF atf
242244 where
243− cellColTH (AnnTableHead _ rs) = concatMap cellColHeader rs
244− cellColTB (AnnTableBody _ _ rs ts) =
245+ cellColTH (Ann.TableHead _ rs) = concatMap cellColHeader rs
246+ cellColTB (Ann.TableBody _ _ rs ts) =
245247 concatMap cellColHeader rs <> concatMap cellColBody ts
246− cellColTF (AnnTableFoot _ rs) = concatMap cellColHeader rs
248+ cellColTF (Ann.TableFoot _ rs) = concatMap cellColHeader rs
247249
248− cellColHeader (AnnHeaderRow _ _ x) = fmap validLength x
249− cellColBody (AnnBodyRow _ _ x y) = fmap validLength x <> fmap validLength y
250+ cellColHeader (Ann.HeaderRow _ _ x) = fmap validLength x
251+ cellColBody (Ann.BodyRow _ _ x y) = fmap validLength x <> fmap validLength y
250252
251− validLength (AnnCell colspec _ (Cell _ _ _ (ColSpan w) _)) =
253+ validLength (Ann.Cell colspec _ (Cell _ _ _ (ColSpan w) _)) =
252254 length colspec == w
test/test-pandoc.hs+2−2
@@ -44,7 +44,7 @@ import qualified Tests.Writers.Org
4444import qualified Tests.Writers.Plain
4545import qualified Tests.Writers.Powerpoint
4646import qualified Tests.Writers.RST
47−import qualified Tests.Writers.Tables
47+import qualified Tests.Writers.AnnotatedTable
4848import qualified Tests.Writers.TEI
4949import Tests.Helpers (findPandoc)
5050import Text.Pandoc.Shared (inDirectory)
@@ -73,7 +73,7 @@ tests pandocPath = testGroup "pandoc tests"
7373 , testGroup "FB2" Tests.Writers.FB2.tests
7474 , testGroup "PowerPoint" Tests.Writers.Powerpoint.tests
7575 , testGroup "Ms" Tests.Writers.Ms.tests
76− , testGroup "Tables" Tests.Writers.Tables.tests
76+ , testGroup "AnnotatedTable" Tests.Writers.AnnotatedTable.tests
7777 ]
7878 , testGroup "Readers"
7979 [ testGroup "LaTeX" Tests.Readers.LaTeX.tests