Docx reader: Add placeholder for word diagram

This commit is contained in:
Ezwal 2021-09-29 15:42:37 +02:00 committed by John MacFarlane
parent 45db998b39
commit 472b33095e
4 changed files with 19 additions and 0 deletions

View file

@ -322,6 +322,7 @@ runToInlines (InlineDrawing fp title alt bs ext) = do
(lift . lift) $ P.insertMedia fp Nothing bs
return $ imageWith (extentToAttr ext) (T.pack fp) title $ text alt
runToInlines InlineChart = return $ spanWith ("", ["chart"], []) $ text "[CHART]"
runToInlines InlineDiagram = return $ spanWith ("", ["diagram"], []) $ text "[DIAGRAM]"
extentToAttr :: Extent -> Attr
extentToAttr (Just (w, h)) =
@ -434,6 +435,8 @@ parPartToInlines' (Drawing fp title alt bs ext) = do
return $ imageWith (extentToAttr ext) (T.pack fp) title $ text alt
parPartToInlines' Chart =
return $ spanWith ("", ["chart"], []) $ text "[CHART]"
parPartToInlines' Diagram =
return $ spanWith ("", ["diagram"], []) $ text "[DIAGRAM]"
parPartToInlines' (InternalHyperLink anchor runs) = do
ils <- smushInlines <$> mapM runToInlines runs
return $ link ("#" <> anchor) "" ils

View file

@ -322,6 +322,7 @@ data ParPart = PlainRun Run
| ExternalHyperLink URL [Run]
| Drawing FilePath T.Text T.Text B.ByteString Extent -- title, alt
| Chart -- placeholder for now
| Diagram -- placeholder for now
| PlainOMath [Exp]
| Field FieldInfo [Run]
| NullParPart -- when we need to return nothing, but
@ -333,6 +334,7 @@ data Run = Run RunStyle [RunElem]
| Endnote [BodyPart]
| InlineDrawing FilePath T.Text T.Text B.ByteString Extent -- title, alt
| InlineChart -- placeholder
| InlineDiagram -- placeholder
deriving Show
data RunElem = TextRun T.Text | LnBrk | Tab | SoftHyphen | NoBreakHyphen
@ -821,6 +823,13 @@ elemToParPart ns element
, Just imagedataElem <- findChildByName ns "v" "imagedata" shapeElem
, Just drawingId <- findAttrByName ns "r" "id" imagedataElem
= expandDrawingId drawingId >>= (\(fp, bs) -> return $ Drawing fp "" "" bs Nothing)
-- Diagram
elemToParPart ns element
| isElem ns "w" "r" element
, Just drawingElem <- findChildByName ns "w" "drawing" element
, d_ns <- "http://schemas.openxmlformats.org/drawingml/2006/diagram"
, Just _ <- findElement (QName "relIds" (Just d_ns) (Just "dgm")) drawingElem
= return Diagram
-- Chart
elemToParPart ns element
| isElem ns "w" "r" element
@ -987,6 +996,11 @@ childElemToRun ns 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" "drawing" element
, c_ns <- "http://schemas.openxmlformats.org/drawingml/2006/diagram"
, Just _ <- findElement (QName "relIds" (Just c_ns) (Just "dgm")) element
= return InlineDiagram
childElemToRun ns element
| isElem ns "w" "footnoteReference" element
, Just fnId <- findAttrByName ns "w" "id" element = do

BIN
test/docx/diagram.docx Normal file

Binary file not shown.

2
test/docx/diagram.native Normal file
View file

@ -0,0 +1,2 @@
[Header 1 ("diagram-after",[],[]) [Str "Diagram",Space,Str "after:"]
,Para [Span ("",["diagram"],[]) [Str "[DIAGRAM]"]]]