Docx reader: Ensure one-row tables don't have header.
Tables in MS Word are set by default to have special first-row
formatting, which pandoc uses to determine whether or not they have a
header. This means that one-row tables will, by default, have only a
header -- which we imagine is not what people want. This change
ensures that a one-row table is not understood to be a header only.
Note that this means that it is impossible to produce a header-only
table from docx, even though it is legal pandoc. But we believe that
in nearly all cases, it will be an accidental (and unwelcome) result
Closes #3285.
commit8ced8cbc6e03212f7a9bd871d74ba0e2622c6233
authorJesse Rosenthal <jrosenthal@jhu.edu>
dateThu 8 Dec 2016, 06:57 (10 years ago)
parenta09f601
src/Text/Pandoc/Readers/Docx.hs+2−1
@@ -568,7 +568,8 @@ bodyPartToBlocks (Tbl _ _ _ []) =
568568bodyPartToBlocks (Tbl cap _ look (r:rs)) = do
569569 let caption = text cap
570570 (hdr, rows) = case firstRowFormatting look of
571− True -> (Just r, rs)
571+ True | null rs -> (Nothing, [r])
572+ | otherwise -> (Just r, rs)
572573 False -> (Nothing, r:rs)
573574 hdrCells <- case hdr of
574575 Just r' -> rowToBlocksList r'
tests/Tests/Readers/Docx.hs+4
@@ -241,6 +241,10 @@ tests = [ testGroup "inlines"
241241 "tables with lists in cells"
242242 "docx/table_with_list_cell.docx"
243243 "docx/table_with_list_cell.native"
244+ , testCompare
245+ "tables with one row"
246+ "docx/table_one_row.docx"
247+ "docx/table_one_row.native"
244248 , testCompare
245249 "code block"
246250 "docx/codeblock.docx"
tests/docx/table_one_row.docxnew file
Binary file not shown.
tests/docx/table_one_row.nativenew file+5
@@ -0,0 +1,5 @@
1+[Table [] [AlignDefault,AlignDefault,AlignDefault] [0.0,0.0,0.0]
2+ []
3+ [[[Plain [Str "One"]]
4+ ,[Plain [Str "Row"]]
5+ ,[Plain [Str "Table"]]]]]