-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrisify.py
More file actions
executable file
·84 lines (66 loc) · 2.2 KB
/
risify.py
File metadata and controls
executable file
·84 lines (66 loc) · 2.2 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env python
import sys
import os
import json
import subprocess
filename = sys.argv[-1]
basename = os.path.basename(filename).split(".")[0]
with open(sys.argv[-1], "r+") as f:
data = json.load(f)
# Add rise metadata if it does not exist
data["metadata"]["rise"] = {
"footer": "<img src='https://github.com/daytum/logos/blob/master/daytum_logo_2019.png?raw=true' width='220'>",
"progress": True,
"scroll": True,
"theme": "simple",
"slideNumber": False,
"auto_select": None,
"enable_chalkboard": False,
"controls": True,
}
# Can be changed to True if you wish the slides to autolaunch
if basename != "index":
data["metadata"]["rise"]["autolaunch"] = False
new_cell_list = []
for cell in data["cells"]:
# Again, switch to True if you want to hide *all* code cells
if "code" in cell:
if "metadata" not in cell:
cell["metadata"] = {}
cell["metadata"]["hide_input"] = False
# If there is a javascript last cell already in the group of cells, exclude
# it from the new list we are constructing, because we are going to add it to
# the end next.
if "javascript_last_cell" not in cell["metadata"]:
new_cell_list += [cell]
# Construct our last cell which we will embed javascript into the remove the In/Out tags
# from the notebook.
hide_cell = {
"cell_type": "code",
"metadata": {
"hide_input": True,
"init_cell": True,
"javascript_last_cell": True,
},
"execution_count": 0,
"outputs": [],
"source": [
"""%%javascript
function hideElements(elements, start) {
for(var i = 0, length = elements.length; i < length;i++) {
if(i >= start) {
elements[i].style.display = \"none\";
}
}
}
var prompt_elements = document.getElementsByClassName(\"prompt\");
hideElements(prompt_elements, 0)"""
],
}
# Add the hide_cell code to the end.
new_cell_list += [hide_cell]
data["cells"] = new_cell_list
f.seek(0)
json.dump(data, f)
f.truncate()
os.system("jupyter trust " + sys.argv[-1])