Skip to content

Commit 7ab61f3

Browse files
committedMar 8, 2016
Merge pull request #21 from julienr/attachments
Add a new attachment property for cells.
2 parents 2b99adc + da965ca commit 7ab61f3

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed
 

‎docs/format_description.rst

+30
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ stream output
155155
The ``stream`` key was changed to ``name`` to match
156156
the stream message.
157157

158+
.. _display-data:
158159

159160
display_data
160161
************
@@ -291,6 +292,35 @@ regardless of format.
291292
"source" : "[some nbformat output text]"
292293
}
293294

295+
296+
Cell attachments
297+
----------------
298+
.. versionadded:: 4.1
299+
300+
Markdown and raw cells can have a number of attachments, typically inline
301+
images that can be referenced in the markdown content of a cell. The ``attachments``
302+
dictionary of a cell contains a set of mime-bundles (see :ref:`display_data`)
303+
keyed by filename that represents the files attached to the cell.
304+
305+
.. note::
306+
307+
The ``attachments`` dictionary is an optional field and can be undefined or empty if the cell does not have any attachments.
308+
309+
310+
.. sourcecode:: python
311+
312+
{
313+
"cell_type" : "markdown",
314+
"metadata" : {},
315+
"source" : ["Here is an *inline* image ![inline image](attachment:test.png)"],
316+
"attachments" : {
317+
"test.png": {
318+
"image/png" : ["base64-encoded-png-data"],
319+
},
320+
},
321+
}
322+
323+
294324
Backward-compatible changes
295325
===========================
296326

‎nbformat/v4/nbbase.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
# Change this when incrementing the nbformat version
1515
nbformat = 4
16-
nbformat_minor = 0
16+
nbformat_minor = 1
1717
nbformat_schema = 'nbformat.v4.schema.json'
1818

1919

‎nbformat/v4/nbformat.v4.schema.json

+12
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
"tags": {"$ref": "#/definitions/misc/metadata_tags"}
114114
}
115115
},
116+
"attachments": {"$ref": "#/definitions/misc/attachments"},
116117
"source": {"$ref": "#/definitions/misc/source"}
117118
}
118119
},
@@ -136,6 +137,7 @@
136137
},
137138
"additionalProperties": true
138139
},
140+
"attachments": {"$ref": "#/definitions/misc/attachments"},
139141
"source": {"$ref": "#/definitions/misc/source"}
140142
}
141143
},
@@ -327,6 +329,16 @@
327329
"pattern": "^[^,]+$"
328330
}
329331
},
332+
"attachments": {
333+
"description": "Media attachments (e.g. inline images), stored as mimebundle keyed by filename.",
334+
"type": "object",
335+
"patternProperties": {
336+
".*": {
337+
"description": "The attachment's data stored as a mimebundle.",
338+
"$ref": "#/definitions/misc/mimebundle"
339+
}
340+
}
341+
},
330342
"source": {
331343
"description": "Contents of the cell, represented as an array of lines.",
332344
"$ref": "#/definitions/misc/multiline_string"

0 commit comments

Comments
 (0)
Please sign in to comment.