From b8982309132fb7ea96fe20fc286acc6f28dddfff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Dietrich?= Date: Fri, 7 Feb 2014 23:08:23 +0100 Subject: [PATCH 1/8] Make python code collapsible: - Remove unused code: https://github.com/getpelican/pelican-plugins/issues/140 - Add javascript and CSS to header to toggle code areas - load jinja2 template from file --- liquid_tags/notebook.py | 60 +++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 33 deletions(-) diff --git a/liquid_tags/notebook.py b/liquid_tags/notebook.py index 8b45d5d..2dce5e4 100644 --- a/liquid_tags/notebook.py +++ b/liquid_tags/notebook.py @@ -112,6 +112,14 @@ pre.ipynb { } img.anim_icon{padding:0; border:0; vertical-align:middle; -webkit-box-shadow:none; -box-shadow:none} + +div.collapseheader { + width=100%; + background-color:#d3d3d3; + padding: 2px; + cursor: pointer; + font-family:"Helvetica Neue",Helvetica,Arial,sans-serif; +} @@ -134,6 +142,23 @@ init_mathjax = function() { } init_mathjax(); + + + + """ CSS_WRAPPER = """ @@ -171,36 +196,6 @@ class SubCell(Transformer): return nbc, resources -#---------------------------------------------------------------------- -# Customize the html template: -# This changes the
 tags in basic_html.tpl to 
-
{{output.text |ansi2html}}
- -{%- endblock stream_stdout %} - -{% block stream_stderr -%} -
-
{{output.text |ansi2html}}
-
-{%- endblock stream_stderr %} - -{% block pyerr -%} -
-
{{super()}}
-
-{%- endblock pyerr %} - -{%- block data_text %} -
{{output.text | ansi2html}}
-{%- endblock -%} -"""}) - #---------------------------------------------------------------------- # Custom highlighter: @@ -254,10 +249,9 @@ def notebook(preprocessor, tag, markup): {'enabled':True, 'start':start, 'end':end}}) exporter = HTMLExporter(config=c, - template_file='basic', + template_file='pelicanhtml', filters={'highlight2html': custom_highlighter}, - transformers=[SubCell], - extra_loaders=[pelican_loader]) + transformers=[SubCell]) # read and parse the notebook with open(nb_path) as f: From 1876bf4438e17bd7879dd6795e70752ab53a2603 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Dietrich?= Date: Fri, 7 Feb 2014 23:10:34 +0100 Subject: [PATCH 2/8] add jinja2 template file to have collapsible python code --- liquid_tags/pelicanhtml.tpl | 44 +++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 liquid_tags/pelicanhtml.tpl diff --git a/liquid_tags/pelicanhtml.tpl b/liquid_tags/pelicanhtml.tpl new file mode 100644 index 0000000..dbba638 --- /dev/null +++ b/liquid_tags/pelicanhtml.tpl @@ -0,0 +1,44 @@ +{%- extends 'html_basic.tpl' -%} + +{% block stream_stdout -%} +
+
{{output.text |ansi2html}}
+
+{%- endblock stream_stdout %} + +{% block stream_stderr -%} +
+
{{output.text |ansi2html}}
+
+{%- endblock stream_stderr %} + +{% block pyerr -%} +
+
{{super()}}
+
+{%- endblock pyerr %} + +{%- block data_text %} +
{{output.text | ansi2html}}
+{%- endblock -%} + +{% block input %} +{% if "#" in cell.input %} +
Expand Code + +
+{% elif "#" in cell.input %} +
Collapse Code +
+{{ cell.input.replace("#\n", "") | highlight2html }} +
+
+{% else %} +
+{{ cell.input.replace("#\n", "") | highlight2html }} +
+{% endif %} +{%- endblock input %} + From e1fd114a0eb93e0d04b2a01a1684146982948887 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Dietrich?= Date: Sat, 8 Feb 2014 10:34:53 +0100 Subject: [PATCH 3/8] remove unnessecary replace from template, require white space after hash --- liquid_tags/pelicanhtml.tpl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/liquid_tags/pelicanhtml.tpl b/liquid_tags/pelicanhtml.tpl index dbba638..b32a52b 100644 --- a/liquid_tags/pelicanhtml.tpl +++ b/liquid_tags/pelicanhtml.tpl @@ -23,21 +23,21 @@ {%- endblock -%} {% block input %} -{% if "#" in cell.input %} +{% if "# " in cell.input %}
Expand Code
-{% elif "#" in cell.input %} +{% elif "# " in cell.input %}
Collapse Code
-{{ cell.input.replace("#\n", "") | highlight2html }} +{{ cell.input.replace("# \n", "") | highlight2html }}
{% else %}
-{{ cell.input.replace("#\n", "") | highlight2html }} +{{ cell.input | highlight2html }}
{% endif %} {%- endblock input %} From 5d0a5d2ec53e1be3c2b16961883cb5a192b6a678 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Dietrich?= Date: Sat, 8 Feb 2014 10:47:18 +0100 Subject: [PATCH 4/8] get jquery via https from google's cdn --- liquid_tags/notebook.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/liquid_tags/notebook.py b/liquid_tags/notebook.py index 2dce5e4..8a1acbb 100644 --- a/liquid_tags/notebook.py +++ b/liquid_tags/notebook.py @@ -142,7 +142,7 @@ init_mathjax = function() { } init_mathjax(); - +