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
This commit is contained in:
Jörg Dietrich
2014-02-07 23:08:23 +01:00
parent 614e670026
commit b898230913

View File

@@ -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;
}
</style>
<script src="https://c328740.ssl.cf1.rackcdn.com/mathjax/latest/MathJax.js?config=TeX-AMS_HTML" type="text/javascript"></script>
@@ -134,6 +142,23 @@ init_mathjax = function() {
}
init_mathjax();
</script>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function($) {
$("div.collapseheader").click(function () {
$header = $(this).children("span").first();
$codearea = $(this).children(".input_area");
console.log($(this).children());
$codearea.slideToggle(500, function () {
$header.text(function () {
return $codearea.is(":visible") ? "Collapse Code" : "Expand Code";
});
});
});
});
</script>
"""
CSS_WRAPPER = """
@@ -171,36 +196,6 @@ class SubCell(Transformer):
return nbc, resources
#----------------------------------------------------------------------
# Customize the html template:
# This changes the <pre> tags in basic_html.tpl to <pre class="ipynb"
pelican_loader = DictLoader({'pelicanhtml.tpl':
"""
{%- extends 'basichtml.tpl' -%}
{% block stream_stdout -%}
<div class="box-flex1 output_subarea output_stream output_stdout">
<pre class="ipynb">{{output.text |ansi2html}}</pre>
</div>
{%- endblock stream_stdout %}
{% block stream_stderr -%}
<div class="box-flex1 output_subarea output_stream output_stderr">
<pre class="ipynb">{{output.text |ansi2html}}</pre>
</div>
{%- endblock stream_stderr %}
{% block pyerr -%}
<div class="box-flex1 output_subarea output_pyerr">
<pre class="ipynb">{{super()}}</pre>
</div>
{%- endblock pyerr %}
{%- block data_text %}
<pre class="ipynb">{{output.text | ansi2html}}</pre>
{%- 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: