diff options
author | John MacFarlane <jgm@berkeley.edu> | 2014-08-07 13:41:58 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2014-08-07 13:41:58 -0700 |
commit | 44dad5286631748b6ed8571f2bcf6a7828e06a79 (patch) | |
tree | ed4cc21befb33021fa94376a47fd4e20ba5ecaca /src | |
parent | 482f7f8e157b713b5dcf81303844721d827b16de (diff) | |
parent | 98d14b2b2a20111d68bdfbaf358da41537ea71c9 (diff) | |
download | pandoc-44dad5286631748b6ed8571f2bcf6a7828e06a79.tar.gz |
Merge pull request #1495 from jkr/inline-drawings
Docx reader: Inline image fix
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/Readers/Docx.hs | 7 | ||||
-rw-r--r-- | src/Text/Pandoc/Readers/Docx/Parse.hs | 18 |
2 files changed, 22 insertions, 3 deletions
diff --git a/src/Text/Pandoc/Readers/Docx.hs b/src/Text/Pandoc/Readers/Docx.hs index 367e26bd0..f19570aec 100644 --- a/src/Text/Pandoc/Readers/Docx.hs +++ b/src/Text/Pandoc/Readers/Docx.hs @@ -321,6 +321,13 @@ runToInlines (Footnote bps) = concatMapM bodyPartToBlocks bps >>= (\blks -> return [Note blks]) runToInlines (Endnote bps) = concatMapM bodyPartToBlocks bps >>= (\blks -> return [Note blks]) +runToInlines (InlineDrawing fp bs) = do + mediaBag <- gets docxMediaBag + modify $ \s -> s { docxMediaBag = insertMedia fp Nothing bs mediaBag } + return [Image [] (fp, "")] + + + parPartToInlines :: ParPart -> DocxContext [Inline] parPartToInlines (PlainRun r) = runToInlines r diff --git a/src/Text/Pandoc/Readers/Docx/Parse.hs b/src/Text/Pandoc/Readers/Docx/Parse.hs index 96210c31a..bc4e6ea06 100644 --- a/src/Text/Pandoc/Readers/Docx/Parse.hs +++ b/src/Text/Pandoc/Readers/Docx/Parse.hs @@ -282,6 +282,7 @@ defaultGroupStyle = GroupStyle {groupChr = Nothing, groupPos = Nothing} data Run = Run RunStyle [RunElem] | Footnote [BodyPart] | Endnote [BodyPart] + | InlineDrawing FilePath B.ByteString deriving Show data RunElem = TextRun String | LnBrk | Tab @@ -874,14 +875,14 @@ lookupRelationship :: RelId -> [Relationship] -> Maybe Target lookupRelationship relid rels = lookup relid (map (\(Relationship pair) -> pair) rels) -expandDrawingId :: String -> D ParPart +expandDrawingId :: String -> D (FilePath, B.ByteString) expandDrawingId s = do target <- asks (lookupRelationship s . envRelationships) case target of Just filepath -> do bytes <- asks (lookup (combine "word" filepath) . envMedia) case bytes of - Just bs -> return $ Drawing filepath bs + Just bs -> return (filepath, bs) Nothing -> throwError DocxError Nothing -> throwError DocxError @@ -894,7 +895,7 @@ elemToParPart ns element >>= findAttr (QName "embed" (lookup "r" ns) (Just "r")) in case drawing of - Just s -> expandDrawingId s + Just s -> expandDrawingId s >>= (\(fp, bs) -> return $ Drawing fp bs) Nothing -> throwError WrongElem elemToParPart ns element | isElem ns "w" "r" element = @@ -945,6 +946,17 @@ lookupEndnote s (Notes _ _ ens) = ens >>= (M.lookup s) elemToRun :: NameSpaces -> Element -> D Run elemToRun ns element | isElem ns "w" "r" element + , Just drawingElem <- findChild (elemName ns "w" "drawing") element = + let a_ns = "http://schemas.openxmlformats.org/drawingml/2006/main" + drawing = findElement (QName "blip" (Just a_ns) (Just "a")) drawingElem + >>= findAttr (QName "embed" (lookup "r" ns) (Just "r")) + in + case drawing of + Just s -> expandDrawingId s >>= + (\(fp, bs) -> return $ InlineDrawing fp bs) + Nothing -> throwError WrongElem +elemToRun ns element + | isElem ns "w" "r" element , Just ref <- findChild (elemName ns "w" "footnoteReference") element , Just fnId <- findAttr (elemName ns "w" "id") ref = do notes <- asks envNotes |