diff --git a/converters/template.py b/converters/template.py index c3853f3..aae868d 100755 --- a/converters/template.py +++ b/converters/template.py @@ -97,6 +97,6 @@ class ConverterTemplate(Configurable): def read(self, filename): "read and parse notebook into NotebookNode called self.nb" - with open(filename) as f: + with io.open(filename) as f: self.nb = nbformat.read(f, 'json') diff --git a/runme.py b/runme.py index 35e10f3..c919f45 100755 --- a/runme.py +++ b/runme.py @@ -1,9 +1,10 @@ #!/usr/bin/env python # coding: utf-8 +from __future__ import print_function import sys import io from converters.template import * C = ConverterTemplate(tplfile=sys.argv[1]) C.read('tests/ipynbref/IntroNumPy.orig.ipynb') -print C.convert() +print(C.convert().encode('utf-8')) diff --git a/templates/python.tpl b/templates/python.tpl index 8576f9f..49eaa43 100644 --- a/templates/python.tpl +++ b/templates/python.tpl @@ -1,27 +1,43 @@ {%- extends 'null.tpl' -%} {% block in_prompt %} -# In[{{cell.prompt_number if cell.prompt_number else ' '}}]:{% endblock in_prompt %} +# In[{{cell.prompt_number if cell.prompt_number else ' '}}]: +{% endblock in_prompt %} + +{% block output_prompt %} +# Out[{{cell.prompt_number}}]:{% endblock output_prompt %} + +{% block input %}{{ cell.input }} +{% endblock input %} + + +{# Those Two are for error displaying +even if the first one seem to do nothing, +it introduces a new line + +#} +{% block pyerr %}{{ super() }} +{% endblock pyerr %} {% block traceback_line %} -{{ line |indent| rm_ansi }} -{% endblock traceback_line %} +{{ line |indent| rm_ansi }}{% endblock traceback_line %} +{# .... #} {% block pyout %} -{{ output.text| indent | pycomment}}{% endblock pyout %} +{{ output.text| indent | pycomment}} +{% endblock pyout %} {% block stream %} {{ output.text| indent | pycomment}} {% endblock stream %} -{% block output_prompt %}# Out[{{cell.prompt_number}}]:{% endblock output_prompt %} -{% block input %}{{ cell.input }}{% endblock input %} {% block display_data scoped %} -# image file:{% endblock display_data %} +# image file: +{% endblock display_data %} {% block markdowncell scoped %} {{ cell.source | pycomment }}