|
3 | 3 | import sys |
4 | 4 | import glob |
5 | 5 | from os.path import join |
| 6 | +import json |
6 | 7 |
|
7 | 8 | import vitessce |
8 | 9 |
|
@@ -123,9 +124,39 @@ def find_source(): |
123 | 124 | # -- Strip notebook output ------------------------------------------------- |
124 | 125 |
|
125 | 126 |
|
126 | | -for filename in glob.glob(join('notebooks', '*.ipynb'), recursive=True): |
| 127 | +for filename in glob.glob(join('notebooks', "__ipynb__", '*.ipynb'), recursive=True): |
127 | 128 | ntbk = nbclean.NotebookCleaner(filename) |
128 | 129 | ntbk.clear('stderr') |
129 | 130 | ntbk.clear('output') |
130 | 131 | ntbk.remove_cells(empty=True) |
| 132 | + ntbk.remove_cells(search_text="import marimo as mo") |
131 | 133 | ntbk.save(filename) |
| 134 | + |
| 135 | + # Add missing metadata, to enable the code to be interpreted as Python code |
| 136 | + # for syntax highlighting when rendered by nbsphinx. |
| 137 | + with open(filename, 'r') as f: |
| 138 | + ntbk_json = json.load(f) |
| 139 | + with open(filename, 'w') as f: |
| 140 | + if len(ntbk_json['metadata']) == 0: |
| 141 | + # If the metadata is empty, we add the default metadata. |
| 142 | + # This is needed for nbsphinx to render the notebook correctly. |
| 143 | + ntbk_json['metadata'] = { |
| 144 | + "kernelspec": { |
| 145 | + "display_name": "Python 3 (ipykernel)", |
| 146 | + "language": "python", |
| 147 | + "name": "python3" |
| 148 | + }, |
| 149 | + "language_info": { |
| 150 | + "codemirror_mode": { |
| 151 | + "name": "ipython", |
| 152 | + "version": 3 |
| 153 | + }, |
| 154 | + "file_extension": ".py", |
| 155 | + "mimetype": "text/x-python", |
| 156 | + "name": "python", |
| 157 | + "nbconvert_exporter": "python", |
| 158 | + "pygments_lexer": "ipython3", |
| 159 | + "version": "3.10.14" |
| 160 | + } |
| 161 | + } |
| 162 | + json.dump(ntbk_json, f, indent=2) |
0 commit comments