git.iko.soy/typeable/pandoc
on master help sign in
Docx reader: add a placeholder value for CHART.

We wrap `[CHART]` in a `<span class="chart">`. Note that it maps to inlines because, in docx, anything in a drawing tag can be part of a larger paragraph.

commiteea4d14f602794532b33c1e5a3966fccb5f7ea8b authorJesse Rosenthal <jrosenthal@jhu.edu> dateThu 10 Nov 2016, 13:15 (10 years ago) parent7539de0
2 files changed+17
src/Text/Pandoc/Readers/Docx.hs+3 src/Text/Pandoc/Readers/Docx/Parse.hs+14
src/Text/Pandoc/Readers/Docx.hs+3
@@ -321,6 +321,7 @@ runToInlines (InlineDrawing fp title alt bs ext) = do
321321 mediaBag <- gets docxMediaBag
322322 modify $ \s -> s { docxMediaBag = insertMedia fp Nothing bs mediaBag }
323323 return $ imageWith (extentToAttr ext) fp title $ text alt
324+runToInlines InlineChart = return $ spanWith ("", ["chart"], []) $ text "[CHART]"
324325
325326extentToAttr :: Extent -> Attr
326327extentToAttr (Just (w, h)) =
@@ -405,6 +406,8 @@ parPartToInlines (Drawing fp title alt bs ext) = do
405406 mediaBag <- gets docxMediaBag
406407 modify $ \s -> s { docxMediaBag = insertMedia fp Nothing bs mediaBag }
407408 return $ imageWith (extentToAttr ext) fp title $ text alt
409+parPartToInlines Chart = do
410+ return $ spanWith ("", ["chart"], []) $ text "[CHART]"
408411parPartToInlines (InternalHyperLink anchor runs) = do
409412 ils <- smushInlines <$> mapM runToInlines runs
410413 return $ link ('#' : anchor) "" ils
src/Text/Pandoc/Readers/Docx/Parse.hs+14
@@ -216,6 +216,7 @@ data ParPart = PlainRun Run
216216 | InternalHyperLink Anchor [Run]
217217 | ExternalHyperLink URL [Run]
218218 | Drawing FilePath String String B.ByteString Extent -- title, alt
219+ | Chart -- placeholder for now
219220 | PlainOMath [Exp]
220221 deriving Show
221222
@@ -223,6 +224,7 @@ data Run = Run RunStyle [RunElem]
223224 | Footnote [BodyPart]
224225 | Endnote [BodyPart]
225226 | InlineDrawing FilePath String String B.ByteString Extent -- title, alt
227+ | InlineChart -- placeholder
226228 deriving Show
227229
228230data RunElem = TextRun String | LnBrk | Tab | SoftHyphen | NoBreakHyphen
@@ -682,6 +684,13 @@ elemToParPart ns element
682684 -- Todo: check out title and attr for deprecated format.
683685 Just s -> expandDrawingId s >>= (\(fp, bs) -> return $ Drawing fp "" "" bs Nothing)
684686 Nothing -> throwError WrongElem
687+-- Chart
688+elemToParPart ns element
689+ | isElem ns "w" "r" element
690+ , Just drawingElem <- findChild (elemName ns "w" "drawing") element
691+ , c_ns <- "http://schemas.openxmlformats.org/drawingml/2006/chart"
692+ , Just _ <- findElement (QName "chart" (Just c_ns) (Just "c")) drawingElem
693+ = return Chart
685694elemToParPart ns element
686695 | isElem ns "w" "r" element =
687696 elemToRun ns element >>= (\r -> return $ PlainRun r)
@@ -778,6 +787,11 @@ childElemToRun ns element
778787 Just s -> expandDrawingId s >>=
779788 (\(fp, bs) -> return $ InlineDrawing fp title alt bs $ elemToExtent element)
780789 Nothing -> throwError WrongElem
790+childElemToRun ns element
791+ | isElem ns "w" "drawing" element
792+ , c_ns <- "http://schemas.openxmlformats.org/drawingml/2006/chart"
793+ , Just _ <- findElement (QName "chart" (Just c_ns) (Just "c")) element
794+ = return InlineChart
781795childElemToRun ns element
782796 | isElem ns "w" "footnoteReference" element
783797 , Just fnId <- findAttr (elemName ns "w" "id") element = do