/
formats.py
70 lines (62 loc) · 2.26 KB
/
formats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# -----------------------------------------------------------------------------
# Copyright (C) Jupyter Development Team
#
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
# -----------------------------------------------------------------------------
def default_formats():
"""
Return the currently-implemented formats.
These are not classes, but maybe should be: would they survive pickling?
- exporter:
an Exporter subclass.
if not defined, and key is in nbconvert.export.exporter_map, it will be added
automatically
- nbconvert_template:
the name of the nbconvert template to add to config.ExporterClass
- test:
a function(notebook_object, notebook_json)
conditionally offer a format based on content if truthy. see
`RenderingHandler.filter_exporters`
- postprocess:
a function(html, resources)
perform any modifications to html and resources after nbconvert
- content_Type:
a string specifying the Content-Type of the response from this format.
Defaults to text/html; charset=UTF-8
"""
def test_slides(nb, json):
"""Determines if at least one cell has a non-blank or "-" as its
metadata.slideshow.slide_type value.
Parameters
----------
nb: nbformat.notebooknode.NotebookNode
Top of the parsed notebook object model
json: str
JSON source of the notebook, unused
Returns
-------
bool
"""
for cell in nb.cells:
if (
"metadata" in cell
and "slideshow" in cell.metadata
and cell.metadata.slideshow.get("slide_type", "-") != "-"
):
return True
return False
return {
"html": {"nbconvert_template": "lab", "label": "Notebook", "icon": "book"},
"slides": {
# "nbconvert_template": "slides_reveal",
"label": "Slides",
"icon": "gift",
"test": test_slides,
},
"script": {
"label": "Code",
"icon": "code",
"content_type": "text/plain; charset=UTF-8",
},
}