git.iko.soy/typeable/pandoc
on master help sign in
ipynb writer: preserve nbformat_minor if it's given.
612e655John MacFarlane
src/Text/Pandoc/Writers/Ipynb.hs+10−2
@@ -62,8 +62,16 @@ pandocToNotebook opts (Pandoc meta blocks) = do
62 opts{ writerTemplate = Nothing } (Pandoc nullMeta [Plain ils])
62 opts{ writerTemplate = Nothing } (Pandoc nullMeta [Plain ils])
63 let jupyterMeta =
63 let jupyterMeta =
64 case lookupMeta "jupyter" meta of
64 case lookupMeta "jupyter" meta of
65− Just (MetaMap m) -> (Meta m <> B.deleteMeta "jupyter" meta)
65+ Just (MetaMap m) -> Meta m
66 _ -> mempty
66 _ -> mempty
67+ let nbformat =
68+ case (lookupMeta "nbformat" jupyterMeta,
69+ lookupMeta "nbformat_minor" jupyterMeta) of
70+ (Just (MetaString "4"), Just (MetaString y)) ->
71+ case safeRead y of
72+ Just z -> (4, z)
73+ Nothing -> (4, 5)
74+ _ -> (4, 5) -- write as v4.5
67 metadata' <- metaToJSON' blockWriter inlineWriter $
75 metadata' <- metaToJSON' blockWriter inlineWriter $
68 B.deleteMeta "nbformat" $
76 B.deleteMeta "nbformat" $
69 B.deleteMeta "nbformat_minor" $ jupyterMeta
77 B.deleteMeta "nbformat_minor" $ jupyterMeta
@@ -74,7 +82,7 @@ pandocToNotebook opts (Pandoc meta blocks) = do
74 cells <- extractCells opts blocks
82 cells <- extractCells opts blocks
75 return $ Notebook{
83 return $ Notebook{
76 notebookMetadata = metadata
84 notebookMetadata = metadata
77− , notebookFormat = (4, 5)
85+ , notebookFormat = nbformat
78 , notebookCells = cells }
86 , notebookCells = cells }
79
87
80addAttachment :: PandocMonad m
88addAttachment :: PandocMonad m