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

Fix convert lhs -> ipynb v4 json.

parent 6d7b9129
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE CPP #-}
module IHaskell.Convert.LhsToIpynb (lhsToIpynb) where
import Control.Applicative ((<$>))
......@@ -47,9 +48,8 @@ data Cell a = Code a a | Markdown a
encodeCells :: [Cell [T.Text]] -> Value
encodeCells xs = object $
[ "worksheets" .= Array (V.singleton (object
[ "cells" .= Array (V.fromList (map cellToVal xs)) ] ))
] ++ boilerplate
[ "cells" .= Array (V.fromList (map cellToVal xs)) ]
++ boilerplate
cellToVal :: Cell [T.Text] -> Value
cellToVal (Code i o) = object $
......@@ -57,7 +57,7 @@ cellToVal (Code i o) = object $
"collapsed" .= Bool False,
"language" .= String "python", -- is what it IPython gives us
"metadata" .= object [],
"input" .= arrayFromTxt i,
"source" .= arrayFromTxt i,
"outputs" .= Array
(V.fromList (
[ object ["text" .= arrayFromTxt o,
......@@ -78,9 +78,20 @@ arrayFromTxt i = Array (V.fromList (map (String . T.toStrict) i))
-- json describing cells and output correctly.
boilerplate :: [(TS.Text, Value)]
boilerplate =
[ "metadata" .= object [ "language" .= String "haskell", "name" .= String ""],
"nbformat" .= Number 3,
"nbformat_minor" .= Number 0 ]
[ "metadata" .= object [ kernelspec, lang ]
, "nbformat" .= Number 4
, "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 (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