Commit 2edf1e67 authored by Jonas Juselius's avatar Jonas Juselius

Fix lhs to ipynb converter.

The previous commit had missed some of the format changes from v3 to v4.
parent 975008b8
...@@ -3,12 +3,12 @@ ...@@ -3,12 +3,12 @@
module IHaskell.Convert.LhsToIpynb (lhsToIpynb) where module IHaskell.Convert.LhsToIpynb (lhsToIpynb) where
import Control.Applicative ((<$>)) import Control.Applicative ((<$>))
import Data.Aeson ((.=), encode, object, Value(Array, Bool, Number, String)) import Data.Aeson ((.=), encode, object, Value(Array, Bool, Number, String, Null))
import qualified Data.ByteString.Lazy as L (writeFile) import qualified Data.ByteString.Lazy as L (writeFile)
import Data.Char (isSpace) import Data.Char (isSpace)
import Data.Monoid (Monoid(mempty)) import Data.Monoid (Monoid(mempty))
import qualified Data.Text as TS (Text) import qualified Data.Text as TS (Text)
import qualified Data.Text.Lazy as T (dropWhile, lines, stripPrefix, Text, toStrict) import qualified Data.Text.Lazy as T (dropWhile, lines, stripPrefix, Text, toStrict, snoc)
import qualified Data.Text.Lazy.IO as T (readFile) import qualified Data.Text.Lazy.IO as T (readFile)
import qualified Data.Vector as V (fromList, singleton) import qualified Data.Vector as V (fromList, singleton)
import IHaskell.Flags (LhsStyle(LhsStyle)) import IHaskell.Flags (LhsStyle(LhsStyle))
...@@ -54,9 +54,8 @@ encodeCells xs = object $ ...@@ -54,9 +54,8 @@ encodeCells xs = object $
cellToVal :: Cell [T.Text] -> Value cellToVal :: Cell [T.Text] -> Value
cellToVal (Code i o) = object $ cellToVal (Code i o) = object $
[ "cell_type" .= String "code", [ "cell_type" .= String "code",
"collapsed" .= Bool False, "execution_count" .= Null,
"language" .= String "python", -- is what it IPython gives us "metadata" .= object [ "collapsed" .= Bool False ],
"metadata" .= object [],
"source" .= arrayFromTxt i, "source" .= arrayFromTxt i,
"outputs" .= Array "outputs" .= Array
(V.fromList ( (V.fromList (
...@@ -67,12 +66,14 @@ cellToVal (Code i o) = object $ ...@@ -67,12 +66,14 @@ cellToVal (Code i o) = object $
cellToVal (Markdown txt) = object $ cellToVal (Markdown txt) = object $
[ "cell_type" .= String "markdown", [ "cell_type" .= String "markdown",
"metadata" .= object [], "metadata" .= object [ "hidden" .= Bool False ],
"source" .= arrayFromTxt txt ] "source" .= arrayFromTxt txt ]
-- | arrayFromTxt makes a JSON array of string s -- | arrayFromTxt makes a JSON array of string s
arrayFromTxt :: [T.Text] -> Value arrayFromTxt :: [T.Text] -> Value
arrayFromTxt i = Array (V.fromList (map (String . T.toStrict) i)) arrayFromTxt i = Array (V.fromList $ map stringify i)
where
stringify = String . T.toStrict . flip T.snoc '\n'
-- | ihaskell needs this boilerplate at the upper level to interpret the -- | ihaskell needs this boilerplate at the upper level to interpret the
-- json describing cells and output correctly. -- json describing cells and output correctly.
......
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