Skip to content

Commit

Permalink
Merge pull request #21 from julienr/attachments
Browse files Browse the repository at this point in the history
Add a new attachment property for cells.
  • Loading branch information
minrk committed Mar 8, 2016
2 parents 2b99adc + da965ca commit 7ab61f3
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
30 changes: 30 additions & 0 deletions docs/format_description.rst
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ stream output
The ``stream`` key was changed to ``name`` to match
the stream message.

.. _display-data:

display_data
************
Expand Down Expand Up @@ -291,6 +292,35 @@ regardless of format.
"source" : "[some nbformat output text]"
}


Cell attachments
----------------
.. versionadded:: 4.1

Markdown and raw cells can have a number of attachments, typically inline
images that can be referenced in the markdown content of a cell. The ``attachments``
dictionary of a cell contains a set of mime-bundles (see :ref:`display_data`)
keyed by filename that represents the files attached to the cell.

.. note::

The ``attachments`` dictionary is an optional field and can be undefined or empty if the cell does not have any attachments.


.. sourcecode:: python

{
"cell_type" : "markdown",
"metadata" : {},
"source" : ["Here is an *inline* image ![inline image](attachment:test.png)"],
"attachments" : {
"test.png": {
"image/png" : ["base64-encoded-png-data"],
},
},
}


Backward-compatible changes
===========================

Expand Down
2 changes: 1 addition & 1 deletion nbformat/v4/nbbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

# Change this when incrementing the nbformat version
nbformat = 4
nbformat_minor = 0
nbformat_minor = 1
nbformat_schema = 'nbformat.v4.schema.json'


Expand Down
12 changes: 12 additions & 0 deletions nbformat/v4/nbformat.v4.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
"tags": {"$ref": "#/definitions/misc/metadata_tags"}
}
},
"attachments": {"$ref": "#/definitions/misc/attachments"},
"source": {"$ref": "#/definitions/misc/source"}
}
},
Expand All @@ -136,6 +137,7 @@
},
"additionalProperties": true
},
"attachments": {"$ref": "#/definitions/misc/attachments"},
"source": {"$ref": "#/definitions/misc/source"}
}
},
Expand Down Expand Up @@ -327,6 +329,16 @@
"pattern": "^[^,]+$"
}
},
"attachments": {
"description": "Media attachments (e.g. inline images), stored as mimebundle keyed by filename.",
"type": "object",
"patternProperties": {
".*": {
"description": "The attachment's data stored as a mimebundle.",
"$ref": "#/definitions/misc/mimebundle"
}
}
},
"source": {
"description": "Contents of the cell, represented as an array of lines.",
"$ref": "#/definitions/misc/multiline_string"
Expand Down

0 comments on commit 7ab61f3

Please sign in to comment.