-
Notifications
You must be signed in to change notification settings - Fork 213
/
config.py
43 lines (31 loc) · 1.05 KB
/
config.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
# coding: utf-8
from nbconvert.preprocessors import Preprocessor
def _all_tags(nb):
rv = set()
for cell in nb.cells:
tags = cell.metadata.get("tags")
if tags:
for tag in tags:
rv.add(tag)
return rv
class ExercisePreprocessor(Preprocessor):
keep_tags = {"setup", "exercise"}
def preprocess(self, nb, resources):
cells = []
for cell in nb.cells:
tags = cell.metadata.get("tags", tuple())
if any(tag in self.keep_tags for tag in tags):
# must check if cell.cell_type == 'code'
# cell.execution_count = None
# cell.outputs = []
cells.append(cell)
nb.cells = cells
nb.metadata.pop("celltoolbar", None)
nb.metadata.pop("toc", None)
return nb, resources
c = get_config() # noqa
c.Exporter.preprocessors = [
ExercisePreprocessor,
"nbconvert.preprocessors.TagRemovePreprocessor",
"nbconvert.preprocessors.ClearOutputPreprocessor",
]