##// END OF EJS Templates
simple custom converter
Jonathan Taylor -
Show More
@@ -1,32 +1,27 b''
1 import os, copy
1 """
2 This module gives a simple example of a custom notebook converter taht only
3 captures display data and deletes the cell inputs.
4 """
2
5
6 import copy
3 import nbconvert as nb
7 import nbconvert as nb
4 import json
5 from decorators import DocInherit
6
7 from IPython.external import argparse
8 from IPython.nbformat import current as nbformat
9 from IPython.nbformat.v3.nbjson import from_dict, rejoin_lines, BytesEncoder
10 from IPython.utils.text import indent
11 from IPython.utils import py3compat
12
13
8
14 class CustomNotebookConverter(nb.ConverterNotebook):
9 class CustomNotebookConverter(nb.ConverterNotebook):
15
10
16 def render_code(self, cell):
11 def render_code(self, cell):
17
12
18 captured_outputs = ['text', 'html', 'svg', 'latex', 'javascript']
13 captured_outputs = ['text', 'html', 'svg', 'latex', 'javascript']
19
14
20 cell = copy.deepcopy(cell)
15 cell = copy.deepcopy(cell)
21 cell['input'] = ''
16 cell['input'] = ''
22
17
23 for output in cell.outputs:
18 for output in cell.outputs:
24 if output.output_type != 'display_data':
19 if output.output_type != 'display_data':
25 cell.outputs.remove(output)
20 cell.outputs.remove(output)
26 return nb.ConverterNotebook.render_code(self, cell)
21 return nb.ConverterNotebook.render_code(self, cell)
27
22
28 if __name__ == '__main__':
23 if __name__ == '__main__':
29 infile = 'tests/test_display.ipynb'
24 infile = 'tests/test_display.ipynb'
30 converter = CustomNotebookConverter(infile, 'test_only_display')
25 converter = CustomNotebookConverter(infile, 'test_only_display')
31 converter.render()
26 converter.render()
32
27
General Comments 0
You need to be logged in to leave comments. Login now