aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2019-03-30 09:57:43 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2019-03-30 09:57:43 -0700
commit79c82a2550977e391ca60820b6013d23d444bf39 (patch)
treed60ca702f56b678cefa576549088e303f2bf0f04
parent036179e44a73e27563f6365b8c8dd331f10ed7fc (diff)
downloadpandoc-79c82a2550977e391ca60820b6013d23d444bf39.tar.gz
ipynb reader/writer: use format 'ipynb' for raw cell where no format given.
According to nbformat docs, this is supposed to render in every format. We don't do that, but we at least preserve it as a raw block in markdown, so you can round-trip.
-rw-r--r--src/Text/Pandoc/Readers/Ipynb.hs5
-rw-r--r--src/Text/Pandoc/Writers/Ipynb.hs9
2 files changed, 9 insertions, 5 deletions
diff --git a/src/Text/Pandoc/Readers/Ipynb.hs b/src/Text/Pandoc/Readers/Ipynb.hs
index 10f3a0675..04e0b1595 100644
--- a/src/Text/Pandoc/Readers/Ipynb.hs
+++ b/src/Text/Pandoc/Readers/Ipynb.hs
@@ -90,10 +90,11 @@ cellToBlocks opts lang c = do
return $ B.divWith ("",["cell","markdown"],kvs)
$ B.fromList bs
Ipynb.Raw -> do
- let format = fromMaybe "html" $ lookup "format" kvs
+ -- we use ipynb to indicate no format given (a wildcard in nbformat)
+ let format = fromMaybe "ipynb" $ lookup "format" kvs
let format' =
case format of
- "text/html" -> "html"
+ "text/html" -> "html"
"text/latex" -> "latex"
"application/pdf" -> "latex"
"text/markdown" -> "markdown"
diff --git a/src/Text/Pandoc/Writers/Ipynb.hs b/src/Text/Pandoc/Writers/Ipynb.hs
index 2a95f669e..4f088f7fc 100644
--- a/src/Text/Pandoc/Writers/Ipynb.hs
+++ b/src/Text/Pandoc/Writers/Ipynb.hs
@@ -19,6 +19,7 @@ where
import Prelude
import Control.Monad.State
import qualified Data.Map as M
+import Data.Char (toLower)
import Data.Maybe (catMaybes, fromMaybe)
import Text.Pandoc.Options
import Text.Pandoc.Definition
@@ -136,7 +137,7 @@ extractCells opts (Div (_id,classes,kvs) xs : bs)
case consolidateAdjacentRawBlocks xs of
[RawBlock (Format f) raw] -> do
let format' =
- case f of
+ case map toLower f of
"html" -> "text/html"
"revealjs" -> "text/html"
"latex" -> "text/latex"
@@ -146,8 +147,10 @@ extractCells opts (Div (_id,classes,kvs) xs : bs)
(Cell{
cellType = Raw
, cellSource = Source $ breakLines $ T.pack raw
- , cellMetadata = M.insert "format"
- (Aeson.String $ T.pack format') mempty
+ , cellMetadata = if format' == "ipynb" -- means no format given
+ then mempty
+ else M.insert "format"
+ (Aeson.String $ T.pack format') mempty
, cellAttachments = Nothing } :) <$> extractCells opts bs
_ -> extractCells opts bs
extractCells opts (CodeBlock (_id,classes,kvs) raw : bs)