From eea4d14f602794532b33c1e5a3966fccb5f7ea8b Mon Sep 17 00:00:00 2001 From: Jesse Rosenthal Date: Thu, 10 Nov 2016 13:15:02 -0500 Subject: Docx reader: add a placeholder value for CHART. We wrap `[CHART]` in a ``. Note that it maps to inlines because, in docx, anything in a drawing tag can be part of a larger paragraph. --- src/Text/Pandoc/Readers/Docx.hs | 3 +++ src/Text/Pandoc/Readers/Docx/Parse.hs | 14 ++++++++++++++ 2 files changed, 17 insertions(+) (limited to 'src') diff --git a/src/Text/Pandoc/Readers/Docx.hs b/src/Text/Pandoc/Readers/Docx.hs index 2c171fe0b..9fe3a3fea 100644 --- a/src/Text/Pandoc/Readers/Docx.hs +++ b/src/Text/Pandoc/Readers/Docx.hs @@ -321,6 +321,7 @@ runToInlines (InlineDrawing fp title alt bs ext) = do mediaBag <- gets docxMediaBag modify $ \s -> s { docxMediaBag = insertMedia fp Nothing bs mediaBag } return $ imageWith (extentToAttr ext) fp title $ text alt +runToInlines InlineChart = return $ spanWith ("", ["chart"], []) $ text "[CHART]" extentToAttr :: Extent -> Attr extentToAttr (Just (w, h)) = @@ -405,6 +406,8 @@ parPartToInlines (Drawing fp title alt bs ext) = do mediaBag <- gets docxMediaBag modify $ \s -> s { docxMediaBag = insertMedia fp Nothing bs mediaBag } return $ imageWith (extentToAttr ext) fp title $ text alt +parPartToInlines Chart = do + return $ spanWith ("", ["chart"], []) $ text "[CHART]" parPartToInlines (InternalHyperLink anchor runs) = do ils <- smushInlines <$> mapM runToInlines runs return $ link ('#' : anchor) "" ils diff --git a/src/Text/Pandoc/Readers/Docx/Parse.hs b/src/Text/Pandoc/Readers/Docx/Parse.hs index 1d7b6088f..80753346b 100644 --- a/src/Text/Pandoc/Readers/Docx/Parse.hs +++ b/src/Text/Pandoc/Readers/Docx/Parse.hs @@ -216,6 +216,7 @@ data ParPart = PlainRun Run | InternalHyperLink Anchor [Run] | ExternalHyperLink URL [Run] | Drawing FilePath String String B.ByteString Extent -- title, alt + | Chart -- placeholder for now | PlainOMath [Exp] deriving Show @@ -223,6 +224,7 @@ data Run = Run RunStyle [RunElem] | Footnote [BodyPart] | Endnote [BodyPart] | InlineDrawing FilePath String String B.ByteString Extent -- title, alt + | InlineChart -- placeholder deriving Show data RunElem = TextRun String | LnBrk | Tab | SoftHyphen | NoBreakHyphen @@ -682,6 +684,13 @@ elemToParPart ns element -- Todo: check out title and attr for deprecated format. Just s -> expandDrawingId s >>= (\(fp, bs) -> return $ Drawing fp "" "" bs Nothing) Nothing -> throwError WrongElem +-- Chart +elemToParPart ns element + | isElem ns "w" "r" element + , Just drawingElem <- findChild (elemName ns "w" "drawing") element + , c_ns <- "http://schemas.openxmlformats.org/drawingml/2006/chart" + , Just _ <- findElement (QName "chart" (Just c_ns) (Just "c")) drawingElem + = return Chart elemToParPart ns element | isElem ns "w" "r" element = elemToRun ns element >>= (\r -> return $ PlainRun r) @@ -778,6 +787,11 @@ childElemToRun ns element Just s -> expandDrawingId s >>= (\(fp, bs) -> return $ InlineDrawing fp title alt bs $ elemToExtent element) Nothing -> throwError WrongElem +childElemToRun ns element + | isElem ns "w" "drawing" element + , c_ns <- "http://schemas.openxmlformats.org/drawingml/2006/chart" + , Just _ <- findElement (QName "chart" (Just c_ns) (Just "c")) element + = return InlineChart childElemToRun ns element | isElem ns "w" "footnoteReference" element , Just fnId <- findAttr (elemName ns "w" "id") element = do -- cgit v1.2.3