diff options
author | danse <f.occhipinti@gmail.com> | 2018-02-12 17:10:29 +0100 |
---|---|---|
committer | Jesse Rosenthal <jrosenthal@jhu.edu> | 2018-02-15 15:06:01 -0500 |
commit | e6ff7f79861d3088f8cba2b22d86d9f75db73f6a (patch) | |
tree | 885440592bae86a5d5178ba650a471f8dc2acdb3 /src | |
parent | 82a0ceaf18e589e8916fbd70e0b13e5945bcc99a (diff) | |
download | pandoc-e6ff7f79861d3088f8cba2b22d86d9f75db73f6a.tar.gz |
Docx reader: Pick table width from the longest row or header
This change is intended to preserve as much of the table content as
possible
Closes #4360
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/Readers/Docx.hs | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/Text/Pandoc/Readers/Docx.hs b/src/Text/Pandoc/Readers/Docx.hs index c24c43901..098759a61 100644 --- a/src/Text/Pandoc/Readers/Docx.hs +++ b/src/Text/Pandoc/Readers/Docx.hs @@ -642,7 +642,7 @@ bodyPartToBlocks (ListItem pPr _ _ _ parparts) = bodyPartToBlocks $ Paragraph pPr' parparts bodyPartToBlocks (Tbl _ _ _ []) = return $ para mempty -bodyPartToBlocks (Tbl cap _ look (r:rs)) = do +bodyPartToBlocks (Tbl cap _ look parts@(r:rs)) = do let caption = text cap (hdr, rows) = case firstRowFormatting look of True | null rs -> (Nothing, [r]) @@ -651,10 +651,14 @@ bodyPartToBlocks (Tbl cap _ look (r:rs)) = do cells <- mapM rowToBlocksList rows - let width = case cells of - r':_ -> length r' - -- shouldn't happen - [] -> 0 + let width = maybe 0 maximum $ nonEmpty $ map rowLength parts + -- Data.List.NonEmpty is not available with ghc 7.10 so we roll out + -- our own, see + -- https://github.com/jgm/pandoc/pull/4361#issuecomment-365416155 + nonEmpty [] = Nothing + nonEmpty l = Just l + rowLength :: Row -> Int + rowLength (Row c) = length c hdrCells <- case hdr of Just r' -> rowToBlocksList r' |