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.
This commit is contained in:
Jesse Rosenthal
2016-12-08 07:01:01 -05:00
parent a09f60180f
commit 8ced8cbc6e
4 changed files with 11 additions and 1 deletions
+2 -1
View File
@@ -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'
+4
View File
@@ -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"
Binary file not shown.
+5
View File
@@ -0,0 +1,5 @@
[Table [] [AlignDefault,AlignDefault,AlignDefault] [0.0,0.0,0.0]
[]
[[[Plain [Str "One"]]
,[Plain [Str "Row"]]
,[Plain [Str "Table"]]]]]