From e92c5c87d87234c63c3833e8e3dad6d6baaf9a25 2013-02-13 19:30:12 From: Matthias BUSSONNIER Date: 2013-02-13 19:30:12 Subject: [PATCH] create rst converter and fix some bugs --- diff --git a/converters/template.py b/converters/template.py index 5e55ec0..1dc0747 100755 --- a/converters/template.py +++ b/converters/template.py @@ -166,6 +166,7 @@ class ConverterTemplate(Configurable): for fmt in self.display_data_priority: if fmt in output: return [fmt] + raise Exception("did not found any format I can extract in output, shoudl at lest have one") preprocessors = [] diff --git a/converters/transformers.py b/converters/transformers.py index f1fd294..6c803c6 100755 --- a/converters/transformers.py +++ b/converters/transformers.py @@ -127,7 +127,6 @@ class ExtractFigureTransformer(ConfigurableTransformers): for type in self.display_data_priority: if out.hasattr(type): figname, key, data = self._new_figure(out[type], type, count) - cell.outputs[i][type] = figname out['key_'+type] = figname other['figures'][key] = data count = count+1 diff --git a/profile/rst.nbcv b/profile/rst.nbcv index 03ee0b7..bb7d9e2 100644 --- a/profile/rst.nbcv +++ b/profile/rst.nbcv @@ -1,7 +1,13 @@ c = get_config() -c.ConverterTemplate.extract_figures=False +c.ConverterTemplate.extract_figures=True c.ConverterTemplate.template_file='rst' c.ConverterTemplate.tex_environement=False c.NbconvertApp.fileext='rst' +c.ExtractFigureTransformer.enabled=True + +c.ExtractFigureTransformer.display_data_priority=['svg', 'png', 'latex', 'jpg', 'jpeg','text'] +c.ConverterTemplate.display_data_priority=['svg', 'png', 'latex', 'jpg', 'jpeg','text'] + + diff --git a/templates/rst.tpl b/templates/rst.tpl index 3400bde..a4341da 100644 --- a/templates/rst.tpl +++ b/templates/rst.tpl @@ -1,5 +1,4 @@ -{%- extends 'null.tpl' -%} - +{%- extends 'display_priority.tpl' -%} {% block in_prompt -%} In[{{cell.prompt_number if cell.prompt_number else ' '}}]: @@ -7,25 +6,18 @@ In[{{cell.prompt_number if cell.prompt_number else ' '}}]: {% endblock in_prompt %} -{% block output_prompt %} -Out[{{cell.prompt_number}}]:{% endblock output_prompt %} +{% block output_prompt %}{% if cell.haspyout -%} +Out[{{cell.prompt_number}}]:{% endif %}{% endblock output_prompt %} {% block input %}{{ cell.input | indent}} -{% endblock input %} - -{# Those Two are for error displaying -even if the first one seem to do nothing, -it introduces a new line +{% endblock input %} -#} {% block pyerr %}{{ super() }} {% endblock pyerr %} {% block traceback_line %} {{ line |indent| rm_ansi }}{% endblock traceback_line %} -{# .... #} - {% block pyout %} .. parsed-literal:: @@ -42,12 +34,21 @@ it introduces a new line -{% block display_data scoped %} -# image file: -{% endblock display_data %} +{% block data_svg %}.. image:: {{output.key_svg}} + +{% endblock data_svg %} -{% block markdowncell scoped %} -{{ cell.source | markdown2rst }} +{% block data_png %}.. image:: {{output.key_png}} + +{% endblock data_png %} + +{% block data_text scoped %}.. parsed-literal:: + +{{output.text | indent}} + +{% endblock data_text %} + +{% block markdowncell scoped %}{{ cell.source | markdown2rst }} {% endblock markdowncell %} {% block headingcell scoped %} @@ -58,10 +59,10 @@ it introduces a new line {%- elif cell.level == 2 %} {{- '-' * len }} {% endif %} + {% endblock headingcell %} -{% block rawcell scoped %} -{{ cell.source }} +{% block rawcell scoped %}{{ cell.source }} {% endblock rawcell %} {% block unknowncell scoped %}