git.iko.soy/typeable/pandoc
on master help sign in
OMath parser: Change signature of exported function.
a426812Jesse Rosenthal
src/Text/Pandoc/Readers/Docx.hs+4−5
@@ -321,7 +321,7 @@ runToInlines (InlineDrawing fp bs) = do
321 modify $ \s -> s { docxMediaBag = insertMedia fp Nothing bs mediaBag }
321 modify $ \s -> s { docxMediaBag = insertMedia fp Nothing bs mediaBag }
322 return [Image [] (fp, "")]
322 return [Image [] (fp, "")]
323
323
324−
324+
325
325
326
326
327parPartToInlines :: ParPart -> DocxContext [Inline]
327parPartToInlines :: ParPart -> DocxContext [Inline]
@@ -507,10 +507,9 @@ bodyPartToBlocks (Tbl cap _ look (r:rs)) = do
507 widths = replicate size 0 :: [Double]
507 widths = replicate size 0 :: [Double]
508
508
509 return [Table caption alignments widths hdrCells cells]
509 return [Table caption alignments widths hdrCells cells]
510−bodyPartToBlocks (OMathPara exps) = do
510+bodyPartToBlocks (OMathPara e) = do
511− return [Para $
512− map (\e -> Math DisplayMath (writeTeX e))
511+ return [Para [Math DisplayMath (writeTeX e)]]
513− exps]
512+
514
513
515-- replace targets with generated anchors.
514-- replace targets with generated anchors.
516rewriteLink :: Inline -> DocxContext Inline
515rewriteLink :: Inline -> DocxContext Inline
src/Text/Pandoc/Readers/Docx/OMath.hs+13−4
@@ -38,11 +38,20 @@ import Data.Maybe (mapMaybe, fromMaybe)
38import Data.List (intersperse)
38import Data.List (intersperse)
39import qualified Text.TeXMath.Types as TM
39import qualified Text.TeXMath.Types as TM
40
40
41+readOMML :: String -> Either String [TM.Exp]
42+readOMML s | Just e <- parseXMLDoc s =
43+ case elemToOMML e of
44+ Just exs -> Right exs
45+ Nothing -> Left "xml file was not an <m:oMathPara> or <m:oMath> element."
46+readOMML _ = Left "Couldn't parse OMML file"
47+
41−readOMML :: Element -> Maybe [TM.Exp]
48+elemToOMML :: Element -> Maybe [TM.Exp]
49+elemToOMML element | isElem "m" "oMathPara" element = do
50+ let expList = mapMaybe elemToOMML (elChildren element)
51+ return $ map (\l -> if length l == 1 then (head l) else TM.EGrouped l) expList
42−readOMML element | isElem "m" "oMath" element =
52+elemToOMML element | isElem "m" "oMath" element =
43 Just $ concat $ mapMaybe (elemToExps') (elChildren element)
53 Just $ concat $ mapMaybe (elemToExps') (elChildren element)
44−readOMML _ = Nothing
54+elemToOMML _ = Nothing
45−
46
55
47isElem :: String -> String -> Element -> Bool
56isElem :: String -> String -> Element -> Bool
48isElem prefix name element =
57isElem prefix name element =
src/Text/Pandoc/Readers/Docx/Parse.hs+7−3
@@ -86,6 +86,10 @@ maybeToD :: Maybe a -> D a
86maybeToD (Just a) = return a
86maybeToD (Just a) = return a
87maybeToD Nothing = throwError DocxError
87maybeToD Nothing = throwError DocxError
88
88
89+eitherToD :: Either a b -> D b
90+eitherToD (Right b) = return b
91+eitherToD (Left _) = throwError DocxError
92+
89concatMapM :: (Monad m) => (a -> m [b]) -> [a] -> m [b]
93concatMapM :: (Monad m) => (a -> m [b]) -> [a] -> m [b]
90concatMapM f xs = liftM concat (mapM f xs)
94concatMapM f xs = liftM concat (mapM f xs)
91
95
@@ -150,7 +154,7 @@ defaultParagraphStyle = ParagraphStyle { pStyle = []
150data BodyPart = Paragraph ParagraphStyle [ParPart]
154data BodyPart = Paragraph ParagraphStyle [ParPart]
151 | ListItem ParagraphStyle String String Level [ParPart]
155 | ListItem ParagraphStyle String String Level [ParPart]
152 | Tbl String TblGrid TblLook [Row]
156 | Tbl String TblGrid TblLook [Row]
153− | OMathPara [[Exp]]
157+ | OMathPara [Exp]
154 deriving Show
158 deriving Show
155
159
156type TblGrid = [Integer]
160type TblGrid = [Integer]
@@ -475,7 +479,7 @@ elemToBodyPart ns element
475 | isElem ns "w" "p" element
479 | isElem ns "w" "p" element
476 , (c:_) <- findChildren (elemName ns "m" "oMathPara") element =
480 , (c:_) <- findChildren (elemName ns "m" "oMathPara") element =
477 do
481 do
478− expsLst <- mapD (\e -> (maybeToD $ readOMML e)) (elChildren c)
482+ expsLst <- eitherToD $ readOMML $ showElement c
479 return $ OMathPara expsLst
483 return $ OMathPara expsLst
480elemToBodyPart ns element
484elemToBodyPart ns element
481 | isElem ns "w" "p" element
485 | isElem ns "w" "p" element
@@ -575,7 +579,7 @@ elemToParPart ns element
575 Nothing -> ExternalHyperLink "" runs
579 Nothing -> ExternalHyperLink "" runs
576elemToParPart ns element
580elemToParPart ns element
577 | isElem ns "m" "oMath" element =
581 | isElem ns "m" "oMath" element =
578− (maybeToD $ readOMML element) >>= (return . PlainOMath)
582+ (eitherToD $ readOMML $ showElement element) >>= (return . PlainOMath)
579elemToParPart _ _ = throwError WrongElem
583elemToParPart _ _ = throwError WrongElem
580
584
581lookupFootnote :: String -> Notes -> Maybe Element
585lookupFootnote :: String -> Notes -> Maybe Element