aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Readers/Docx/OMath.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Text/Pandoc/Readers/Docx/OMath.hs')
-rw-r--r--src/Text/Pandoc/Readers/Docx/OMath.hs17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/Text/Pandoc/Readers/Docx/OMath.hs b/src/Text/Pandoc/Readers/Docx/OMath.hs
index 62fc6286c..47f8dd197 100644
--- a/src/Text/Pandoc/Readers/Docx/OMath.hs
+++ b/src/Text/Pandoc/Readers/Docx/OMath.hs
@@ -38,11 +38,20 @@ import Data.Maybe (mapMaybe, fromMaybe)
import Data.List (intersperse)
import qualified Text.TeXMath.Types as TM
-readOMML :: Element -> Maybe [TM.Exp]
-readOMML element | isElem "m" "oMath" element =
+readOMML :: String -> Either String [TM.Exp]
+readOMML s | Just e <- parseXMLDoc s =
+ case elemToOMML e of
+ Just exs -> Right exs
+ Nothing -> Left "xml file was not an <m:oMathPara> or <m:oMath> element."
+readOMML _ = Left "Couldn't parse OMML file"
+
+elemToOMML :: Element -> Maybe [TM.Exp]
+elemToOMML element | isElem "m" "oMathPara" element = do
+ let expList = mapMaybe elemToOMML (elChildren element)
+ return $ map (\l -> if length l == 1 then (head l) else TM.EGrouped l) expList
+elemToOMML element | isElem "m" "oMath" element =
Just $ concat $ mapMaybe (elemToExps') (elChildren element)
-readOMML _ = Nothing
-
+elemToOMML _ = Nothing
isElem :: String -> String -> Element -> Bool
isElem prefix name element =