diff options
author | John MacFarlane <jgm@berkeley.edu> | 2019-02-10 22:05:22 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2019-02-10 22:05:22 -0800 |
commit | 85afbc7c6b00cc796a5a674d0d50022707a1a4f9 (patch) | |
tree | 9b4bd82a1cbd10160b68ccddaaa17307fc749af0 /src | |
parent | 9abb458cbbcf93f6cd0f435c26ce67d77762e3ac (diff) | |
download | pandoc-85afbc7c6b00cc796a5a674d0d50022707a1a4f9.tar.gz |
ipynb writer: keep plain text fallbacks in output...
even if a richer format is included.
We don't know what output format will be needed.
The fallback can always be weeded out using a filter.
Closes #5293.
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/Readers/Ipynb.hs | 40 |
1 files changed, 14 insertions, 26 deletions
diff --git a/src/Text/Pandoc/Readers/Ipynb.hs b/src/Text/Pandoc/Readers/Ipynb.hs index 14cae6bb7..028e07dda 100644 --- a/src/Text/Pandoc/Readers/Ipynb.hs +++ b/src/Text/Pandoc/Readers/Ipynb.hs @@ -169,23 +169,14 @@ outputToBlock _ Err{ errName = ename, -- the output format. handleData :: PandocMonad m => ReaderOptions -> JSONMeta -> MimeBundle -> m B.Blocks -handleData opts metadata (MimeBundle mb) = do - let mimePairs = M.toList mb - - results <- mapM dataBlock mimePairs - - -- return the result with highest priority: - - let highest = maximum (0 : map fst results) - return $ case [r | (pr, r) <- results, pr == highest] of - x:_ -> x - [] -> mempty +handleData opts metadata (MimeBundle mb) = + mconcat <$> mapM dataBlock (M.toList mb) where exts = readerExtensions opts - dataBlock :: PandocMonad m => (MimeType, MimeData) -> m (Int, B.Blocks) + dataBlock :: PandocMonad m => (MimeType, MimeData) -> m B.Blocks dataBlock (mt, BinaryData bs) | "image/" `T.isPrefixOf` mt = do @@ -206,29 +197,26 @@ handleData opts metadata (MimeBundle mb) = do Nothing -> "" Just ext -> '.':ext insertMedia fname (Just mt') bl - return (3, B.para $ B.imageWith ("",[],metaPairs) fname "" mempty) - - dataBlock (_, BinaryData _) = return (0, mempty) + return $ B.para $ B.imageWith ("",[],metaPairs) fname "" mempty + | otherwise = return mempty dataBlock ("text/html", TextualData t) | extensionEnabled Ext_raw_html exts - = return (2, B.rawBlock "html" $ T.unpack t) - | otherwise = do -- try parsing the HTML - Pandoc _ bls <- readHtml opts t - return (1, B.fromList bls) + = return $ B.rawBlock "html" $ T.unpack t + | otherwise = return mempty - dataBlock ("text/latex", TextualData t) = - return $ if extensionEnabled Ext_raw_tex exts - then (2, B.rawBlock "latex" $ T.unpack t) - else (0, mempty) + dataBlock ("text/latex", TextualData t) + | extensionEnabled Ext_raw_tex exts + = return $ B.rawBlock "latex" $ T.unpack t + | otherwise = return mempty dataBlock ("text/plain", TextualData t) = - return (0, B.codeBlock $ T.unpack t) + return $ B.codeBlock $ T.unpack t dataBlock (_, JsonData v) = - return (2, B.codeBlockWith ("",["json"],[]) $ toStringLazy $ encode v) + return $ B.codeBlockWith ("",["json"],[]) $ toStringLazy $ encode v - dataBlock _ = return (0, mempty) + dataBlock _ = return mempty jsonMetaToMeta :: JSONMeta -> M.Map String MetaValue jsonMetaToMeta = M.mapKeys T.unpack . M.map valueToMetaValue |