aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2025-02-19 10:02:25 -0800
committerJohn MacFarlane <[email protected]>2025-02-19 10:02:50 -0800
commit3caf2b1e3aaa09fbe1374f99dd287590bc75bcb7 (patch)
tree0da29d0feaac1118e9352fecf09c41f8320e8447 /src
parent3528f405b1e7085f32fc36fb3f8ffbb6a6fb5767 (diff)
Revert "Docx reader and writer: support row heads."
This reverts commit cbe67b9602a736976ef6921aefbbc60d51c6755a. Word sets `w:firstColumn="1"` by default for tables. You have to find the Table Design tab and explicitly uncheck "First Column" to make this go away. In most cases, I don't think writers intend to designate the first column as a row head, so this commit is going to produce unexpected results. In addition, because of the table normalization done by pandoc-type's `tableWith`, any table containing a colspanned cell in the left-hand column will get broken if the first column is designated a row head. For these reasons it seems best to revert this change, which was made in response to #9495. Closes #10627.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Readers/Docx.hs4
-rw-r--r--src/Text/Pandoc/Readers/Docx/Parse.hs24
-rw-r--r--src/Text/Pandoc/Writers/Docx/Table.hs8
3 files changed, 10 insertions, 26 deletions
diff --git a/src/Text/Pandoc/Readers/Docx.hs b/src/Text/Pandoc/Readers/Docx.hs
index cafd4cbe6..74c7c9445 100644
--- a/src/Text/Pandoc/Readers/Docx.hs
+++ b/src/Text/Pandoc/Readers/Docx.hs
@@ -816,8 +816,6 @@ bodyPartToBlocks (Tbl mbsty cap grid look parts) = do
cap' = caption shortCaption fullCaption
(hdr, rows) = splitHeaderRows (firstRowFormatting look) parts
- let rowHeadCols = if firstColumnFormatting look then 1 else 0
-
let width = maybe 0 maximum $ nonEmpty $ map rowLength parts
rowLength :: Docx.Row -> Int
rowLength (Docx.Row _ c) = sum (fmap (\(Docx.Cell _ gridSpan _ _) -> fromIntegral gridSpan) c)
@@ -841,7 +839,7 @@ bodyPartToBlocks (Tbl mbsty cap grid look parts) = do
return $ tableWith attr cap'
(zip alignments widths)
(TableHead nullAttr headerCells)
- [TableBody nullAttr (RowHeadColumns rowHeadCols) [] bodyCells]
+ [TableBody nullAttr 0 [] bodyCells]
(TableFoot nullAttr [])
bodyPartToBlocks HRule = pure Pandoc.horizontalRule
diff --git a/src/Text/Pandoc/Readers/Docx/Parse.hs b/src/Text/Pandoc/Readers/Docx/Parse.hs
index 43adf7930..99ffcaf09 100644
--- a/src/Text/Pandoc/Readers/Docx/Parse.hs
+++ b/src/Text/Pandoc/Readers/Docx/Parse.hs
@@ -294,15 +294,11 @@ data BodyPart = Paragraph ParagraphStyle [ParPart]
type TblGrid = [Integer]
-data TblLook = TblLook { firstRowFormatting ::Bool
- , firstColumnFormatting :: Bool
- }
+newtype TblLook = TblLook {firstRowFormatting::Bool}
deriving Show
defaultTblLook :: TblLook
-defaultTblLook = TblLook{ firstRowFormatting = False
- , firstColumnFormatting = False
- }
+defaultTblLook = TblLook{firstRowFormatting = False}
data Row = Row TblHeader [Cell] deriving Show
@@ -695,25 +691,17 @@ elemToTblGrid _ _ = throwError WrongElem
elemToTblLook :: NameSpaces -> Element -> D TblLook
elemToTblLook ns element | isElem ns "w" "tblLook" element =
- let val = findAttrByName ns "w" "val" element
+ let firstRow = findAttrByName ns "w" "firstRow" element
+ val = findAttrByName ns "w" "val" element
firstRowFmt =
- case findAttrByName ns "w" "firstRow" element of
+ case firstRow of
Just "1" -> True
Just _ -> False
Nothing -> case val of
Just bitMask -> testBitMask bitMask 0x020
Nothing -> False
- firstColFmt =
- case findAttrByName ns "w" "firstColumn" element of
- Just "1" -> True
- Just _ -> False
- Nothing -> case val of
- Just bitMask -> testBitMask bitMask 0x080
- Nothing -> False
in
- return TblLook{ firstRowFormatting = firstRowFmt
- , firstColumnFormatting = firstColFmt
- }
+ return TblLook{firstRowFormatting = firstRowFmt}
elemToTblLook _ _ = throwError WrongElem
elemToRow :: NameSpaces -> Element -> D Row
diff --git a/src/Text/Pandoc/Writers/Docx/Table.hs b/src/Text/Pandoc/Writers/Docx/Table.hs
index 6dcb3f027..0caab7cd5 100644
--- a/src/Text/Pandoc/Writers/Docx/Table.hs
+++ b/src/Text/Pandoc/Writers/Docx/Table.hs
@@ -63,7 +63,6 @@ import Text.Pandoc.XML.Light.Types
import qualified Data.Text as T
import qualified Text.Pandoc.Translations as Term
import qualified Text.Pandoc.Writers.GridTable as Grid
-import Data.Bits ((.|.))
tableToOpenXML :: PandocMonad m
=> WriterOptions
@@ -72,7 +71,7 @@ tableToOpenXML :: PandocMonad m
-> WS m [Content]
tableToOpenXML opts blocksToOpenXML gridTable = do
setFirstPara
- let (Grid.Table (ident,_,tableAttr) caption colspecs rowheads thead tbodies tfoot) =
+ let (Grid.Table (ident,_,tableAttr) caption colspecs _rowheads thead tbodies tfoot) =
gridTable
let (Caption _maybeShortCaption captionBlocks) = caption
tablenum <- gets stNextTableNum
@@ -107,8 +106,7 @@ tableToOpenXML opts blocksToOpenXML gridTable = do
-- 0×0100 Apply last column conditional formatting
-- 0×0200 Do not apply row banding conditional formatting
-- 0×0400 Do not apply column banding conditional formattin
- let tblLookVal = (if hasHeader then (0x20 :: Int) else 0) .|.
- (if rowheads > 0 then (0x80 :: Int) else 0)
+ let tblLookVal = if hasHeader then (0x20 :: Int) else 0
let (gridCols, tblWattr) = tableLayout (elems colspecs)
listLevel <- asks envListLevel
let tblStyle = fromMaybe "Table" (lookup "custom-style" tableAttr)
@@ -124,7 +122,7 @@ tableToOpenXML opts blocksToOpenXML gridTable = do
[ mknode "w:tblLayout" [("w:type", "fixed")] () | hasWidths ] ++
[ mknode "w:tblLook" [("w:firstRow",if hasHeader then "1" else "0")
,("w:lastRow",if hasFooter then "1" else "0")
- ,("w:firstColumn",if rowheads > 0 then "1" else "0")
+ ,("w:firstColumn","0")
,("w:lastColumn","0")
,("w:noHBand","0")
,("w:noVBand","0")