mirror of
https://github.com/jgm/pandoc.git
synced 2026-08-28 09:10:48 +08:00
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:
@@ -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
|
||||
|
||||
@@ -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.
@@ -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>
|
||||
```
|
||||
Reference in New Issue
Block a user