Copyright | Copyright (C) 2019 John MacFarlane |
---|---|
License | BSD3 |
Maintainer | John MacFarlane <jgm@berkeley.edu> |
Stability | alpha |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
Data structure and JSON serializers for ipynb (Jupyter notebook) format. Version 4 of the format is documented here: https://nbformat.readthedocs.io/en/latest/format_description.html.
The library supports both version 4 ('Notebook NbV4') and version 3
('Notebook NbV3') of nbformat. Note that this is a phantom type: the
NbV3
or NbV4
parameter only affects JSON serialization,
not the data structure itself. So code that manipulates
notebooks can be polymorphic, operating on `Notebook a`.
Synopsis
- data Notebook a = Notebook {
- notebookMetadata :: JSONMeta
- notebookFormat :: (Int, Int)
- notebookCells :: [Cell a]
- data NbV3
- data NbV4
- type JSONMeta = Map Text Value
- data Cell a = Cell {
- cellType :: CellType a
- cellSource :: Source
- cellMetadata :: JSONMeta
- cellAttachments :: Maybe (Map Text MimeBundle)
- newtype Source = Source {}
- data CellType a
- = Markdown
- | Heading {
- headingLevel :: Int
- | Raw
- | Code {
- codeExecutionCount :: Maybe Int
- codeOutputs :: [Output a]
- data Output a
- = Stream {
- streamName :: Text
- streamText :: Source
- | DisplayData { }
- | ExecuteResult { }
- | Err { }
- = Stream {
- type MimeType = Text
- data MimeData
- newtype MimeBundle = MimeBundle {}
- breakLines :: Text -> [Text]
Documentation
A Jupyter notebook.
Notebook | |
|
Instances
Eq (Notebook a) Source # | |
Show (Notebook a) Source # | |
Generic (Notebook a) Source # | |
Semigroup (Notebook a) Source # | |
Monoid (Notebook a) Source # | |
ToJSON (Notebook NbV4) Source # | |
ToJSON (Notebook NbV3) Source # | |
FromJSON (Notebook NbV4) Source # | |
FromJSON (Notebook NbV3) Source # | |
type Rep (Notebook a) Source # | |
Defined in Data.Ipynb type Rep (Notebook a) = D1 (MetaData "Notebook" "Data.Ipynb" "ipynb-0.1.0.1-340DlaLihPdGTM9Vs2R3XB" False) (C1 (MetaCons "Notebook" PrefixI True) (S1 (MetaSel (Just "notebookMetadata") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 JSONMeta) :*: (S1 (MetaSel (Just "notebookFormat") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Int, Int)) :*: S1 (MetaSel (Just "notebookCells") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Cell a])))) |
Indexes Notebook
for serialization as nbformat version 3.
Indexes Notebook
for serialization as nbformat version 4.
A Jupyter notebook cell.
Cell | |
|
Instances
Eq (Cell a) Source # | |
Show (Cell a) Source # | |
Generic (Cell a) Source # | |
ToJSON (Cell NbV4) Source # | |
ToJSON (Cell NbV3) Source # | |
FromJSON (Cell NbV4) Source # | |
FromJSON (Cell NbV3) Source # | |
type Rep (Cell a) Source # | |
Defined in Data.Ipynb type Rep (Cell a) = D1 (MetaData "Cell" "Data.Ipynb" "ipynb-0.1.0.1-340DlaLihPdGTM9Vs2R3XB" False) (C1 (MetaCons "Cell" PrefixI True) ((S1 (MetaSel (Just "cellType") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (CellType a)) :*: S1 (MetaSel (Just "cellSource") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Source)) :*: (S1 (MetaSel (Just "cellMetadata") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 JSONMeta) :*: S1 (MetaSel (Just "cellAttachments") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Maybe (Map Text MimeBundle)))))) |
A Source
is a textual content which may be
represented in JSON either as a single string
or as a list of strings (which are concatenated).
Information about the type of a notebook cell, plus
data specific to that type. note that Heading
is
for v3 only; a Heading
will be rendered as Markdown
in v4.
Markdown | |
Heading | |
| |
Raw | |
Code | |
|
Instances
Eq (CellType a) Source # | |
Show (CellType a) Source # | |
Generic (CellType a) Source # | |
type Rep (CellType a) Source # | |
Defined in Data.Ipynb type Rep (CellType a) = D1 (MetaData "CellType" "Data.Ipynb" "ipynb-0.1.0.1-340DlaLihPdGTM9Vs2R3XB" False) ((C1 (MetaCons "Markdown" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "Heading" PrefixI True) (S1 (MetaSel (Just "headingLevel") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Int))) :+: (C1 (MetaCons "Raw" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "Code" PrefixI True) (S1 (MetaSel (Just "codeExecutionCount") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Maybe Int)) :*: S1 (MetaSel (Just "codeOutputs") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Output a])))) |
Output from a Code cell.
Instances
Data in an execution result or display data cell.
Instances
Eq MimeData Source # | |
Show MimeData Source # | |
Generic MimeData Source # | |
type Rep MimeData Source # | |
Defined in Data.Ipynb type Rep MimeData = D1 (MetaData "MimeData" "Data.Ipynb" "ipynb-0.1.0.1-340DlaLihPdGTM9Vs2R3XB" False) (C1 (MetaCons "BinaryData" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 ByteString)) :+: (C1 (MetaCons "TextualData" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Text)) :+: C1 (MetaCons "JsonData" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Value)))) |
newtype MimeBundle Source #
A MimeBundle
wraps a map from mime types to mime data.
Instances
breakLines :: Text -> [Text] Source #
Break up a string into a list of strings, each representing one line of the string (including trailing newline if any).