|
166 | 166 | "source": [ |
167 | 167 | "#| export\n", |
168 | 168 | "def _clean_cell_output(cell, clean_ids, allowed_out_meta_keys):\n", |
169 | | - " \"Remove `cell` output execution count and optionally ids from text reprs\"\n", |
| 169 | + " \"Remove `cell` output execution count, optionally ids from text reprs, and representations listed under `nbdev.strip`\"\n", |
170 | 170 | " outputs = cell.get('outputs', [])\n", |
171 | 171 | " for o in outputs:\n", |
172 | 172 | " if 'execution_count' in o: o['execution_count'] = None\n", |
173 | 173 | " data = o.get('data', {})\n", |
174 | 174 | " data.pop(\"application/vnd.google.colaboratory.intrinsic+json\", None)\n", |
| 175 | + " for k in nested_idx(o, 'metadata', 'nbdev', 'strip') or []: data.pop(k, None)\n", |
175 | 176 | " for k in data:\n", |
176 | 177 | " if k.startswith('text') and clean_ids: data[k] = _clean_cell_output_id(data[k])\n", |
177 | 178 | " if k.startswith('image') and \"svg\" not in k: data[k] = data[k].rstrip()\n", |
|
379 | 380 | "```" |
380 | 381 | ] |
381 | 382 | }, |
| 383 | + { |
| 384 | + "cell_type": "markdown", |
| 385 | + "id": "063fbebb", |
| 386 | + "metadata": {}, |
| 387 | + "source": [ |
| 388 | + "A display object with a large, regenerable representation beside a small one can ask for the large one to be removed on clean. It lists the mimetypes to drop under `nbdev.strip` in the output's metadata, which IPython takes from the second element of a `_repr_mimebundle_` return value. `clean_nb` removes those representations and keeps the others:" |
| 389 | + ] |
| 390 | + }, |
| 391 | + { |
| 392 | + "cell_type": "code", |
| 393 | + "execution_count": null, |
| 394 | + "id": "6148ce9b", |
| 395 | + "metadata": {}, |
| 396 | + "outputs": [], |
| 397 | + "source": [ |
| 398 | + "out = dict(output_type='display_data', metadata={'nbdev': {'strip': ['text/html']}},\n", |
| 399 | + " data={'text/html': '<iframe srcdoc=\"...\"></iframe>', 'text/markdown': '```html\\n<p>Hi</p>\\n```'})\n", |
| 400 | + "_nb = dict2nb(dict(cells=[mk_cell('preview()', outputs=[out])], metadata={}))\n", |
| 401 | + "clean_nb(_nb)\n", |
| 402 | + "test_eq(list(_nb.cells[0].outputs[0].data), ['text/markdown'])" |
| 403 | + ] |
| 404 | + }, |
382 | 405 | { |
383 | 406 | "cell_type": "markdown", |
384 | 407 | "id": "89d0a249", |
|
0 commit comments