summaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2022-12-11 20:20:28 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2022-12-11 20:20:28 -0800
commit3439c1ae94f5caa1043d88818863870f3e38e6c2 (patch)
tree36cdcd86118d202908c6a2b87c7e1e21edb6dc48 /src/Text
parent5819e36dfa2b2e16e7b54cecfbc6851efec090d2 (diff)
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.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Readers/Docx.hs4
-rw-r--r--src/Text/Pandoc/Readers/Docx/Parse.hs15
2 files changed, 12 insertions, 7 deletions
diff --git a/src/Text/Pandoc/Readers/Docx.hs b/src/Text/Pandoc/Readers/Docx.hs
index 0fe9a3b9f..c91372553 100644
--- a/src/Text/Pandoc/Readers/Docx.hs
+++ b/src/Text/Pandoc/Readers/Docx.hs
@@ -468,6 +468,8 @@ parPartToInlines' (ExternalHyperLink target children) = do
return $ link target "" ils
parPartToInlines' (PlainOMath exps) =
return $ math $ writeTeX exps
+parPartToInlines' (OMathPara exps) =
+ return $ displayMath $ writeTeX exps
parPartToInlines' (Field info children) =
case info of
HyperlinkField url -> parPartToInlines' $ ExternalHyperLink url children
@@ -793,8 +795,6 @@ bodyPartToBlocks (Tbl cap grid look parts) = do
(TableHead nullAttr headerCells)
[TableBody nullAttr 0 [] bodyCells]
(TableFoot nullAttr [])
-bodyPartToBlocks (OMathPara e) =
- return $ para $ displayMath (writeTeX e)
-- replace targets with generated anchors.
rewriteLink' :: PandocMonad m => Inline -> DocxContext m Inline
diff --git a/src/Text/Pandoc/Readers/Docx/Parse.hs b/src/Text/Pandoc/Readers/Docx/Parse.hs
index c36107da7..9e922ff76 100644
--- a/src/Text/Pandoc/Readers/Docx/Parse.hs
+++ b/src/Text/Pandoc/Readers/Docx/Parse.hs
@@ -242,7 +242,6 @@ data BodyPart = Paragraph ParagraphStyle [ParPart]
| ListItem ParagraphStyle T.Text T.Text (Maybe Level) [ParPart]
| Tbl T.Text TblGrid TblLook [Row]
| TblCaption ParagraphStyle [ParPart]
- | OMathPara [Exp]
deriving Show
type TblGrid = [Integer]
@@ -333,6 +332,7 @@ data ParPart = PlainRun Run
| Chart -- placeholder for now
| Diagram -- placeholder for now
| PlainOMath [Exp]
+ | OMathPara [Exp]
| Field FieldInfo [ParPart]
deriving Show
@@ -703,10 +703,12 @@ pStyleIndentation style = (getParStyleField indent . pStyle) style
elemToBodyPart :: NameSpaces -> Element -> D BodyPart
elemToBodyPart ns element
- | isElem ns "w" "p" element
- , (c:_) <- findChildrenByName ns "m" "oMathPara" element = do
- expsLst <- eitherToD $ readOMML $ showElement c
- return $ OMathPara expsLst
+ | isElem ns "m" "oMathPara" element = do
+ expsLst <- eitherToD $ readOMML $ showElement element
+ parstyle <- elemToParagraphStyle ns element
+ <$> asks envParStyles
+ <*> asks envNumbering
+ return $ Paragraph parstyle [OMathPara expsLst]
elemToBodyPart ns element
| isElem ns "w" "p" element
, Just (numId, lvl) <- getNumInfo ns element = do
@@ -1000,6 +1002,9 @@ elemToParPart' ns element
elemToParPart' ns element
| isElem ns "m" "oMath" element =
fmap (return . PlainOMath) (eitherToD $ readOMML $ showElement element)
+elemToParPart' ns element
+ | isElem ns "m" "oMathPara" element =
+ fmap (return . OMathPara) (eitherToD $ readOMML $ showElement element)
elemToParPart' _ _ = throwError WrongElem
elemToCommentStart :: NameSpaces -> Element -> D [ParPart]