Docx reader: handle case where non-header rows come before header rows.

In this case we'll treat them all as the header in order to
preserve the order.

Added test case for #11833.
This commit is contained in:
John MacFarlane
2026-08-27 14:51:13 -07:00
parent 75982322cf
commit 2f103b3c76
4 changed files with 52 additions and 5 deletions
+1
View File
@@ -226,6 +226,7 @@ extra-source-files:
test/command/9603.docx
test/command/11113.docx
test/command/11689.docx
test/command/11833.docx
test/command/biblio.bib
test/command/averroes.bib
test/command/A.txt
+11 -5
View File
@@ -629,14 +629,20 @@ rowsToRows rows = do
return (fmap (Pandoc.Row nullAttr) cells)
splitHeaderRows :: Bool -> [Docx.Row] -> ([Docx.Row], [Docx.Row])
splitHeaderRows hasFirstRowFormatting rs = bimap reverse reverse $ fst
$ if hasFirstRowFormatting
then L.foldl' f ((take 1 rs, []), True) (drop 1 rs)
else L.foldl' f (([], []), False) rs
splitHeaderRows hasFirstRowFormatting rs =
bimap reverse reverse $ fst $
if hasFirstRowFormatting
then L.foldl' f ((take 1 rs, []), True) (drop 1 rs)
else L.foldl' f (([], []), False) rs
where
f ((headerRows, bodyRows), previousRowWasHeader) r@(Docx.Row h cs)
| h == HasTblHeader || (previousRowWasHeader && any isContinuationCell cs)
= ((r : headerRows, bodyRows), True)
= if null headerRows
-- in rare cases we have non-header rows before a header row.
-- in this case it's important to retain the order of rows,
-- so we promote the preceeding body rows to header rows:
then ((r : bodyRows, []), True)
else ((r : headerRows, bodyRows), True)
| otherwise
= ((headerRows, r : bodyRows), False)
Binary file not shown.
+40
View File
@@ -0,0 +1,40 @@
```
% pandoc command/11833.docx -t html
^D
<table>
<colgroup>
<col style="width: 39%" />
<col style="width: 9%" />
<col style="width: 35%" />
<col style="width: 15%" />
</colgroup>
<thead>
<tr>
<th>VENDOR SERVICE MODEL</th>
<th></th>
<th></th>
<th></th>
</tr>
<tr>
<th>Question</th>
<th>Response</th>
<th>Comments</th>
<th>Evidence Reference</th>
</tr>
</thead>
<tbody>
<tr>
<td>question1</td>
<td>response1</td>
<td>comment1</td>
<td>evidence1</td>
</tr>
<tr>
<td>question 2</td>
<td>response 2</td>
<td>comment 2</td>
<td>evidence 2</td>
</tr>
</tbody>
</table>
```