We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
 The `IPython.nbconvert` package has been deprecated.
IPython 4.0 was just released (http://blog.jupyter.org/2015/08/12/first-release-of-jupyter/).  The `IPython.nbconvert` package has been deprecated. The [`nbconvert`-based ipynb compiler](https://github.com/getnikola/nikola/blob/15217bc93f0af0d70ffe33e0ea067d81ddf32403/nikola/plugins/compile/ipynb.py) should be updated where necessary to reflect any API changes in the 4.0 release.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `nikola/plugins/compile/ipynb.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 
3 # Copyright © 2013-2015 Damián Avila, Chris Warrick and others.
4 
5 # Permission is hereby granted, free of charge, to any
6 # person obtaining a copy of this software and associated
7 # documentation files (the "Software"), to deal in the
8 # Software without restriction, including without limitation
9 # the rights to use, copy, modify, merge, publish,
10 # distribute, sublicense, and/or sell copies of the
11 # Software, and to permit persons to whom the Software is
12 # furnished to do so, subject to the following conditions:
13 #
14 # The above copyright notice and this permission notice
15 # shall be included in all copies or substantial portions of
16 # the Software.
17 #
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
21 # PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
22 # OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23 # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24 # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 
27 """Implementation of compile_html based on nbconvert."""
28 
29 from __future__ import unicode_literals, print_function
30 import io
31 import os
32 import sys
33 
34 try:
35     import IPython
36     from IPython.nbconvert.exporters import HTMLExporter
37     if IPython.version_info[0] >= 3:     # API changed with 3.0.0
38         from IPython import nbformat
39         current_nbformat = nbformat.current_nbformat
40         from IPython.kernel import kernelspec
41     else:
42         import IPython.nbformat.current as nbformat
43         current_nbformat = 'json'
44         kernelspec = None
45 
46     from IPython.config import Config
47     flag = True
48 except ImportError:
49     flag = None
50 
51 from nikola.plugin_categories import PageCompiler
52 from nikola.utils import makedirs, req_missing, get_logger, STDERR_HANDLER
53 
54 
55 class CompileIPynb(PageCompiler):
56     """Compile IPynb into HTML."""
57 
58     name = "ipynb"
59     friendly_name = "Jupyter/IPython Notebook"
60     demote_headers = True
61     default_kernel = 'python2' if sys.version_info[0] == 2 else 'python3'
62 
63     def set_site(self, site):
64         """Set Nikola site."""
65         self.logger = get_logger('compile_ipynb', STDERR_HANDLER)
66         super(CompileIPynb, self).set_site(site)
67 
68     def compile_html_string(self, source, is_two_file=True):
69         """Export notebooks as HTML strings."""
70         if flag is None:
71             req_missing(['ipython[notebook]>=2.0.0'], 'build this site (compile ipynb)')
72         HTMLExporter.default_template = 'basic'
73         c = Config(self.site.config['IPYNB_CONFIG'])
74         exportHtml = HTMLExporter(config=c)
75         with io.open(source, "r", encoding="utf8") as in_file:
76             nb_json = nbformat.read(in_file, current_nbformat)
77         (body, resources) = exportHtml.from_notebook_node(nb_json)
78         return body
79 
80     def compile_html(self, source, dest, is_two_file=True):
81         """Compile source file into HTML and save as dest."""
82         makedirs(os.path.dirname(dest))
83         with io.open(dest, "w+", encoding="utf8") as out_file:
84             out_file.write(self.compile_html_string(source, is_two_file))
85 
86     def read_metadata(self, post, file_metadata_regexp=None, unslugify_titles=False, lang=None):
87         """Read metadata directly from ipynb file.
88 
89         As ipynb file support arbitrary metadata as json, the metadata used by Nikola
90         will be assume to be in the 'nikola' subfield.
91         """
92         if flag is None:
93             req_missing(['ipython[notebook]>=2.0.0'], 'build this site (compile ipynb)')
94         source = post.source_path
95         with io.open(source, "r", encoding="utf8") as in_file:
96             nb_json = nbformat.read(in_file, current_nbformat)
97         # Metadata might not exist in two-file posts or in hand-crafted
98         # .ipynb files.
99         return nb_json.get('metadata', {}).get('nikola', {})
100 
101     def create_post(self, path, **kw):
102         """Create a new post."""
103         if flag is None:
104             req_missing(['ipython[notebook]>=2.0.0'], 'build this site (compile ipynb)')
105         content = kw.pop('content', None)
106         onefile = kw.pop('onefile', False)
107         kernel = kw.pop('ipython_kernel', None)
108         # is_page is not needed to create the file
109         kw.pop('is_page', False)
110 
111         metadata = {}
112         metadata.update(self.default_metadata)
113         metadata.update(kw)
114 
115         makedirs(os.path.dirname(path))
116 
117         if content.startswith("{"):
118             # imported .ipynb file, guaranteed to start with "{" because it’s JSON.
119             nb = nbformat.reads(content, current_nbformat)
120         else:
121             if IPython.version_info[0] >= 3:
122                 nb = nbformat.v4.new_notebook()
123                 nb["cells"] = [nbformat.v4.new_markdown_cell(content)]
124             else:
125                 nb = nbformat.new_notebook()
126                 nb["worksheets"] = [nbformat.new_worksheet(cells=[nbformat.new_text_cell('markdown', [content])])]
127 
128             if kernelspec is not None:
129                 if kernel is None:
130                     kernel = self.default_kernel
131                     self.logger.notice('No kernel specified, assuming "{0}".'.format(kernel))
132 
133                 IPYNB_KERNELS = {}
134                 ksm = kernelspec.KernelSpecManager()
135                 for k in ksm.find_kernel_specs():
136                     IPYNB_KERNELS[k] = ksm.get_kernel_spec(k).to_dict()
137                     IPYNB_KERNELS[k]['name'] = k
138                     del IPYNB_KERNELS[k]['argv']
139 
140                 if kernel not in IPYNB_KERNELS:
141                     self.logger.error('Unknown kernel "{0}". Maybe you mispelled it?'.format(kernel))
142                     self.logger.info("Available kernels: {0}".format(", ".join(sorted(IPYNB_KERNELS))))
143                     raise Exception('Unknown kernel "{0}"'.format(kernel))
144 
145                 nb["metadata"]["kernelspec"] = IPYNB_KERNELS[kernel]
146             else:
147                 # Older IPython versions don’t need kernelspecs.
148                 pass
149 
150         if onefile:
151             nb["metadata"]["nikola"] = metadata
152 
153         with io.open(path, "w+", encoding="utf8") as fd:
154             if IPython.version_info[0] >= 3:
155                 nbformat.write(nb, fd, 4)
156             else:
157                 nbformat.write(nb, fd, 'ipynb')
158
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/nikola/plugins/compile/ipynb.py b/nikola/plugins/compile/ipynb.py
--- a/nikola/plugins/compile/ipynb.py
+++ b/nikola/plugins/compile/ipynb.py
@@ -32,21 +32,33 @@
 import sys
 
 try:
-    import IPython
-    from IPython.nbconvert.exporters import HTMLExporter
-    if IPython.version_info[0] >= 3:     # API changed with 3.0.0
-        from IPython import nbformat
-        current_nbformat = nbformat.current_nbformat
-        from IPython.kernel import kernelspec
-    else:
-        import IPython.nbformat.current as nbformat
-        current_nbformat = 'json'
-        kernelspec = None
-
-    from IPython.config import Config
+    from nbconvert.exporters import HTMLExporter
+    import nbformat
+    current_nbformat = nbformat.current_nbformat
+    from jupyter_client import kernelspec
+    from traitlets.config import Config
     flag = True
+    ipy_modern = True
 except ImportError:
-    flag = None
+    try:
+        import IPython
+        from IPython.nbconvert.exporters import HTMLExporter
+        if IPython.version_info[0] >= 3:     # API changed with 3.0.0
+            from IPython import nbformat
+            current_nbformat = nbformat.current_nbformat
+            from IPython.kernel import kernelspec
+            ipy_modern = True
+        else:
+            import IPython.nbformat.current as nbformat
+            current_nbformat = 'json'
+            kernelspec = None
+            ipy_modern = False
+
+        from IPython.config import Config
+        flag = True
+    except ImportError:
+        flag = None
+        ipy_modern = None
 
 from nikola.plugin_categories import PageCompiler
 from nikola.utils import makedirs, req_missing, get_logger, STDERR_HANDLER
@@ -118,7 +130,7 @@
             # imported .ipynb file, guaranteed to start with "{" because it’s JSON.
             nb = nbformat.reads(content, current_nbformat)
         else:
-            if IPython.version_info[0] >= 3:
+            if ipy_modern:
                 nb = nbformat.v4.new_notebook()
                 nb["cells"] = [nbformat.v4.new_markdown_cell(content)]
             else:
@@ -151,7 +163,7 @@
             nb["metadata"]["nikola"] = metadata
 
         with io.open(path, "w+", encoding="utf8") as fd:
-            if IPython.version_info[0] >= 3:
+            if ipy_modern:
                 nbformat.write(nb, fd, 4)
             else:
                 nbformat.write(nb, fd, 'ipynb')

{"golden_diff": "diff --git a/nikola/plugins/compile/ipynb.py b/nikola/plugins/compile/ipynb.py\n--- a/nikola/plugins/compile/ipynb.py\n+++ b/nikola/plugins/compile/ipynb.py\n@@ -32,21 +32,33 @@\n import sys\n \n try:\n-    import IPython\n-    from IPython.nbconvert.exporters import HTMLExporter\n-    if IPython.version_info[0] >= 3:     # API changed with 3.0.0\n-        from IPython import nbformat\n-        current_nbformat = nbformat.current_nbformat\n-        from IPython.kernel import kernelspec\n-    else:\n-        import IPython.nbformat.current as nbformat\n-        current_nbformat = 'json'\n-        kernelspec = None\n-\n-    from IPython.config import Config\n+    from nbconvert.exporters import HTMLExporter\n+    import nbformat\n+    current_nbformat = nbformat.current_nbformat\n+    from jupyter_client import kernelspec\n+    from traitlets.config import Config\n     flag = True\n+    ipy_modern = True\n except ImportError:\n-    flag = None\n+    try:\n+        import IPython\n+        from IPython.nbconvert.exporters import HTMLExporter\n+        if IPython.version_info[0] >= 3:     # API changed with 3.0.0\n+            from IPython import nbformat\n+            current_nbformat = nbformat.current_nbformat\n+            from IPython.kernel import kernelspec\n+            ipy_modern = True\n+        else:\n+            import IPython.nbformat.current as nbformat\n+            current_nbformat = 'json'\n+            kernelspec = None\n+            ipy_modern = False\n+\n+        from IPython.config import Config\n+        flag = True\n+    except ImportError:\n+        flag = None\n+        ipy_modern = None\n \n from nikola.plugin_categories import PageCompiler\n from nikola.utils import makedirs, req_missing, get_logger, STDERR_HANDLER\n@@ -118,7 +130,7 @@\n             # imported .ipynb file, guaranteed to start with \"{\" because it\u2019s JSON.\n             nb = nbformat.reads(content, current_nbformat)\n         else:\n-            if IPython.version_info[0] >= 3:\n+            if ipy_modern:\n                 nb = nbformat.v4.new_notebook()\n                 nb[\"cells\"] = [nbformat.v4.new_markdown_cell(content)]\n             else:\n@@ -151,7 +163,7 @@\n             nb[\"metadata\"][\"nikola\"] = metadata\n \n         with io.open(path, \"w+\", encoding=\"utf8\") as fd:\n-            if IPython.version_info[0] >= 3:\n+            if ipy_modern:\n                 nbformat.write(nb, fd, 4)\n             else:\n                 nbformat.write(nb, fd, 'ipynb')\n", "issue": " The `IPython.nbconvert` package has been deprecated.\nIPython 4.0 was just released (http://blog.jupyter.org/2015/08/12/first-release-of-jupyter/).  The `IPython.nbconvert` package has been deprecated. The [`nbconvert`-based ipynb compiler](https://github.com/getnikola/nikola/blob/15217bc93f0af0d70ffe33e0ea067d81ddf32403/nikola/plugins/compile/ipynb.py) should be updated where necessary to reflect any API changes in the 4.0 release.\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\n# Copyright \u00a9 2013-2015 Dami\u00e1n Avila, Chris Warrick and others.\n\n# Permission is hereby granted, free of charge, to any\n# person obtaining a copy of this software and associated\n# documentation files (the \"Software\"), to deal in the\n# Software without restriction, including without limitation\n# the rights to use, copy, modify, merge, publish,\n# distribute, sublicense, and/or sell copies of the\n# Software, and to permit persons to whom the Software is\n# furnished to do so, subject to the following conditions:\n#\n# The above copyright notice and this permission notice\n# shall be included in all copies or substantial portions of\n# the Software.\n#\n# THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY\n# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE\n# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR\n# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS\n# OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR\n# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n\"\"\"Implementation of compile_html based on nbconvert.\"\"\"\n\nfrom __future__ import unicode_literals, print_function\nimport io\nimport os\nimport sys\n\ntry:\n    import IPython\n    from IPython.nbconvert.exporters import HTMLExporter\n    if IPython.version_info[0] >= 3:     # API changed with 3.0.0\n        from IPython import nbformat\n        current_nbformat = nbformat.current_nbformat\n        from IPython.kernel import kernelspec\n    else:\n        import IPython.nbformat.current as nbformat\n        current_nbformat = 'json'\n        kernelspec = None\n\n    from IPython.config import Config\n    flag = True\nexcept ImportError:\n    flag = None\n\nfrom nikola.plugin_categories import PageCompiler\nfrom nikola.utils import makedirs, req_missing, get_logger, STDERR_HANDLER\n\n\nclass CompileIPynb(PageCompiler):\n    \"\"\"Compile IPynb into HTML.\"\"\"\n\n    name = \"ipynb\"\n    friendly_name = \"Jupyter/IPython Notebook\"\n    demote_headers = True\n    default_kernel = 'python2' if sys.version_info[0] == 2 else 'python3'\n\n    def set_site(self, site):\n        \"\"\"Set Nikola site.\"\"\"\n        self.logger = get_logger('compile_ipynb', STDERR_HANDLER)\n        super(CompileIPynb, self).set_site(site)\n\n    def compile_html_string(self, source, is_two_file=True):\n        \"\"\"Export notebooks as HTML strings.\"\"\"\n        if flag is None:\n            req_missing(['ipython[notebook]>=2.0.0'], 'build this site (compile ipynb)')\n        HTMLExporter.default_template = 'basic'\n        c = Config(self.site.config['IPYNB_CONFIG'])\n        exportHtml = HTMLExporter(config=c)\n        with io.open(source, \"r\", encoding=\"utf8\") as in_file:\n            nb_json = nbformat.read(in_file, current_nbformat)\n        (body, resources) = exportHtml.from_notebook_node(nb_json)\n        return body\n\n    def compile_html(self, source, dest, is_two_file=True):\n        \"\"\"Compile source file into HTML and save as dest.\"\"\"\n        makedirs(os.path.dirname(dest))\n        with io.open(dest, \"w+\", encoding=\"utf8\") as out_file:\n            out_file.write(self.compile_html_string(source, is_two_file))\n\n    def read_metadata(self, post, file_metadata_regexp=None, unslugify_titles=False, lang=None):\n        \"\"\"Read metadata directly from ipynb file.\n\n        As ipynb file support arbitrary metadata as json, the metadata used by Nikola\n        will be assume to be in the 'nikola' subfield.\n        \"\"\"\n        if flag is None:\n            req_missing(['ipython[notebook]>=2.0.0'], 'build this site (compile ipynb)')\n        source = post.source_path\n        with io.open(source, \"r\", encoding=\"utf8\") as in_file:\n            nb_json = nbformat.read(in_file, current_nbformat)\n        # Metadata might not exist in two-file posts or in hand-crafted\n        # .ipynb files.\n        return nb_json.get('metadata', {}).get('nikola', {})\n\n    def create_post(self, path, **kw):\n        \"\"\"Create a new post.\"\"\"\n        if flag is None:\n            req_missing(['ipython[notebook]>=2.0.0'], 'build this site (compile ipynb)')\n        content = kw.pop('content', None)\n        onefile = kw.pop('onefile', False)\n        kernel = kw.pop('ipython_kernel', None)\n        # is_page is not needed to create the file\n        kw.pop('is_page', False)\n\n        metadata = {}\n        metadata.update(self.default_metadata)\n        metadata.update(kw)\n\n        makedirs(os.path.dirname(path))\n\n        if content.startswith(\"{\"):\n            # imported .ipynb file, guaranteed to start with \"{\" because it\u2019s JSON.\n            nb = nbformat.reads(content, current_nbformat)\n        else:\n            if IPython.version_info[0] >= 3:\n                nb = nbformat.v4.new_notebook()\n                nb[\"cells\"] = [nbformat.v4.new_markdown_cell(content)]\n            else:\n                nb = nbformat.new_notebook()\n                nb[\"worksheets\"] = [nbformat.new_worksheet(cells=[nbformat.new_text_cell('markdown', [content])])]\n\n            if kernelspec is not None:\n                if kernel is None:\n                    kernel = self.default_kernel\n                    self.logger.notice('No kernel specified, assuming \"{0}\".'.format(kernel))\n\n                IPYNB_KERNELS = {}\n                ksm = kernelspec.KernelSpecManager()\n                for k in ksm.find_kernel_specs():\n                    IPYNB_KERNELS[k] = ksm.get_kernel_spec(k).to_dict()\n                    IPYNB_KERNELS[k]['name'] = k\n                    del IPYNB_KERNELS[k]['argv']\n\n                if kernel not in IPYNB_KERNELS:\n                    self.logger.error('Unknown kernel \"{0}\". Maybe you mispelled it?'.format(kernel))\n                    self.logger.info(\"Available kernels: {0}\".format(\", \".join(sorted(IPYNB_KERNELS))))\n                    raise Exception('Unknown kernel \"{0}\"'.format(kernel))\n\n                nb[\"metadata\"][\"kernelspec\"] = IPYNB_KERNELS[kernel]\n            else:\n                # Older IPython versions don\u2019t need kernelspecs.\n                pass\n\n        if onefile:\n            nb[\"metadata\"][\"nikola\"] = metadata\n\n        with io.open(path, \"w+\", encoding=\"utf8\") as fd:\n            if IPython.version_info[0] >= 3:\n                nbformat.write(nb, fd, 4)\n            else:\n                nbformat.write(nb, fd, 'ipynb')\n", "path": "nikola/plugins/compile/ipynb.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n\n# Copyright \u00a9 2013-2015 Dami\u00e1n Avila, Chris Warrick and others.\n\n# Permission is hereby granted, free of charge, to any\n# person obtaining a copy of this software and associated\n# documentation files (the \"Software\"), to deal in the\n# Software without restriction, including without limitation\n# the rights to use, copy, modify, merge, publish,\n# distribute, sublicense, and/or sell copies of the\n# Software, and to permit persons to whom the Software is\n# furnished to do so, subject to the following conditions:\n#\n# The above copyright notice and this permission notice\n# shall be included in all copies or substantial portions of\n# the Software.\n#\n# THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY\n# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE\n# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR\n# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS\n# OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR\n# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n\"\"\"Implementation of compile_html based on nbconvert.\"\"\"\n\nfrom __future__ import unicode_literals, print_function\nimport io\nimport os\nimport sys\n\ntry:\n    from nbconvert.exporters import HTMLExporter\n    import nbformat\n    current_nbformat = nbformat.current_nbformat\n    from jupyter_client import kernelspec\n    from traitlets.config import Config\n    flag = True\n    ipy_modern = True\nexcept ImportError:\n    try:\n        import IPython\n        from IPython.nbconvert.exporters import HTMLExporter\n        if IPython.version_info[0] >= 3:     # API changed with 3.0.0\n            from IPython import nbformat\n            current_nbformat = nbformat.current_nbformat\n            from IPython.kernel import kernelspec\n            ipy_modern = True\n        else:\n            import IPython.nbformat.current as nbformat\n            current_nbformat = 'json'\n            kernelspec = None\n            ipy_modern = False\n\n        from IPython.config import Config\n        flag = True\n    except ImportError:\n        flag = None\n        ipy_modern = None\n\nfrom nikola.plugin_categories import PageCompiler\nfrom nikola.utils import makedirs, req_missing, get_logger, STDERR_HANDLER\n\n\nclass CompileIPynb(PageCompiler):\n    \"\"\"Compile IPynb into HTML.\"\"\"\n\n    name = \"ipynb\"\n    friendly_name = \"Jupyter/IPython Notebook\"\n    demote_headers = True\n    default_kernel = 'python2' if sys.version_info[0] == 2 else 'python3'\n\n    def set_site(self, site):\n        \"\"\"Set Nikola site.\"\"\"\n        self.logger = get_logger('compile_ipynb', STDERR_HANDLER)\n        super(CompileIPynb, self).set_site(site)\n\n    def compile_html_string(self, source, is_two_file=True):\n        \"\"\"Export notebooks as HTML strings.\"\"\"\n        if flag is None:\n            req_missing(['ipython[notebook]>=2.0.0'], 'build this site (compile ipynb)')\n        HTMLExporter.default_template = 'basic'\n        c = Config(self.site.config['IPYNB_CONFIG'])\n        exportHtml = HTMLExporter(config=c)\n        with io.open(source, \"r\", encoding=\"utf8\") as in_file:\n            nb_json = nbformat.read(in_file, current_nbformat)\n        (body, resources) = exportHtml.from_notebook_node(nb_json)\n        return body\n\n    def compile_html(self, source, dest, is_two_file=True):\n        \"\"\"Compile source file into HTML and save as dest.\"\"\"\n        makedirs(os.path.dirname(dest))\n        with io.open(dest, \"w+\", encoding=\"utf8\") as out_file:\n            out_file.write(self.compile_html_string(source, is_two_file))\n\n    def read_metadata(self, post, file_metadata_regexp=None, unslugify_titles=False, lang=None):\n        \"\"\"Read metadata directly from ipynb file.\n\n        As ipynb file support arbitrary metadata as json, the metadata used by Nikola\n        will be assume to be in the 'nikola' subfield.\n        \"\"\"\n        if flag is None:\n            req_missing(['ipython[notebook]>=2.0.0'], 'build this site (compile ipynb)')\n        source = post.source_path\n        with io.open(source, \"r\", encoding=\"utf8\") as in_file:\n            nb_json = nbformat.read(in_file, current_nbformat)\n        # Metadata might not exist in two-file posts or in hand-crafted\n        # .ipynb files.\n        return nb_json.get('metadata', {}).get('nikola', {})\n\n    def create_post(self, path, **kw):\n        \"\"\"Create a new post.\"\"\"\n        if flag is None:\n            req_missing(['ipython[notebook]>=2.0.0'], 'build this site (compile ipynb)')\n        content = kw.pop('content', None)\n        onefile = kw.pop('onefile', False)\n        kernel = kw.pop('ipython_kernel', None)\n        # is_page is not needed to create the file\n        kw.pop('is_page', False)\n\n        metadata = {}\n        metadata.update(self.default_metadata)\n        metadata.update(kw)\n\n        makedirs(os.path.dirname(path))\n\n        if content.startswith(\"{\"):\n            # imported .ipynb file, guaranteed to start with \"{\" because it\u2019s JSON.\n            nb = nbformat.reads(content, current_nbformat)\n        else:\n            if ipy_modern:\n                nb = nbformat.v4.new_notebook()\n                nb[\"cells\"] = [nbformat.v4.new_markdown_cell(content)]\n            else:\n                nb = nbformat.new_notebook()\n                nb[\"worksheets\"] = [nbformat.new_worksheet(cells=[nbformat.new_text_cell('markdown', [content])])]\n\n            if kernelspec is not None:\n                if kernel is None:\n                    kernel = self.default_kernel\n                    self.logger.notice('No kernel specified, assuming \"{0}\".'.format(kernel))\n\n                IPYNB_KERNELS = {}\n                ksm = kernelspec.KernelSpecManager()\n                for k in ksm.find_kernel_specs():\n                    IPYNB_KERNELS[k] = ksm.get_kernel_spec(k).to_dict()\n                    IPYNB_KERNELS[k]['name'] = k\n                    del IPYNB_KERNELS[k]['argv']\n\n                if kernel not in IPYNB_KERNELS:\n                    self.logger.error('Unknown kernel \"{0}\". Maybe you mispelled it?'.format(kernel))\n                    self.logger.info(\"Available kernels: {0}\".format(\", \".join(sorted(IPYNB_KERNELS))))\n                    raise Exception('Unknown kernel \"{0}\"'.format(kernel))\n\n                nb[\"metadata\"][\"kernelspec\"] = IPYNB_KERNELS[kernel]\n            else:\n                # Older IPython versions don\u2019t need kernelspecs.\n                pass\n\n        if onefile:\n            nb[\"metadata\"][\"nikola\"] = metadata\n\n        with io.open(path, \"w+\", encoding=\"utf8\") as fd:\n            if ipy_modern:\n                nbformat.write(nb, fd, 4)\n            else:\n                nbformat.write(nb, fd, 'ipynb')\n", "path": "nikola/plugins/compile/ipynb.py"}]}