From 2f54470266813866d30a68a75ee98c0de58fcd8d Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Thu, 24 Jan 2019 16:51:56 -0800 Subject: Ipynb: Put all jupyter metadata under 'jupyter' key. --- src/Text/Pandoc/Readers/Ipynb.hs | 2 +- src/Text/Pandoc/Writers/Ipynb.hs | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'src/Text/Pandoc') diff --git a/src/Text/Pandoc/Readers/Ipynb.hs b/src/Text/Pandoc/Readers/Ipynb.hs index 2497e6a0a..ad0652ed0 100644 --- a/src/Text/Pandoc/Readers/Ipynb.hs +++ b/src/Text/Pandoc/Readers/Ipynb.hs @@ -83,7 +83,7 @@ notebookToPandoc opts notebook = do _ -> "python" bs <- mconcat <$> mapM (cellToBlocks opts lang) cells let Pandoc _ blocks = B.doc bs - return $ Pandoc (Meta m) blocks + return $ Pandoc (Meta $ M.insert "jupyter" (MetaMap m) mempty) blocks cellToBlocks :: PandocMonad m => ReaderOptions -> String -> Cell a -> m B.Blocks diff --git a/src/Text/Pandoc/Writers/Ipynb.hs b/src/Text/Pandoc/Writers/Ipynb.hs index c9d71e180..509e60aa0 100644 --- a/src/Text/Pandoc/Writers/Ipynb.hs +++ b/src/Text/Pandoc/Writers/Ipynb.hs @@ -77,9 +77,14 @@ pandocToNotebook opts (Pandoc meta blocks) = do opts{ writerTemplate = Nothing } (Pandoc nullMeta bs) let inlineWriter ils = T.stripEnd <$> writeMarkdown opts{ writerTemplate = Nothing } (Pandoc nullMeta [Plain ils]) + let jupyterMeta = + case lookupMeta "jupyter" meta of + Just (MetaMap m) -> (Meta m <> B.deleteMeta "jupyter" meta) + _ -> meta metadata' <- metaToJSON' blockWriter inlineWriter $ B.deleteMeta "nbformat" $ - B.deleteMeta "nbformat_minor" $ meta + B.deleteMeta "nbformat_minor" $ jupyterMeta + -- convert from a Value (JSON object) to a M.Map Text Value: let metadata = case fromJSON metadata' of Error _ -> mempty -- TODO warning here? shouldn't happen Success x -> x -- cgit v1.2.3