Commit 975008b8 authored by Jonas Juselius's avatar Jonas Juselius

Fix convert lhs -> ipynb v4 json.

parent 6d7b9129
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE CPP #-}
module IHaskell.Convert.LhsToIpynb (lhsToIpynb) where module IHaskell.Convert.LhsToIpynb (lhsToIpynb) where
import Control.Applicative ((<$>)) import Control.Applicative ((<$>))
...@@ -47,9 +48,8 @@ data Cell a = Code a a | Markdown a ...@@ -47,9 +48,8 @@ data Cell a = Code a a | Markdown a
encodeCells :: [Cell [T.Text]] -> Value encodeCells :: [Cell [T.Text]] -> Value
encodeCells xs = object $ encodeCells xs = object $
[ "worksheets" .= Array (V.singleton (object [ "cells" .= Array (V.fromList (map cellToVal xs)) ]
[ "cells" .= Array (V.fromList (map cellToVal xs)) ] )) ++ boilerplate
] ++ boilerplate
cellToVal :: Cell [T.Text] -> Value cellToVal :: Cell [T.Text] -> Value
cellToVal (Code i o) = object $ cellToVal (Code i o) = object $
...@@ -57,7 +57,7 @@ cellToVal (Code i o) = object $ ...@@ -57,7 +57,7 @@ cellToVal (Code i o) = object $
"collapsed" .= Bool False, "collapsed" .= Bool False,
"language" .= String "python", -- is what it IPython gives us "language" .= String "python", -- is what it IPython gives us
"metadata" .= object [], "metadata" .= object [],
"input" .= arrayFromTxt i, "source" .= arrayFromTxt i,
"outputs" .= Array "outputs" .= Array
(V.fromList ( (V.fromList (
[ object ["text" .= arrayFromTxt o, [ object ["text" .= arrayFromTxt o,
...@@ -78,9 +78,20 @@ arrayFromTxt i = Array (V.fromList (map (String . T.toStrict) i)) ...@@ -78,9 +78,20 @@ arrayFromTxt i = Array (V.fromList (map (String . T.toStrict) i))
-- json describing cells and output correctly. -- json describing cells and output correctly.
boilerplate :: [(TS.Text, Value)] boilerplate :: [(TS.Text, Value)]
boilerplate = boilerplate =
[ "metadata" .= object [ "language" .= String "haskell", "name" .= String ""], [ "metadata" .= object [ kernelspec, lang ]
"nbformat" .= Number 3, , "nbformat" .= Number 4
"nbformat_minor" .= Number 0 ] , "nbformat_minor" .= Number 0
]
where
kernelspec = "kernelspec" .= object [
"display_name" .= String "Haskell"
, "language" .= String "haskell"
, "name" .= String "haskell"
]
lang = "language_info" .= object [
"name" .= String "haskell"
, "version" .= String VERSION_ghc
]
groupClassified :: [CellLine T.Text] -> [Cell [T.Text]] groupClassified :: [CellLine T.Text] -> [Cell [T.Text]]
groupClassified (CodeLine a : x) groupClassified (CodeLine a : x)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment