From 9aba5d3234fac9fc9bb198b950c60a8d3e2e0015 2013-01-28 21:47:37 From: Matthias BUSSONNIER Date: 2013-01-28 21:47:37 Subject: [PATCH] start rst converter --- diff --git a/converters/template.py b/converters/template.py index 162c4c7..5e55ec0 100755 --- a/converters/template.py +++ b/converters/template.py @@ -21,6 +21,8 @@ from converters.jinja_filters import (python_comment, indent, rm_fake, remove_ansi, markdown, highlight, ansi2html, markdown2latex, escape_tex) +from converters.utils import markdown2rst + # Stdlib imports @@ -199,6 +201,7 @@ class ConverterTemplate(Configurable): self.env.filters['highlight'] = highlight self.env.filters['ansi2html'] = ansi2html self.env.filters['markdown2latex'] = markdown2latex + self.env.filters['markdown2rst'] = markdown2rst for k, v in jinja_filters.iteritems(): self.env.filters[k] = v diff --git a/profile/rst.nbcv b/profile/rst.nbcv new file mode 100644 index 0000000..03ee0b7 --- /dev/null +++ b/profile/rst.nbcv @@ -0,0 +1,7 @@ +c = get_config() + +c.ConverterTemplate.extract_figures=False +c.ConverterTemplate.template_file='rst' +c.ConverterTemplate.tex_environement=False + +c.NbconvertApp.fileext='rst' diff --git a/templates/rst.tpl b/templates/rst.tpl new file mode 100644 index 0000000..3400bde --- /dev/null +++ b/templates/rst.tpl @@ -0,0 +1,69 @@ +{%- extends 'null.tpl' -%} + +{% block in_prompt -%} +In[{{cell.prompt_number if cell.prompt_number else ' '}}]: + +.. code:: python + +{% endblock in_prompt %} + +{% block output_prompt %} +Out[{{cell.prompt_number}}]:{% 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 + +#} +{% block pyerr %}{{ super() }} +{% endblock pyerr %} + +{% block traceback_line %} +{{ line |indent| rm_ansi }}{% endblock traceback_line %} +{# .... #} + + +{% block pyout %} +.. parsed-literal:: + +{{ output.text| indent }} +{% endblock pyout %} + +{% block stream %} +.. parsed-literal:: + +{{ output.text| indent }} +{% endblock stream %} + + + + +{% block display_data scoped %} +# image file: +{% endblock display_data %} + +{% block markdowncell scoped %} +{{ cell.source | markdown2rst }} +{% endblock markdowncell %} + +{% block headingcell scoped %} +{%- set len = cell.source|length -%} +{{ cell.source}} +{% if cell.level == 1 %} +{{- '=' * len }} +{%- elif cell.level == 2 %} +{{- '-' * len }} +{% endif %} +{% endblock headingcell %} + +{% block rawcell scoped %} +{{ cell.source }} +{% endblock rawcell %} + +{% block unknowncell scoped %} +unknown type {{cell.type}} +{% endblock unknowncell %}