aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Readers/Ipynb.hs17
-rw-r--r--src/Text/Pandoc/Writers/Ipynb.hs13
2 files changed, 16 insertions, 14 deletions
diff --git a/src/Text/Pandoc/Readers/Ipynb.hs b/src/Text/Pandoc/Readers/Ipynb.hs
index 13550d9a1..156e6bb8d 100644
--- a/src/Text/Pandoc/Readers/Ipynb.hs
+++ b/src/Text/Pandoc/Readers/Ipynb.hs
@@ -18,6 +18,7 @@ Ipynb (Jupyter notebook JSON format) reader for pandoc.
module Text.Pandoc.Readers.Ipynb ( readIpynb )
where
import Prelude
+import Data.Char (isDigit)
import Data.List (isPrefixOf)
import Data.Maybe (fromMaybe)
import Data.Digest.Pure.SHA (sha1, showDigest)
@@ -39,6 +40,7 @@ import qualified Data.ByteString.Lazy as BL
import Data.Aeson as Aeson
import Control.Monad.Except (throwError)
import Text.Pandoc.Readers.Markdown (readMarkdown)
+import qualified Text.Pandoc.UTF8 as UTF8
readIpynb :: PandocMonad m => ReaderOptions -> Text -> m Pandoc
readIpynb opts t = do
@@ -217,10 +219,11 @@ jsonMetaToMeta = M.mapKeys T.unpack . M.map valueToMetaValue
valueToMetaValue Aeson.Null = MetaString ""
jsonMetaToPairs :: JSONMeta -> [(String, String)]
-jsonMetaToPairs = M.toList . M.mapMaybe
- (\case
- MetaString s -> Just s
- MetaBool True -> Just "true"
- MetaBool False -> Just "false"
- -- for now we skip complex cell metadata:
- _ -> Nothing) . jsonMetaToMeta
+jsonMetaToPairs = M.toList . M.mapKeys T.unpack . M.map
+ (\case
+ String t
+ | not (T.all isDigit t)
+ , t /= "true"
+ , t /= "false"
+ -> T.unpack t
+ x -> UTF8.toStringLazy $ Aeson.encode x)
diff --git a/src/Text/Pandoc/Writers/Ipynb.hs b/src/Text/Pandoc/Writers/Ipynb.hs
index 661f585f4..0babf7112 100644
--- a/src/Text/Pandoc/Writers/Ipynb.hs
+++ b/src/Text/Pandoc/Writers/Ipynb.hs
@@ -213,10 +213,9 @@ extractData bs = do
pairsToJSONMeta :: [(String, String)] -> JSONMeta
pairsToJSONMeta kvs =
- M.fromList [(T.pack k, case v of
- "true" -> Bool True
- "false" -> Bool False
- _ -> case safeRead v of
- Just n -> Number n
- _ -> String (T.pack v))
- | (k,v) <- kvs , k /= "execution_count" ]
+ M.fromList [(T.pack k, case Aeson.decode (UTF8.fromStringLazy v) of
+ Just val -> val
+ Nothing -> String (T.pack v))
+ | (k,v) <- kvs
+ , k /= "execution_count"
+ ]