@@ -910,7 +910,7 @@ tableToHtml :: PandocMonad m
910910 => WriterOptions
911911 -> Ann.Table
912912 -> StateT WriterState m Html
913−tableToHtml opts (Ann.Table 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
@@ -921,11 +921,11 @@ tableToHtml opts (Ann.Table attr caption colspecs thead tbodies _tfoot) = do
921921 coltags <- colSpecListToHtml opts colspecs
922922 head' <- tableHeadToHtml opts thead
923923 body' <- mconcat <$> mapM (tableBodyToHtml opts) tbodies
924+ foot' <- tableFootToHtml opts tfoot
924925 let (ident,classes,kvs) = attr
925926 -- When widths of columns are < 100%, we need to set width for the whole
926927 -- table, or some browsers give us skinny columns with lots of space
927928 -- between:
928− -- let totalWidth = sum widths
929929 let colWidth = \case
930930 ColWidth d -> d
931931 ColWidthDefault -> 0
@@ -936,8 +936,14 @@ tableToHtml opts (Ann.Table attr caption colspecs thead tbodies _tfoot) = do
936936 T.pack (show (round (totalWidth * 100) :: Int))
937937 <> "%;"):kvs)
938938 _ -> attr
939− addAttrs opts attr' $ H.table $
940− nl opts *> captionDoc *> coltags *> head' *> body' *> nl opts
939+ addAttrs opts attr' $ H.table $ do
940+ nl opts
941+ captionDoc
942+ coltags
943+ head'
944+ body'
945+ foot'
946+ nl opts
941947
942948tableBodyToHtml :: PandocMonad m
943949 => WriterOptions
@@ -951,36 +957,57 @@ tableHeadToHtml :: PandocMonad m
951957 -> Ann.TableHead
952958 -> StateT WriterState m Html
953959tableHeadToHtml opts (Ann.TableHead attr rows) =
960+ tablePartToHtml opts Thead attr rows
961+
962+tableFootToHtml :: PandocMonad m
963+ => WriterOptions
964+ -> Ann.TableFoot
965+ -> StateT WriterState m Html
966+tableFootToHtml opts (Ann.TableFoot attr rows) =
967+ tablePartToHtml opts Tfoot attr rows
968+
969+tablePartToHtml :: PandocMonad m
970+ => WriterOptions
971+ -> TablePart
972+ -> Attr
973+ -> [Ann.HeaderRow]
974+ -> StateT WriterState m Html
975+tablePartToHtml opts tblpart attr rows =
954976 if null rows || all isEmptyRow rows
955977 then return mempty
956978 else do
957− contents <- headerRowsToHtml opts rows
958− headElement <- addAttrs opts attr $ H.thead contents
979+ let tag' = case tblpart of
980+ Thead -> H.thead
981+ Tfoot -> H.tfoot
982+ Tbody -> H.tbody -- this would be unexpected
983+ contents <- headerRowsToHtml opts tblpart rows
984+ tablePartElement <- addAttrs opts attr $ tag' contents
959985 return $ do
960− headElement
986+ tablePartElement
961987 nl opts
962988 where
963989 isEmptyRow (Ann.HeaderRow _attr _rownum cells) = all isEmptyCell cells
964990 isEmptyCell (Ann.Cell _colspecs _colnum cell) =
965991 cell == Cell nullAttr AlignDefault (RowSpan 1) (ColSpan 1) []
966992
967−
968−data RowType = HeaderRow | FooterRow | BodyRow
993+-- | The part of a table; header, footer, or body.
994+data TablePart = Thead | Tfoot | Tbody
969995 deriving (Eq)
970996
971997data CellType = HeaderCell | BodyCell
972998
973−data TableRow = TableRow RowType Attr Ann.RowNumber Ann.RowHead Ann.RowBody
999+data TableRow = TableRow TablePart Attr Ann.RowNumber Ann.RowHead Ann.RowBody
9741000
9751001headerRowsToHtml :: PandocMonad m
976− => WriterOptions
977− -> [Ann.HeaderRow]
978− -> StateT WriterState m Html
979−headerRowsToHtml opts =
1002+ => WriterOptions
1003+ -> TablePart
1004+ -> [Ann.HeaderRow]
1005+ -> StateT WriterState m Html
1006+headerRowsToHtml opts tablepart =
9801007 rowListToHtml opts . map toTableRow
9811008 where
9821009 toTableRow (Ann.HeaderRow attr rownum rowbody) =
983− TableRow HeaderRow attr rownum [] rowbody
1010+ TableRow tablepart attr rownum [] rowbody
9841011
9851012bodyRowsToHtml :: PandocMonad m
9861013 => WriterOptions
@@ -990,7 +1017,7 @@ bodyRowsToHtml opts =
9901017 rowListToHtml opts . zipWith toTableRow [1..]
9911018 where
9921019 toTableRow rownum (Ann.BodyRow attr _rownum rowhead rowbody) =
993− TableRow BodyRow attr rownum rowhead rowbody
1020+ TableRow Tbody attr rownum rowhead rowbody
9941021
9951022
9961023rowListToHtml :: PandocMonad m
@@ -1034,14 +1061,14 @@ tableRowToHtml :: PandocMonad m
10341061 => WriterOptions
10351062 -> TableRow
10361063 -> StateT WriterState m Html
1037−tableRowToHtml opts (TableRow rowtype _attr rownum rowhead rowbody) = do
1064+tableRowToHtml opts (TableRow tblpart _attr rownum rowhead rowbody) = do
10381065 let rowclass = A.class_ $ case rownum of
1039− Ann.RowNumber x | x `rem` 2 == 1 -> "odd"
1040− _ | rowtype /= HeaderRow -> "even"
1041− _ -> "header"
1042− let celltype = case rowtype of
1043− HeaderRow -> HeaderCell
1044− _ -> BodyCell
1066+ Ann.RowNumber x | x `rem` 2 == 1 -> "odd"
1067+ _ | tblpart /= Thead -> "even"
1068+ _ -> "header"
1069+ let celltype = case tblpart of
1070+ Thead -> HeaderCell
1071+ _ -> BodyCell
10451072 head' <- mapM (cellToHtml opts HeaderCell) rowhead
10461073 body <- mapM (cellToHtml opts celltype) rowbody
10471074 return $ do