From 612e6555a99368a6cab06334f4596a005855c77b Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Wed, 27 Mar 2019 18:04:00 -0700 Subject: ipynb writer: preserve nbformat_minor if it's given. This helps with round-tripping. --- src/Text/Pandoc/Writers/Ipynb.hs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/Text') 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 -- cgit v1.2.3