git.iko.soy/typeable/pandoc
on master help sign in
Docx reader: Empty header should be list of lists.

In the past, the docx reader wrote an empty header as an empty list. It should have the same width as a row (and be filled with empty cells). (Note that I've reordered the code here slightly to get rid of a call to `head`. It wasn't unsafe because it tested for null, but it was a bit of a smell.)

commit60004cd518f0fc72d45633dbb552f153bc3bfe96 authorJesse Rosenthal <jrosenthal@jhu.edu> dateTue 13 Dec 2016, 06:58 (10 years ago) parent7caaa5b
3 files changed+18−12
src/Text/Pandoc/Readers/Docx.hs+11−9 tests/docx/table_one_row.native+3−1 tests/docx/tables.native+4−2
src/Text/Pandoc/Readers/Docx.hs+11−9
@@ -571,23 +571,25 @@ bodyPartToBlocks (Tbl cap _ look (r:rs)) = do
571571 True | null rs -> (Nothing, [r])
572572 | otherwise -> (Just r, rs)
573573 False -> (Nothing, r:rs)
574+
575+ cells <- mapM rowToBlocksList rows
576+
577+ let width = case cells of
578+ r':_ -> length r'
579+ -- shouldn't happen
580+ [] -> 0
581+
574582 hdrCells <- case hdr of
575583 Just r' -> rowToBlocksList r'
576− Nothing -> return []
577−
578− cells <- mapM rowToBlocksList rows
584+ Nothing -> return $ replicate width mempty
579585
580− let size = case null hdrCells of
581− True -> length $ head cells
582− False -> length $ hdrCells
583− --
584586 -- The two following variables (horizontal column alignment and
585587 -- relative column widths) go to the default at the
586588 -- moment. Width information is in the TblGrid field of the Tbl,
587589 -- so should be possible. Alignment might be more difficult,
588590 -- since there doesn't seem to be a column entity in docx.
589− alignments = replicate size AlignDefault
590− widths = replicate size 0 :: [Double]
591+ let alignments = replicate width AlignDefault
592+ widths = replicate width 0 :: [Double]
591593
592594 return $ table caption (zip alignments widths) hdrCells cells
593595bodyPartToBlocks (OMathPara e) = do
tests/docx/table_one_row.native+3−1
@@ -1,5 +1,7 @@
11[Table [] [AlignDefault,AlignDefault,AlignDefault] [0.0,0.0,0.0]
2− []
2+ [[]
3+ ,[]
4+ ,[]]
35 [[[Plain [Str "One"]]
46 ,[Plain [Str "Row"]]
57 ,[Plain [Str "Table"]]]]]
tests/docx/tables.native+4−2
@@ -17,13 +17,15 @@
1717 ,[Plain [Str "High"]]
1818 ,[Plain [Str "Tacky",Space,Str "uniform"]]]]
1919,Table [] [AlignDefault,AlignDefault] [0.0,0.0]
20− []
20+ [[]
21+ ,[]]
2122 [[[Plain [Str "Sinple"]]
2223 ,[Plain [Str "Table"]]]
2324 ,[[Plain [Str "Without"]]
2425 ,[Plain [Str "Header"]]]]
2526,Table [] [AlignDefault,AlignDefault] [0.0,0.0]
26− []
27+ [[]
28+ ,[]]
2729 [[[Para [Str "Simple"]
2830 ,Para [Str "Multiparagraph"]]
2931 ,[Para [Str "Table"]