diff options
author | John MacFarlane <jgm@berkeley.edu> | 2019-02-02 18:22:43 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2019-02-02 18:22:43 -0800 |
commit | ca4d308b60472ab0dfb9186f5c999177ef3137da (patch) | |
tree | 5871cb557868c91da86c3c604813822c722c2586 /src/Text/Pandoc/Readers | |
parent | d50cb029fdd3555d5f14e6eee15411d6704ad96e (diff) | |
download | pandoc-ca4d308b60472ab0dfb9186f5c999177ef3137da.tar.gz |
ipynb reader: handle images referring to attachments.
Previously we didn't strip off the attachment: prefix,
so even though the attachment is available in the mediabag,
pandoc couldn't find it.
Diffstat (limited to 'src/Text/Pandoc/Readers')
-rw-r--r-- | src/Text/Pandoc/Readers/Ipynb.hs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Readers/Ipynb.hs b/src/Text/Pandoc/Readers/Ipynb.hs index ad0652ed0..14cae6bb7 100644 --- a/src/Text/Pandoc/Readers/Ipynb.hs +++ b/src/Text/Pandoc/Readers/Ipynb.hs @@ -36,6 +36,7 @@ Ipynb (Jupyter notebook JSON format) reader for pandoc. module Text.Pandoc.Readers.Ipynb ( readIpynb ) where import Prelude +import Data.List (isPrefixOf) import Data.Maybe (fromMaybe) import Data.Digest.Pure.SHA (sha1, showDigest) import Text.Pandoc.Options @@ -46,6 +47,7 @@ import Data.Ipynb as Ipynb import Text.Pandoc.Class import Text.Pandoc.MIME (extensionFromMimeType) import Text.Pandoc.UTF8 +import Text.Pandoc.Walk (walk) import Text.Pandoc.Error import Data.Text (Text) import qualified Data.Map as M @@ -95,7 +97,7 @@ cellToBlocks opts lang c = do mapM_ addAttachment attachments case cellType c of Ipynb.Markdown -> do - Pandoc _ bs <- readMarkdown opts source + Pandoc _ bs <- walk fixImage <$> readMarkdown opts source return $ B.divWith ("",["cell","markdown"],kvs) $ B.fromList bs Ipynb.Heading lev -> do @@ -122,6 +124,12 @@ cellToBlocks opts lang c = do B.codeBlockWith ("",[lang],[]) (T.unpack source) <> outputBlocks +-- Remove attachment: prefix from images... +fixImage :: Inline -> Inline +fixImage (Image attr lab (src,tit)) + | "attachment:" `isPrefixOf` src = Image attr lab (drop 11 src, tit) +fixImage x = x + addAttachment :: PandocMonad m => (Text, MimeBundle) -> m () addAttachment (fname, mimeBundle) = do let fp = T.unpack fname |