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.
This commit is contained in:
parent
9abb458cbb
commit
85afbc7c6b
1 changed files with 14 additions and 26 deletions
|
@ -169,23 +169,14 @@ outputToBlock _ Err{ errName = ename,
|
||||||
-- the output format.
|
-- the output format.
|
||||||
handleData :: PandocMonad m
|
handleData :: PandocMonad m
|
||||||
=> ReaderOptions -> JSONMeta -> MimeBundle -> m B.Blocks
|
=> ReaderOptions -> JSONMeta -> MimeBundle -> m B.Blocks
|
||||||
handleData opts metadata (MimeBundle mb) = do
|
handleData opts metadata (MimeBundle mb) =
|
||||||
let mimePairs = M.toList mb
|
mconcat <$> mapM dataBlock (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
|
|
||||||
|
|
||||||
where
|
where
|
||||||
|
|
||||||
exts = readerExtensions opts
|
exts = readerExtensions opts
|
||||||
|
|
||||||
dataBlock :: PandocMonad m => (MimeType, MimeData) -> m (Int, B.Blocks)
|
dataBlock :: PandocMonad m => (MimeType, MimeData) -> m B.Blocks
|
||||||
dataBlock (mt, BinaryData bs)
|
dataBlock (mt, BinaryData bs)
|
||||||
| "image/" `T.isPrefixOf` mt
|
| "image/" `T.isPrefixOf` mt
|
||||||
= do
|
= do
|
||||||
|
@ -206,29 +197,26 @@ handleData opts metadata (MimeBundle mb) = do
|
||||||
Nothing -> ""
|
Nothing -> ""
|
||||||
Just ext -> '.':ext
|
Just ext -> '.':ext
|
||||||
insertMedia fname (Just mt') bl
|
insertMedia fname (Just mt') bl
|
||||||
return (3, B.para $ B.imageWith ("",[],metaPairs) fname "" mempty)
|
return $ B.para $ B.imageWith ("",[],metaPairs) fname "" mempty
|
||||||
|
| otherwise = return mempty
|
||||||
dataBlock (_, BinaryData _) = return (0, mempty)
|
|
||||||
|
|
||||||
dataBlock ("text/html", TextualData t)
|
dataBlock ("text/html", TextualData t)
|
||||||
| extensionEnabled Ext_raw_html exts
|
| extensionEnabled Ext_raw_html exts
|
||||||
= return (2, B.rawBlock "html" $ T.unpack t)
|
= return $ B.rawBlock "html" $ T.unpack t
|
||||||
| otherwise = do -- try parsing the HTML
|
| otherwise = return mempty
|
||||||
Pandoc _ bls <- readHtml opts t
|
|
||||||
return (1, B.fromList bls)
|
|
||||||
|
|
||||||
dataBlock ("text/latex", TextualData t) =
|
dataBlock ("text/latex", TextualData t)
|
||||||
return $ if extensionEnabled Ext_raw_tex exts
|
| extensionEnabled Ext_raw_tex exts
|
||||||
then (2, B.rawBlock "latex" $ T.unpack t)
|
= return $ B.rawBlock "latex" $ T.unpack t
|
||||||
else (0, mempty)
|
| otherwise = return mempty
|
||||||
|
|
||||||
dataBlock ("text/plain", TextualData t) =
|
dataBlock ("text/plain", TextualData t) =
|
||||||
return (0, B.codeBlock $ T.unpack t)
|
return $ B.codeBlock $ T.unpack t
|
||||||
|
|
||||||
dataBlock (_, JsonData v) =
|
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 :: JSONMeta -> M.Map String MetaValue
|
||||||
jsonMetaToMeta = M.mapKeys T.unpack . M.map valueToMetaValue
|
jsonMetaToMeta = M.mapKeys T.unpack . M.map valueToMetaValue
|
||||||
|
|
Loading…
Reference in a new issue