diff --git a/nbconvert/exporters/tests/test_asciidoc.py b/nbconvert/exporters/tests/test_asciidoc.py index be08077b4..9fb20be47 100644 --- a/nbconvert/exporters/tests/test_asciidoc.py +++ b/nbconvert/exporters/tests/test_asciidoc.py @@ -12,13 +12,19 @@ # Imports #----------------------------------------------------------------------------- +import re + +from traitlets.config import Config +from ipython_genutils.testing import decorators as dec + from .base import ExportersTestsBase from ..asciidoc import ASCIIDocExporter -from ipython_genutils.testing import decorators as dec #----------------------------------------------------------------------------- # Class #----------------------------------------------------------------------------- +in_regex = r"In\[(.*)\]:" +out_regex = r"Out\[(.*)\]:" class TestASCIIDocExporter(ExportersTestsBase): """Tests for ASCIIDocExporter""" @@ -39,3 +45,25 @@ def test_export(self): """ (output, resources) = ASCIIDocExporter().from_filename(self._get_notebook()) assert len(output) > 0 + + assert re.findall(in_regex, output) + assert re.findall(out_regex, output) + + @dec.onlyif_cmds_exist('pandoc') + def test_export_no_prompt(self): + """ + Can a ASCIIDocExporter export something without prompts? + """ + no_prompt = { + "TemplateExporter":{ + "exclude_input_prompt": True, + "exclude_output_prompt": True, + } + } + c_no_prompt = Config(no_prompt) + exporter = ASCIIDocExporter(config=c_no_prompt) + (output, resources) = exporter.from_filename( + self._get_notebook(nb_name="prompt_numbers.ipynb")) + + assert not re.findall(in_regex, output) + assert not re.findall(out_regex, output) diff --git a/nbconvert/exporters/tests/test_html.py b/nbconvert/exporters/tests/test_html.py index c7d5b20a5..1a771e023 100644 --- a/nbconvert/exporters/tests/test_html.py +++ b/nbconvert/exporters/tests/test_html.py @@ -3,10 +3,13 @@ # Copyright (c) IPython Development Team. # Distributed under the terms of the Modified BSD License. +import re + from .base import ExportersTestsBase from ..html import HTMLExporter + +from traitlets.config import Config from nbformat import v4 -import re class TestHTMLExporter(ExportersTestsBase): @@ -59,6 +62,26 @@ def test_prompt_number(self): assert re.findall(in_regex, output) == ins assert re.findall(out_regex, output) == outs + + def test_prompt_number(self): + """ + Does HTMLExporter properly format input and output prompts? + """ + no_prompt_conf = Config( + {"TemplateExporter":{ + "exclude_input_prompt": True, + "exclude_output_prompt": True, + } + } + ) + exporter = HTMLExporter(config=no_prompt_conf, template_file='full') + (output, resources) = exporter.from_filename( + self._get_notebook(nb_name="prompt_numbers.ipynb")) + in_regex = r"In \[(.*)\]:" + out_regex = r"Out\[(.*)\]:" + + assert not re.findall(in_regex, output) + assert not re.findall(out_regex, output) def test_png_metadata(self): """ diff --git a/nbconvert/exporters/tests/test_latex.py b/nbconvert/exporters/tests/test_latex.py index 17a33851c..b58273293 100644 --- a/nbconvert/exporters/tests/test_latex.py +++ b/nbconvert/exporters/tests/test_latex.py @@ -9,6 +9,8 @@ from .base import ExportersTestsBase from ..latex import LatexExporter + +from traitlets.config import Config from nbformat import write from nbformat import v4 from ipython_genutils.testing.decorators import onlyif_cmds_exist @@ -117,6 +119,22 @@ def test_prompt_number_color(self): assert re.findall(in_regex, output) == ins assert re.findall(out_regex, output) == outs + @onlyif_cmds_exist('pandoc') + def test_no_prompt_yes_input(self): + no_prompt = { + "TemplateExporter":{ + "exclude_input_prompt": True, + "exclude_output_prompt": True, + } + } + c_no_prompt = Config(no_prompt) + + exporter = LatexExporter(config=c_no_prompt) + (output, resources) = exporter.from_filename( + self._get_notebook(nb_name="prompt_numbers.ipynb")) + assert "shape" in output + assert "evs" in output + def test_in_memory_template_tplx(self): # Loads in an in memory latex template (.tplx) using jinja2.DictLoader # creates a class that uses this template with the template_file argument diff --git a/nbconvert/templates/html/basic.tpl b/nbconvert/templates/html/basic.tpl index eaec1f701..9159415ab 100644 --- a/nbconvert/templates/html/basic.tpl +++ b/nbconvert/templates/html/basic.tpl @@ -23,21 +23,17 @@ {% block in_prompt -%}
-{%- if cell.execution_count is defined -%} -{%- if resources.global_content_filter.include_input_prompt-%} -In [{{ cell.execution_count|replace(None, " ") }}]: -{%- else -%} -In [ ]: -{%- endif -%} -{%- endif -%} + {%- if cell.execution_count is defined -%} + In [{{ cell.execution_count|replace(None, " ") }}]: + {%- else -%} + In [ ]: + {%- endif -%}
{%- endblock in_prompt %} {% block empty_in_prompt -%} -{%- if resources.global_content_filter.include_input_prompt-%}
-{% endif %} {%- endblock empty_in_prompt %} {# @@ -51,26 +47,28 @@ In [ ]:
{{ cell.source | highlight_code(metadata=cell.metadata) }} -
+
{%- endblock input %} -{% block output %} -
-{% if resources.global_content_filter.include_output_prompt %} {% block output_area_prompt %} {%- if output.output_type == 'execute_result' -%}
-{%- if cell.execution_count is defined -%} - Out[{{ cell.execution_count|replace(None, " ") }}]: -{%- else -%} - Out[ ]: -{%- endif -%} + {%- if cell.execution_count is defined -%} + Out[{{ cell.execution_count|replace(None, " ") }}]: + {%- else -%} + Out[ ]: + {%- endif -%} {%- else -%}
{%- endif -%}
{% endblock output_area_prompt %} + +{% block output %} +
+{% if resources.global_content_filter.include_output_prompt %} + {{ self.output_area_prompt() }} {% endif %} {{ super() }}
@@ -79,7 +77,7 @@ In [ ]: {% block markdowncell scoped %}
{%- if resources.global_content_filter.include_input_prompt-%} -{{ self.empty_in_prompt() }} + {{ self.empty_in_prompt() }} {%- endif -%}
@@ -97,7 +95,7 @@ unknown type {{ cell.type }} {%- set extra_class="output_execute_result" -%} {% block data_priority scoped %} {{ super() }} -{% endblock %} +{% endblock data_priority %} {%- set extra_class="" -%} {%- endblock execute_result %} diff --git a/nbconvert/templates/latex/style_bw_ipython.tplx b/nbconvert/templates/latex/style_bw_ipython.tplx index 9309f9196..43ccc5563 100644 --- a/nbconvert/templates/latex/style_bw_ipython.tplx +++ b/nbconvert/templates/latex/style_bw_ipython.tplx @@ -9,6 +9,8 @@ ((* block input scoped *)) ((*- if resources.global_content_filter.include_input_prompt *)) ((( add_prompt(cell.source, cell, 'In ') ))) +((* else *)) +(((cell.source))) ((* endif -*)) ((* endblock input *)) @@ -25,6 +27,12 @@ ((*- else -*)) \verb+Out[((( cell.execution_count )))]:+((( super() ))) ((*- endif -*)) + ((*- else -*)) + ((*- if type in ['text/plain'] *)) +((( output.data['text/plain'] ))) + ((*- else -*)) +\verb+((( super() ))) + ((*- endif -*)) ((*- endif -*)) ((*- endfor -*)) ((* endblock execute_result *)) diff --git a/nbconvert/templates/latex/style_ipython.tplx b/nbconvert/templates/latex/style_ipython.tplx index 7a3ab8c3b..10f01a80b 100644 --- a/nbconvert/templates/latex/style_ipython.tplx +++ b/nbconvert/templates/latex/style_ipython.tplx @@ -22,6 +22,8 @@ ((* block input scoped *)) ((*- if resources.global_content_filter.include_input_prompt *)) ((( add_prompt(cell.source | highlight_code(strip_verbatim=True, metadata=cell.metadata), cell, 'In ', 'incolor') ))) +((*- else *)) + ((( cell.source | highlight_code(strip_verbatim=True, metadata=cell.metadata) ))) ((* endif *)) ((* endblock input *)) @@ -38,6 +40,12 @@ ((* else -*)) \texttt{\color{outcolor}Out[{\color{outcolor}((( cell.execution_count )))}]:}((( super() ))) ((*- endif -*)) + ((*- else -*)) + ((*- if type in ['text/plain'] *)) +((( output.data['text/plain'] | escape_latex ))) + ((* else -*)) +((( super() ))) + ((*- endif -*)) ((*- endif -*)) ((*- endfor -*)) ((* endblock execute_result *))