From d41a2f835cfcfad753f091f396ac39b44031bf81 Mon Sep 17 00:00:00 2001 From: "Maarten A. Breddels" Date: Tue, 15 Oct 2019 17:01:56 +0200 Subject: [PATCH] add more structure to null.tpl body_header/footer --- .../jupyter/nbconvert/templates/base/null.j2 | 144 +++++++++--------- .../nbconvert/templates/classic/index.html.j2 | 16 +- .../nbconvert/templates/lab/index.html.j2 | 14 +- 3 files changed, 84 insertions(+), 90 deletions(-) diff --git a/share/jupyter/nbconvert/templates/base/null.j2 b/share/jupyter/nbconvert/templates/base/null.j2 index 32886a867..7cc55ea4b 100644 --- a/share/jupyter/nbconvert/templates/base/null.j2 +++ b/share/jupyter/nbconvert/templates/base/null.j2 @@ -24,78 +24,84 @@ consider calling super even if it is a leave block, we might insert more blocks {%- block header -%} {%- endblock header -%} {%- block body -%} -{%- for cell in nb.cells -%} - {%- block any_cell scoped -%} - {%- if cell.cell_type == 'code'-%} - {%- if resources.global_content_filter.include_code -%} - {%- block codecell scoped -%} - {%- if resources.global_content_filter.include_input and not cell.get("transient",{}).get("remove_source", false) -%} - {%- block input_group -%} - {%- if resources.global_content_filter.include_input_prompt -%} - {%- block in_prompt -%}{%- endblock in_prompt -%} - {%- endif -%} - {%- block input -%}{%- endblock input -%} - {%- endblock input_group -%} - {%- endif -%} - {%- if cell.outputs and resources.global_content_filter.include_output -%} - {%- block output_group -%} - {%- if resources.global_content_filter.include_output_prompt -%} - {%- block output_prompt -%}{%- endblock output_prompt -%} + {%- block body_header -%} + {%- endblock body_header -%} + {%- block body_loop -%} + {%- for cell in nb.cells -%} + {%- block any_cell scoped -%} + {%- if cell.cell_type == 'code'-%} + {%- if resources.global_content_filter.include_code -%} + {%- block codecell scoped -%} + {%- if resources.global_content_filter.include_input and not cell.get("transient",{}).get("remove_source", false) -%} + {%- block input_group -%} + {%- if resources.global_content_filter.include_input_prompt -%} + {%- block in_prompt -%}{%- endblock in_prompt -%} + {%- endif -%} + {%- block input -%}{%- endblock input -%} + {%- endblock input_group -%} {%- endif -%} - {%- block outputs scoped -%} - {%- for output in cell.outputs -%} - {%- block output scoped -%} - {%- if output.output_type == 'execute_result' -%} - {%- block execute_result scoped -%}{%- endblock execute_result -%} - {%- elif output.output_type == 'stream' -%} - {%- block stream scoped -%} - {%- if output.name == 'stdout' -%} - {%- block stream_stdout scoped -%} - {%- endblock stream_stdout -%} - {%- elif output.name == 'stderr' -%} - {%- block stream_stderr scoped -%} - {%- endblock stream_stderr -%} + {%- if cell.outputs and resources.global_content_filter.include_output -%} + {%- block output_group -%} + {%- if resources.global_content_filter.include_output_prompt -%} + {%- block output_prompt -%}{%- endblock output_prompt -%} + {%- endif -%} + {%- block outputs scoped -%} + {%- for output in cell.outputs -%} + {%- block output scoped -%} + {%- if output.output_type == 'execute_result' -%} + {%- block execute_result scoped -%}{%- endblock execute_result -%} + {%- elif output.output_type == 'stream' -%} + {%- block stream scoped -%} + {%- if output.name == 'stdout' -%} + {%- block stream_stdout scoped -%} + {%- endblock stream_stdout -%} + {%- elif output.name == 'stderr' -%} + {%- block stream_stderr scoped -%} + {%- endblock stream_stderr -%} + {%- endif -%} + {%- endblock stream -%} + {%- elif output.output_type == 'display_data' -%} + {%- block display_data scoped -%} + {%- block data_priority scoped -%} + {%- endblock data_priority -%} + {%- endblock display_data -%} + {%- elif output.output_type == 'error' -%} + {%- block error scoped -%} + {%- for line in output.traceback -%} + {%- block traceback_line scoped -%}{%- endblock traceback_line -%} + {%- endfor -%} + {%- endblock error -%} {%- endif -%} - {%- endblock stream -%} - {%- elif output.output_type == 'display_data' -%} - {%- block display_data scoped -%} - {%- block data_priority scoped -%} - {%- endblock data_priority -%} - {%- endblock display_data -%} - {%- elif output.output_type == 'error' -%} - {%- block error scoped -%} - {%- for line in output.traceback -%} - {%- block traceback_line scoped -%}{%- endblock traceback_line -%} - {%- endfor -%} - {%- endblock error -%} - {%- endif -%} - {%- endblock output -%} - {%- endfor -%} - {%- endblock outputs -%} - {%- endblock output_group -%} - {%- endif -%} - {%- endblock codecell -%} - {%- endif -%} - {%- elif cell.cell_type in ['markdown'] -%} - {%- if resources.global_content_filter.include_markdown and not cell.get("transient",{}).get("remove_source", false) -%} - {%- block markdowncell scoped-%} {%- endblock markdowncell -%} - {%- endif -%} - {%- elif cell.cell_type in ['raw'] -%} - {%- if resources.global_content_filter.include_raw and not cell.get("transient",{}).get("remove_source", false) -%} - {%- block rawcell scoped -%} - {%- if cell.metadata.get('raw_mimetype', '').lower() in resources.get('raw_mimetypes', ['']) -%} - {{ cell.source }} + {%- endblock output -%} + {%- endfor -%} + {%- endblock outputs -%} + {%- endblock output_group -%} + {%- endif -%} + {%- endblock codecell -%} + {%- endif -%} + {%- elif cell.cell_type in ['markdown'] -%} + {%- if resources.global_content_filter.include_markdown and not cell.get("transient",{}).get("remove_source", false) -%} + {%- block markdowncell scoped-%} {%- endblock markdowncell -%} + {%- endif -%} + {%- elif cell.cell_type in ['raw'] -%} + {%- if resources.global_content_filter.include_raw and not cell.get("transient",{}).get("remove_source", false) -%} + {%- block rawcell scoped -%} + {%- if cell.metadata.get('raw_mimetype', '').lower() in resources.get('raw_mimetypes', ['']) -%} + {{ cell.source }} + {%- endif -%} + {%- endblock rawcell -%} + {%- endif -%} + {%- else -%} + {%- if resources.global_content_filter.include_unknown and not cell.get("transient",{}).get("remove_source", false) -%} + {%- block unknowncell scoped-%} + {%- endblock unknowncell -%} + {%- endif -%} {%- endif -%} - {%- endblock rawcell -%} - {%- endif -%} - {%- else -%} - {%- if resources.global_content_filter.include_unknown and not cell.get("transient",{}).get("remove_source", false) -%} - {%- block unknowncell scoped-%} - {%- endblock unknowncell -%} - {%- endif -%} - {%- endif -%} - {%- endblock any_cell -%} -{%- endfor -%} + {%- endblock any_cell -%} + {%- endfor -%} + {%- endblock body_loop -%} + {%- block body_footer -%} + {%- endblock body_footer -%} {%- endblock body -%} {%- block footer -%} diff --git a/share/jupyter/nbconvert/templates/classic/index.html.j2 b/share/jupyter/nbconvert/templates/classic/index.html.j2 index 17bb27274..1c4e2301d 100644 --- a/share/jupyter/nbconvert/templates/classic/index.html.j2 +++ b/share/jupyter/nbconvert/templates/classic/index.html.j2 @@ -113,23 +113,17 @@ div#notebook-container{ {%- endblock header -%} {# using the body block like this makes is difficult to be composable, added body_content/body_cells block for that#} -{% block body %} +{% block body_header %} - {% block body_content %}
- {%- block body_cells -%} - {%- for cell in nb.cells -%} - {%- block any_cell scoped -%} - {{ super() }} - {%- endblock any_cell -%} - {%- endfor -%} - {%- endblock body_cells -%} +{% endblock body_header %} + +{% block body_footer %}
- {% endblock body_content %} -{%- endblock body %} +{% endblock body_footer %} {% block footer %} {% block footer_js %} diff --git a/share/jupyter/nbconvert/templates/lab/index.html.j2 b/share/jupyter/nbconvert/templates/lab/index.html.j2 index 924011d86..e1c7bec00 100644 --- a/share/jupyter/nbconvert/templates/lab/index.html.j2 +++ b/share/jupyter/nbconvert/templates/lab/index.html.j2 @@ -16,20 +16,14 @@ a.anchor-link { margin: 0.4em; } -{% endblock notebook_css %} +{% endblock notebook_css %} -{%- block body -%} +{%- block body_header -%} {% if resources.theme == 'dark' %} - + {% else %} {% endif %} -{% block body_content %} - {%- block body_cells -%} - {{ super() }} - {%- endblock body_cells -%} -{% endblock body_content %} - -{%- endblock body -%} +{%- endblock body_header -%}