/** * [[include:src/codecs/ipynb/README.md]] * * @module codecs/ipynb */ import schema from '@stencila/schema'; import * as vfile from '../../util/vfile'; import { Codec } from '../types'; import * as nbformat3 from './nbformat-v3'; import * as nbformat4 from './nbformat-v4'; /** * Additional type definitions not generated from JSON Schemas * or required for decoding based on format version. */ declare namespace nbformat { /** * An enum for the version of notebook being processed. * Used for branching logic in decoding functions below. */ enum Version { v3 = 3, v4 = 4 } namespace v3 { type Cell = nbformat3.RawCell | nbformat3.MarkdownCell | nbformat3.HeadingCell | nbformat3.CodeCell; /** * Types that we need to check for using `isa` typeguard */ interface Types { Notebook: nbformat3.Notebook; Cell: Cell; Pyout: nbformat3.Pyout; DisplayData: nbformat3.DisplayData; } } /** * A multiline string. */ type MultilineString = string | string[]; /** * A mime-type keyed dictionary of data. * * For most MIME types the data is a `MultilineString` but * "Mimetypes with JSON output, can be any type" (source: `nbformat-v4.json.schema`) */ interface MimeBundle { [key: string]: MultilineString | any; } } /** * Type guard for letting Typescript know that node is a v3 type */ export declare function isv3(node: unknown, key: Key, version: nbformat.Version): node is nbformat.v3.Types[Key]; export declare class IpynbCodec extends Codec implements Codec { /** * The media types that this codec can decode/encode. */ readonly mediaTypes: string[]; /** * The file extension names associated with this codec. */ readonly extNames: string[]; /** * Decode a `VFile` with IPYNB content to a Stencila `Node`. * * @param file The `VFile` to decode * @returns A promise that resolves to a Stencila `Node` */ readonly decode: (file: vfile.VFile) => Promise; /** * Encode a Stencila `Node` to a `VFile` with IPYNB content. * * @param thing The Stencila `Node` to encode * @returns A promise that resolves to a `VFile` */ readonly encode: (node: schema.Node) => Promise; } /** * Decode a Jupyter `CodeCell` to a Stencila `CodeChunk`. * * If the cell has no code and no outputs then returns `undefined` (ie. * empty cells are ignored). * * If the cell metadata has a `caption` that is a string it will be attempted * to be decoded as Markdown. */ export declare function decodeCodeCell(cell: nbformat3.CodeCell | nbformat4.CodeCell, version?: nbformat.Version, language?: string): Promise; /** * Encode a Stencila `CodeChunk` as a Jupyter `CodeCell`. */ export declare function encodeCodeChunk(chunk: schema.CodeChunk): Promise; /** * Decode a Jupyter `MultilineString` to a `string`. */ export declare function decodeMultilineString(source: nbformat.MultilineString): string; /** * Encode a `string` as a Jupyter `MultilineString`. */ export declare function encodeMultilineString(source: string): nbformat.MultilineString; export {};