From 81b4bfe2b49708766c972ff8ad55cf873aeda49b Mon Sep 17 00:00:00 2001 From: Eric Matthes Date: Mon, 13 Apr 2015 07:18:11 -0800 Subject: [PATCH] Template includes html structure, title. --- notebooks/my_templates/base.tpl | 197 ------------------ .../{test.tpl => intro_python_base.tpl} | 14 +- scripts/create_common_html.sh | 2 +- scripts/scraping_approach/add_opening_tags.sh | 19 -- scripts/scraping_approach/add_title.sh | 21 -- scripts/scraping_approach/close_body_html.sh | 13 -- .../scraping_approach/close_head_open_body.sh | 20 -- 7 files changed, 7 insertions(+), 279 deletions(-) delete mode 100644 notebooks/my_templates/base.tpl rename notebooks/my_templates/{test.tpl => intro_python_base.tpl} (71%) delete mode 100755 scripts/scraping_approach/add_opening_tags.sh delete mode 100755 scripts/scraping_approach/add_title.sh delete mode 100755 scripts/scraping_approach/close_body_html.sh delete mode 100755 scripts/scraping_approach/close_head_open_body.sh diff --git a/notebooks/my_templates/base.tpl b/notebooks/my_templates/base.tpl deleted file mode 100644 index f68ee3a..0000000 --- a/notebooks/my_templates/base.tpl +++ /dev/null @@ -1,197 +0,0 @@ -{%- extends 'display_priority.tpl' -%} - -{% block codecell %} -
-{{ super() }} -
-{%- endblock codecell %} - -{% block input_group -%} -
-{{ super() }} -
-{% endblock input_group %} - -{% block output_group %} -
-
-{{ super() }} -
-
-{% endblock output_group %} - -{% block in_prompt -%} -
-{%- if cell.execution_count is defined -%} -In [{{ cell.execution_count|replace(None, " ") }}]: -{%- else -%} -In [ ]: -{%- endif -%} -
-{%- endblock in_prompt %} - -{% block empty_in_prompt -%} -
-
-{%- endblock empty_in_prompt %} - -{# - output_prompt doesn't do anything in HTML, - because there is a prompt div in each output area (see output block) -#} -{% block output_prompt %} -{% endblock output_prompt %} - -{% block input %} -
-
-{{ cell.source | highlight_code(metadata=cell.metadata) }} -
-
-{%- endblock input %} - -{% block output %} -
-{%- if output.output_type == 'execute_result' -%} -
-{%- if cell.execution_count is defined -%} - Out[{{ cell.execution_count|replace(None, " ") }}]: -{%- else -%} - Out[ ]: -{%- endif -%} -{%- else -%} -
-{%- endif -%} -
-{{ super() }} -
-{% endblock output %} - -{% block markdowncell scoped %} -
-{{ self.empty_in_prompt() }} -
-
-{{ cell.source | markdown2html | strip_files_prefix }} -
-
-
-{%- endblock markdowncell %} - -{% block unknowncell scoped %} -unknown type {{ cell.type }} -{% endblock unknowncell %} - -{% block execute_result -%} -{%- set extra_class="output_execute_result" -%} -{% block data_priority scoped %} -{{ super() }} -{% endblock %} -{%- set extra_class="" -%} -{%- endblock execute_result %} - -{% block stream_stdout -%} -
-
-{{- output.text | ansi2html -}}
-
-
-{%- endblock stream_stdout %} - -{% block stream_stderr -%} -
-
-{{- output.text | ansi2html -}}
-
-
-{%- endblock stream_stderr %} - -{% block data_svg scoped -%} -
-{%- if output.svg_filename %} - -{%- endblock data_svg %} - -{% block data_html scoped -%} -
-{{ output.data['text/html'] }} -
-{%- endblock data_html %} - -{% block data_markdown scoped -%} -
-{{ output.data['text/markdown'] | markdown2html }} -
-{%- endblock data_markdown %} - -{% block data_png scoped %} -
-{%- if 'image/png' in output.metadata.get('filenames', {}) %} - -
-{%- endblock data_png %} - -{% block data_jpg scoped %} -
-{%- if 'image/jpeg' in output.metadata.get('filenames', {}) %} - -
-{%- endblock data_jpg %} - -{% block data_latex scoped %} -
-{{ output.data['text/latex'] }} -
-{%- endblock data_latex %} - -{% block error -%} -
-
-{{- super() -}}
-
-
-{%- endblock error %} - -{%- block traceback_line %} -{{ line | ansi2html }} -{%- endblock traceback_line %} - -{%- block data_text scoped %} -
-
-{{- output.data['text/plain'] | ansi2html -}}
-
-
-{%- endblock -%} - -{%- block data_javascript scoped %} -
- -
-{%- endblock -%} diff --git a/notebooks/my_templates/test.tpl b/notebooks/my_templates/intro_python_base.tpl similarity index 71% rename from notebooks/my_templates/test.tpl rename to notebooks/my_templates/intro_python_base.tpl index 595e285..5a67259 100644 --- a/notebooks/my_templates/test.tpl +++ b/notebooks/my_templates/intro_python_base.tpl @@ -3,16 +3,14 @@ {%- block header -%} - - - + + + - + + Introduction to Python - -{{ mathjax() }} - - + {%- endblock header -%} {% block body %} diff --git a/scripts/create_common_html.sh b/scripts/create_common_html.sh index 48c06dd..7d7b03b 100644 --- a/scripts/create_common_html.sh +++ b/scripts/create_common_html.sh @@ -54,7 +54,7 @@ printf "\n Removed files." ### Then I can remove some of the other build scripts, and ### diagnose changes in styling issues. printf "\nConverting raw .ipynb files to raw .html files...\n" -cd "$path_to_notebooks" && ipython nbconvert --template my_templates/my_base.tpl *.ipynb +cd "$path_to_notebooks" && ipython nbconvert --template my_templates/intro_python_base.tpl *.ipynb printf "\n Converted files.\n" # Go through each html file, changing all internal links so they point to these diff --git a/scripts/scraping_approach/add_opening_tags.sh b/scripts/scraping_approach/add_opening_tags.sh deleted file mode 100755 index f9d8de0..0000000 --- a/scripts/scraping_approach/add_opening_tags.sh +++ /dev/null @@ -1,19 +0,0 @@ -# This file adds the first few tags that need to appear on every html page. -# -# DOCTYPE declaration -# opens html tag -# opens head tag -# meta charset tag - -opening_tags="\n\n\n\n" - -printf "\nAdding opening tags to html files..." - -if [ -e "../notebooks/" ] -then - find ../notebooks -iname '*.html' | xargs sed -i "1s/^/$opening_tags/" -else - find notebooks -iname '*.html' | xargs sed -i "1s/^/$opening_tags/" -fi - -printf "\nAdded opening tags.\n\n" diff --git a/scripts/scraping_approach/add_title.sh b/scripts/scraping_approach/add_title.sh deleted file mode 100755 index aa3a525..0000000 --- a/scripts/scraping_approach/add_title.sh +++ /dev/null @@ -1,21 +0,0 @@ -# This file adds a title to each html page. -# -# Should pull title from the top of each page. -# Good place would be the first content within an h1 tag. -# For now, just title everything 'Introduction to Python'. - - -printf "\nAdding titles to html files..." - -# String right before where the title should be -before_string="" -title_string='Introduction to Python<\/title>\n' - -if [ -e "../notebooks/" ] -then - find ../notebooks -iname '*.html' | xargs sed -i "s/$before_string/$before_string\n\n$title_string/" -else - find notebooks -iname '*.html' | xargs sed -i "s/$before_string/$before_string\n\n$title_string/" -fi - -printf "\nAdded titles.\n\n" diff --git a/scripts/scraping_approach/close_body_html.sh b/scripts/scraping_approach/close_body_html.sh deleted file mode 100755 index 94adae6..0000000 --- a/scripts/scraping_approach/close_body_html.sh +++ /dev/null @@ -1,13 +0,0 @@ -# This file adds the closing body and html tags to the end of the file. -# - -printf "\nAdding closing body and closing html tags to ends of html files..." - -if [ -e "../notebooks/" ] -then - find ../notebooks -iname '*.html' | xargs sed -i '$a\</body>\n</html>' -else - find notebooks -iname '*.html' | xargs sed -i '$a\</body>\n</html>' -fi - -printf "\nAdded closing tags.\n\n" diff --git a/scripts/scraping_approach/close_head_open_body.sh b/scripts/scraping_approach/close_head_open_body.sh deleted file mode 100755 index fa08ab6..0000000 --- a/scripts/scraping_approach/close_head_open_body.sh +++ /dev/null @@ -1,20 +0,0 @@ -# Closes the head section and opens the body. - - -printf "\nAdding closing head tag and opening body tag..." - -# String right before where the title should be -#before_string="<script type='text\/javascript' src='js\/nbconvert_js.js'><\/script>" -before_string="<script type='text\/javascript' src='js\/show_hide_output.js'><\/script>" -head_body_tags_string="<\/head>\n<body>" - - - -if [ -e "../notebooks/" ] -then - find ../notebooks -iname '*.html' | xargs sed -i "s/$before_string/$before_string\n$head_body_tags_string\n/" -else - find notebooks -iname '*.html' | xargs sed -i "s/$before_string/$before_string\n$head_body_tags_string\n/" -fi - -printf "\nAdded closing head tag and opening body tag.\n\n"