##// END OF EJS Templates
Add IPython Notebook exporter
Julia Evans -
Show More
@@ -0,0 +1,36 b''
1 """IPython Notebook Exporter class"""
2
3 #-----------------------------------------------------------------------------
4 # Copyright (c) 2013, the IPython Development Team.
5 #
6 # Distributed under the terms of the Modified BSD License.
7 #
8 # The full license is in the file COPYING.txt, distributed with this software.
9 #-----------------------------------------------------------------------------
10
11 #-----------------------------------------------------------------------------
12 # Imports
13 #-----------------------------------------------------------------------------
14
15 from .exporter import Exporter
16 from IPython.nbformat import current as nbformat
17
18 #-----------------------------------------------------------------------------
19 # Classes
20 #-----------------------------------------------------------------------------
21
22 class NotebookExporter(Exporter):
23 """
24 Exports an IPython notebook.
25 """
26 def _file_extension_default(self):
27 return 'ipynb'
28
29 output_mimetype = 'application/json'
30
31 def from_notebook_node(self, nb, resources=None, **kw):
32 nb_copy, resources = super(NotebookExporter, self).from_notebook_node(nb, resources, **kw)
33 output = nbformat.writes_json(nb_copy)
34 return output, resources
35
36
@@ -0,0 +1,45 b''
1 """
2 Module with tests for notebook.py
3 """
4
5 #-----------------------------------------------------------------------------
6 # Copyright (c) 2013, the IPython Development Team.
7 #
8 # Distributed under the terms of the Modified BSD License.
9 #
10 # The full license is in the file COPYING.txt, distributed with this software.
11 #-----------------------------------------------------------------------------
12
13 #-----------------------------------------------------------------------------
14 # Imports
15 #-----------------------------------------------------------------------------
16
17 from .base import ExportersTestsBase
18 from ..notebook import NotebookExporter
19
20 #-----------------------------------------------------------------------------
21 # Class
22 #-----------------------------------------------------------------------------
23
24 class TestNotebookExporter(ExportersTestsBase):
25 """Contains test functions for notebook.py"""
26
27 exporter_class = NotebookExporter
28
29 def test_constructor(self):
30 """
31 Can a NotebookExporter be constructed?
32 """
33 NotebookExporter()
34
35
36 def test_export(self):
37 """
38 Does the NotebookExporter return the file unchanged?
39 """
40 with open(self._get_notebook()) as f:
41 file_contents = f.read()
42 (output, resources) = NotebookExporter().from_filename(self._get_notebook())
43 assert len(output) > 0
44 assert output == file_contents
45
@@ -18,6 +18,7 b' from .pdf import PDFExporter'
18 from .markdown import MarkdownExporter
18 from .markdown import MarkdownExporter
19 from .python import PythonExporter
19 from .python import PythonExporter
20 from .rst import RSTExporter
20 from .rst import RSTExporter
21 from .notebook import NotebookExporter
21
22
22 #-----------------------------------------------------------------------------
23 #-----------------------------------------------------------------------------
23 # Classes
24 # Classes
@@ -130,6 +131,7 b' exporter_map = dict('
130 markdown=MarkdownExporter,
131 markdown=MarkdownExporter,
131 python=PythonExporter,
132 python=PythonExporter,
132 rst=RSTExporter,
133 rst=RSTExporter,
134 notebook=NotebookExporter,
133 )
135 )
134
136
135 def _make_exporter(name, E):
137 def _make_exporter(name, E):
General Comments 0
You need to be logged in to leave comments. Login now