git.iko.soy/typeable/pandoc
on master help sign in
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.

commit85afbc7c6b00cc796a5a674d0d50022707a1a4f9 authorJohn MacFarlane <jgm@berkeley.edu> dateSun 10 Feb 2019, 22:05 (8 years ago) parent9abb458
1 file changed+14−26
src/Text/Pandoc/Readers/Ipynb.hs+14−26
src/Text/Pandoc/Readers/Ipynb.hs+14−26
@@ -169,23 +169,14 @@ outputToBlock _ Err{ errName = ename,
169169-- the output format.
170170handleData :: PandocMonad m
171171 => ReaderOptions -> JSONMeta -> MimeBundle -> m B.Blocks
172−handleData opts metadata (MimeBundle mb) = do
173− let mimePairs = M.toList mb
174−
175− results <- mapM dataBlock mimePairs
176−
177− -- return the result with highest priority:
178−
179− let highest = maximum (0 : map fst results)
180− return $ case [r | (pr, r) <- results, pr == highest] of
181− x:_ -> x
182− [] -> mempty
172+handleData opts metadata (MimeBundle mb) =
173+ mconcat <$> mapM dataBlock (M.toList mb)
183174
184175 where
185176
186177 exts = readerExtensions opts
187178
188− dataBlock :: PandocMonad m => (MimeType, MimeData) -> m (Int, B.Blocks)
179+ dataBlock :: PandocMonad m => (MimeType, MimeData) -> m B.Blocks
189180 dataBlock (mt, BinaryData bs)
190181 | "image/" `T.isPrefixOf` mt
191182 = do
@@ -206,29 +197,26 @@ handleData opts metadata (MimeBundle mb) = do
206197 Nothing -> ""
207198 Just ext -> '.':ext
208199 insertMedia fname (Just mt') bl
209− return (3, B.para $ B.imageWith ("",[],metaPairs) fname "" mempty)
210−
211− dataBlock (_, BinaryData _) = return (0, mempty)
200+ return $ B.para $ B.imageWith ("",[],metaPairs) fname "" mempty
201+ | otherwise = return mempty
212202
213203 dataBlock ("text/html", TextualData t)
214204 | extensionEnabled Ext_raw_html exts
215− = return (2, B.rawBlock "html" $ T.unpack t)
216− | otherwise = do -- try parsing the HTML
217− Pandoc _ bls <- readHtml opts t
218− return (1, B.fromList bls)
205+ = return $ B.rawBlock "html" $ T.unpack t
206+ | otherwise = return mempty
219207
220− dataBlock ("text/latex", TextualData t) =
221− return $ if extensionEnabled Ext_raw_tex exts
222− then (2, B.rawBlock "latex" $ T.unpack t)
223− else (0, mempty)
208+ dataBlock ("text/latex", TextualData t)
209+ | extensionEnabled Ext_raw_tex exts
210+ = return $ B.rawBlock "latex" $ T.unpack t
211+ | otherwise = return mempty
224212
225213 dataBlock ("text/plain", TextualData t) =
226− return (0, B.codeBlock $ T.unpack t)
214+ return $ B.codeBlock $ T.unpack t
227215
228216 dataBlock (_, JsonData v) =
229− return (2, B.codeBlockWith ("",["json"],[]) $ toStringLazy $ encode v)
217+ return $ B.codeBlockWith ("",["json"],[]) $ toStringLazy $ encode v
230218
231− dataBlock _ = return (0, mempty)
219+ dataBlock _ = return mempty
232220
233221jsonMetaToMeta :: JSONMeta -> M.Map String MetaValue
234222jsonMetaToMeta = M.mapKeys T.unpack . M.map valueToMetaValue