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.
This commit is contained in:
parent
7539de0287
commit
eea4d14f60
2 changed files with 17 additions and 0 deletions
|
@ -321,6 +321,7 @@ runToInlines (InlineDrawing fp title alt bs ext) = do
|
||||||
mediaBag <- gets docxMediaBag
|
mediaBag <- gets docxMediaBag
|
||||||
modify $ \s -> s { docxMediaBag = insertMedia fp Nothing bs mediaBag }
|
modify $ \s -> s { docxMediaBag = insertMedia fp Nothing bs mediaBag }
|
||||||
return $ imageWith (extentToAttr ext) fp title $ text alt
|
return $ imageWith (extentToAttr ext) fp title $ text alt
|
||||||
|
runToInlines InlineChart = return $ spanWith ("", ["chart"], []) $ text "[CHART]"
|
||||||
|
|
||||||
extentToAttr :: Extent -> Attr
|
extentToAttr :: Extent -> Attr
|
||||||
extentToAttr (Just (w, h)) =
|
extentToAttr (Just (w, h)) =
|
||||||
|
@ -405,6 +406,8 @@ parPartToInlines (Drawing fp title alt bs ext) = do
|
||||||
mediaBag <- gets docxMediaBag
|
mediaBag <- gets docxMediaBag
|
||||||
modify $ \s -> s { docxMediaBag = insertMedia fp Nothing bs mediaBag }
|
modify $ \s -> s { docxMediaBag = insertMedia fp Nothing bs mediaBag }
|
||||||
return $ imageWith (extentToAttr ext) fp title $ text alt
|
return $ imageWith (extentToAttr ext) fp title $ text alt
|
||||||
|
parPartToInlines Chart = do
|
||||||
|
return $ spanWith ("", ["chart"], []) $ text "[CHART]"
|
||||||
parPartToInlines (InternalHyperLink anchor runs) = do
|
parPartToInlines (InternalHyperLink anchor runs) = do
|
||||||
ils <- smushInlines <$> mapM runToInlines runs
|
ils <- smushInlines <$> mapM runToInlines runs
|
||||||
return $ link ('#' : anchor) "" ils
|
return $ link ('#' : anchor) "" ils
|
||||||
|
|
|
@ -216,6 +216,7 @@ data ParPart = PlainRun Run
|
||||||
| InternalHyperLink Anchor [Run]
|
| InternalHyperLink Anchor [Run]
|
||||||
| ExternalHyperLink URL [Run]
|
| ExternalHyperLink URL [Run]
|
||||||
| Drawing FilePath String String B.ByteString Extent -- title, alt
|
| Drawing FilePath String String B.ByteString Extent -- title, alt
|
||||||
|
| Chart -- placeholder for now
|
||||||
| PlainOMath [Exp]
|
| PlainOMath [Exp]
|
||||||
deriving Show
|
deriving Show
|
||||||
|
|
||||||
|
@ -223,6 +224,7 @@ data Run = Run RunStyle [RunElem]
|
||||||
| Footnote [BodyPart]
|
| Footnote [BodyPart]
|
||||||
| Endnote [BodyPart]
|
| Endnote [BodyPart]
|
||||||
| InlineDrawing FilePath String String B.ByteString Extent -- title, alt
|
| InlineDrawing FilePath String String B.ByteString Extent -- title, alt
|
||||||
|
| InlineChart -- placeholder
|
||||||
deriving Show
|
deriving Show
|
||||||
|
|
||||||
data RunElem = TextRun String | LnBrk | Tab | SoftHyphen | NoBreakHyphen
|
data RunElem = TextRun String | LnBrk | Tab | SoftHyphen | NoBreakHyphen
|
||||||
|
@ -682,6 +684,13 @@ elemToParPart ns element
|
||||||
-- Todo: check out title and attr for deprecated format.
|
-- Todo: check out title and attr for deprecated format.
|
||||||
Just s -> expandDrawingId s >>= (\(fp, bs) -> return $ Drawing fp "" "" bs Nothing)
|
Just s -> expandDrawingId s >>= (\(fp, bs) -> return $ Drawing fp "" "" bs Nothing)
|
||||||
Nothing -> throwError WrongElem
|
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
|
elemToParPart ns element
|
||||||
| isElem ns "w" "r" element =
|
| isElem ns "w" "r" element =
|
||||||
elemToRun ns element >>= (\r -> return $ PlainRun r)
|
elemToRun ns element >>= (\r -> return $ PlainRun r)
|
||||||
|
@ -778,6 +787,11 @@ childElemToRun ns element
|
||||||
Just s -> expandDrawingId s >>=
|
Just s -> expandDrawingId s >>=
|
||||||
(\(fp, bs) -> return $ InlineDrawing fp title alt bs $ elemToExtent element)
|
(\(fp, bs) -> return $ InlineDrawing fp title alt bs $ elemToExtent element)
|
||||||
Nothing -> throwError WrongElem
|
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
|
childElemToRun ns element
|
||||||
| isElem ns "w" "footnoteReference" element
|
| isElem ns "w" "footnoteReference" element
|
||||||
, Just fnId <- findAttr (elemName ns "w" "id") element = do
|
, Just fnId <- findAttr (elemName ns "w" "id") element = do
|
||||||
|
|
Loading…
Add table
Reference in a new issue