diff options
-rw-r--r-- | src/Text/Pandoc/Readers/Ipynb.hs | 3 | ||||
-rw-r--r-- | src/Text/Pandoc/Writers/Ipynb.hs | 7 | ||||
-rw-r--r-- | test/ipynb/simple.out.native | 6 |
3 files changed, 10 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Readers/Ipynb.hs b/src/Text/Pandoc/Readers/Ipynb.hs index a245bdad3..056fa431c 100644 --- a/src/Text/Pandoc/Readers/Ipynb.hs +++ b/src/Text/Pandoc/Readers/Ipynb.hs @@ -79,7 +79,8 @@ cellToBlocks opts lang c = do case cellType c of Ipynb.Markdown -> do Pandoc _ bs <- walk fixImage <$> readMarkdown opts source - return $ B.divWith ("",["cell","markdown"],kvs) + let kvs' = ("source", source) : kvs + return $ B.divWith ("",["cell","markdown"],kvs') $ B.fromList bs Ipynb.Heading lev -> do Pandoc _ bs <- readMarkdown opts diff --git a/src/Text/Pandoc/Writers/Ipynb.hs b/src/Text/Pandoc/Writers/Ipynb.hs index d01d5a7e5..86e2abbdf 100644 --- a/src/Text/Pandoc/Writers/Ipynb.hs +++ b/src/Text/Pandoc/Writers/Ipynb.hs @@ -102,10 +102,13 @@ extractCells _ [] = return [] extractCells opts (Div (_id,classes,kvs) xs : bs) | "cell" `elem` classes , "markdown" `elem` classes = do - let meta = pairsToJSONMeta kvs + let meta = pairsToJSONMeta [(k,v) | (k,v) <- kvs, k /= "source"] (newdoc, attachments) <- runStateT (walkM addAttachment (Pandoc nullMeta xs)) mempty - source <- writeMarkdown opts{ writerTemplate = Nothing } newdoc + source <- case lookup "source" kvs of + Just s -> return s + Nothing -> writeMarkdown opts{ writerTemplate = Nothing } + newdoc (Ipynb.Cell{ cellType = Markdown , cellSource = Source $ breakLines $ T.stripEnd source diff --git a/test/ipynb/simple.out.native b/test/ipynb/simple.out.native index 4c060b82f..960230894 100644 --- a/test/ipynb/simple.out.native +++ b/test/ipynb/simple.out.native @@ -1,15 +1,15 @@ Pandoc (Meta {unMeta = fromList [("jupyter",MetaMap (fromList [("nbformat",MetaString "4"),("nbformat_minor",MetaString "5")]))]}) -[Div ("",["cell","markdown"],[]) +[Div ("",["cell","markdown"],[("source","Lorem ipsum\n===========\n\n**Lorem ipsum** dolor sit amet, consectetur adipiscing elit. Nunc luctus\nbibendum felis dictum sodales.")]) [Header 1 ("lorem-ipsum",[],[]) [Str "Lorem",Space,Str "ipsum"] ,Para [Strong [Str "Lorem",Space,Str "ipsum"],Space,Str "dolor",Space,Str "sit",Space,Str "amet,",Space,Str "consectetur",Space,Str "adipiscing",Space,Str "elit.",Space,Str "Nunc",Space,Str "luctus",SoftBreak,Str "bibendum",Space,Str "felis",Space,Str "dictum",Space,Str "sodales."]] ,Div ("",["cell","code"],[]) [CodeBlock ("",["python"],[]) "print(\"hello\")"] -,Div ("",["cell","markdown"],[]) +,Div ("",["cell","markdown"],[("source","Pyout\n-----")]) [Header 2 ("pyout",[],[]) [Str "Pyout"]] ,Div ("",["cell","code"],[("execution_count","2")]) [CodeBlock ("",["python"],[]) "from IPython.display import HTML\nHTML(\"\"\"\n<script>\nconsole.log(\"hello\");\n</script>\n<b>HTML</b>\n\"\"\")" ,Div ("",["output","execute_result"],[("execution_count","2")]) [RawBlock (Format "html") "<script>\nconsole.log(\"hello\");\n</script>\n<b>HTML</b>\nhello"]] -,Div ("",["cell","markdown"],[("tags","[\"foo\",\"bar\"]")]) +,Div ("",["cell","markdown"],[("source","Image\n-----\n\nThis image ![the moon](attachment:lalune.jpg) will be included as a cell\nattachment."),("tags","[\"foo\",\"bar\"]")]) [Header 2 ("image",[],[]) [Str "Image"] ,Para [Str "This",Space,Str "image",Space,Image ("",[],[]) [Str "the",Space,Str "moon"] ("lalune.jpg",""),Space,Str "will",Space,Str "be",Space,Str "included",Space,Str "as",Space,Str "a",Space,Str "cell",SoftBreak,Str "attachment."]]] |