aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2019-03-27 18:04:00 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2019-03-27 18:04:20 -0700
commit612e6555a99368a6cab06334f4596a005855c77b (patch)
tree4976374453f46a610203574ed87e514087c8a783 /src
parent6157f7ec4f549f5db3406f86cb37d6047d2483fc (diff)
downloadpandoc-612e6555a99368a6cab06334f4596a005855c77b.tar.gz
ipynb writer: preserve nbformat_minor if it's given.
This helps with round-tripping.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Writers/Ipynb.hs12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Writers/Ipynb.hs b/src/Text/Pandoc/Writers/Ipynb.hs
index 0babf7112..40248ed5a 100644
--- a/src/Text/Pandoc/Writers/Ipynb.hs
+++ b/src/Text/Pandoc/Writers/Ipynb.hs
@@ -62,8 +62,16 @@ pandocToNotebook opts (Pandoc meta blocks) = do
opts{ writerTemplate = Nothing } (Pandoc nullMeta [Plain ils])
let jupyterMeta =
case lookupMeta "jupyter" meta of
- Just (MetaMap m) -> (Meta m <> B.deleteMeta "jupyter" meta)
+ Just (MetaMap m) -> Meta m
_ -> mempty
+ let nbformat =
+ case (lookupMeta "nbformat" jupyterMeta,
+ lookupMeta "nbformat_minor" jupyterMeta) of
+ (Just (MetaString "4"), Just (MetaString y)) ->
+ case safeRead y of
+ Just z -> (4, z)
+ Nothing -> (4, 5)
+ _ -> (4, 5) -- write as v4.5
metadata' <- metaToJSON' blockWriter inlineWriter $
B.deleteMeta "nbformat" $
B.deleteMeta "nbformat_minor" $ jupyterMeta
@@ -74,7 +82,7 @@ pandocToNotebook opts (Pandoc meta blocks) = do
cells <- extractCells opts blocks
return $ Notebook{
notebookMetadata = metadata
- , notebookFormat = (4, 5)
+ , notebookFormat = nbformat
, notebookCells = cells }
addAttachment :: PandocMonad m