Skip to content

Commit 3439c1a

Browse files
committed
Docx reader: fix handling of oMathPara in w:p with other content.
Closes #8483. The problem is that oMathPara can either occur at the block-level (child of w:body) or at the inline level (child of w:p, potentially with other content). We need to handle both cases. Previously the code just assumed that if we had a w:p with an oMathPara, the math would be the sole content. This patch removes OMathPara as a constructor of BodyPart and adds it as a constructor of ParPart.
1 parent 5819e36 commit 3439c1a

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/Text/Pandoc/Readers/Docx.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,8 @@ parPartToInlines' (ExternalHyperLink target children) = do
468468
return $ link target "" ils
469469
parPartToInlines' (PlainOMath exps) =
470470
return $ math $ writeTeX exps
471+
parPartToInlines' (OMathPara exps) =
472+
return $ displayMath $ writeTeX exps
471473
parPartToInlines' (Field info children) =
472474
case info of
473475
HyperlinkField url -> parPartToInlines' $ ExternalHyperLink url children
@@ -793,8 +795,6 @@ bodyPartToBlocks (Tbl cap grid look parts) = do
793795
(TableHead nullAttr headerCells)
794796
[TableBody nullAttr 0 [] bodyCells]
795797
(TableFoot nullAttr [])
796-
bodyPartToBlocks (OMathPara e) =
797-
return $ para $ displayMath (writeTeX e)
798798

799799
-- replace targets with generated anchors.
800800
rewriteLink' :: PandocMonad m => Inline -> DocxContext m Inline

src/Text/Pandoc/Readers/Docx/Parse.hs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ data BodyPart = Paragraph ParagraphStyle [ParPart]
242242
| ListItem ParagraphStyle T.Text T.Text (Maybe Level) [ParPart]
243243
| Tbl T.Text TblGrid TblLook [Row]
244244
| TblCaption ParagraphStyle [ParPart]
245-
| OMathPara [Exp]
246245
deriving Show
247246

248247
type TblGrid = [Integer]
@@ -333,6 +332,7 @@ data ParPart = PlainRun Run
333332
| Chart -- placeholder for now
334333
| Diagram -- placeholder for now
335334
| PlainOMath [Exp]
335+
| OMathPara [Exp]
336336
| Field FieldInfo [ParPart]
337337
deriving Show
338338

@@ -703,10 +703,12 @@ pStyleIndentation style = (getParStyleField indent . pStyle) style
703703

704704
elemToBodyPart :: NameSpaces -> Element -> D BodyPart
705705
elemToBodyPart ns element
706-
| isElem ns "w" "p" element
707-
, (c:_) <- findChildrenByName ns "m" "oMathPara" element = do
708-
expsLst <- eitherToD $ readOMML $ showElement c
709-
return $ OMathPara expsLst
706+
| isElem ns "m" "oMathPara" element = do
707+
expsLst <- eitherToD $ readOMML $ showElement element
708+
parstyle <- elemToParagraphStyle ns element
709+
<$> asks envParStyles
710+
<*> asks envNumbering
711+
return $ Paragraph parstyle [OMathPara expsLst]
710712
elemToBodyPart ns element
711713
| isElem ns "w" "p" element
712714
, Just (numId, lvl) <- getNumInfo ns element = do
@@ -1000,6 +1002,9 @@ elemToParPart' ns element
10001002
elemToParPart' ns element
10011003
| isElem ns "m" "oMath" element =
10021004
fmap (return . PlainOMath) (eitherToD $ readOMML $ showElement element)
1005+
elemToParPart' ns element
1006+
| isElem ns "m" "oMathPara" element =
1007+
fmap (return . OMathPara) (eitherToD $ readOMML $ showElement element)
10031008
elemToParPart' _ _ = throwError WrongElem
10041009

10051010
elemToCommentStart :: NameSpaces -> Element -> D [ParPart]

0 commit comments

Comments
 (0)