From 8ced8cbc6e03212f7a9bd871d74ba0e2622c6233 Mon Sep 17 00:00:00 2001 From: Jesse Rosenthal Date: Thu, 8 Dec 2016 06:57:38 -0500 Subject: 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. --- src/Text/Pandoc/Readers/Docx.hs | 3 ++- tests/Tests/Readers/Docx.hs | 4 ++++ tests/docx/table_one_row.docx | Bin 0 -> 25251 bytes tests/docx/table_one_row.native | 5 +++++ 4 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 tests/docx/table_one_row.docx create mode 100644 tests/docx/table_one_row.native diff --git a/src/Text/Pandoc/Readers/Docx.hs b/src/Text/Pandoc/Readers/Docx.hs index 9fe3a3fea..c8a09248a 100644 --- a/src/Text/Pandoc/Readers/Docx.hs +++ b/src/Text/Pandoc/Readers/Docx.hs @@ -568,7 +568,8 @@ bodyPartToBlocks (Tbl _ _ _ []) = bodyPartToBlocks (Tbl cap _ look (r:rs)) = do let caption = text cap (hdr, rows) = case firstRowFormatting look of - True -> (Just r, rs) + True | null rs -> (Nothing, [r]) + | otherwise -> (Just r, rs) False -> (Nothing, r:rs) hdrCells <- case hdr of Just r' -> rowToBlocksList r' diff --git a/tests/Tests/Readers/Docx.hs b/tests/Tests/Readers/Docx.hs index 2fe98b8ac..0d31eb629 100644 --- a/tests/Tests/Readers/Docx.hs +++ b/tests/Tests/Readers/Docx.hs @@ -241,6 +241,10 @@ tests = [ testGroup "inlines" "tables with lists in cells" "docx/table_with_list_cell.docx" "docx/table_with_list_cell.native" + , testCompare + "tables with one row" + "docx/table_one_row.docx" + "docx/table_one_row.native" , testCompare "code block" "docx/codeblock.docx" diff --git a/tests/docx/table_one_row.docx b/tests/docx/table_one_row.docx new file mode 100644 index 000000000..f7e0ebe43 Binary files /dev/null and b/tests/docx/table_one_row.docx differ diff --git a/tests/docx/table_one_row.native b/tests/docx/table_one_row.native new file mode 100644 index 000000000..bd1bf8145 --- /dev/null +++ b/tests/docx/table_one_row.native @@ -0,0 +1,5 @@ +[Table [] [AlignDefault,AlignDefault,AlignDefault] [0.0,0.0,0.0] + [] + [[[Plain [Str "One"]] + ,[Plain [Str "Row"]] + ,[Plain [Str "Table"]]]]] -- cgit v1.2.3