|
| 1 | +{# Lines inside these brackets are comments #} |
| 2 | +{#- Brackets with a `-` mean to skip whitespace before or after the block. -#} |
| 3 | + |
| 4 | +{#- |
| 5 | + # This file defines a Jinja Template for converting .ipynb files into scripts |
| 6 | + # for either delve or julia. We need this because the default script exporter |
| 7 | + # doesn't render Markdown for any languages except Python. |
| 8 | + # Exporting the markdown makes github reviews of .ipynb files easier. |
| 9 | + # This template is invoked by our custom `jupyter_notebook_config.py`. You can |
| 10 | + # read more about the Jinja template specification here: |
| 11 | + # http://jinja.pocoo.org/docs/2.10/templates/#comments |
| 12 | + # and here: |
| 13 | + # https://nbconvert.readthedocs.io/en/latest/customizing.html |
| 14 | + # And the filter functions used in this file are defined here: |
| 15 | + # https://github.com/pallets/jinja/blob/master/jinja2/filters.py |
| 16 | + # and here: |
| 17 | + # https://github.com/jupyter/nbconvert/blob/master/nbconvert/filters/strings.py |
| 18 | + -#} |
| 19 | +
|
| 20 | +{#- --------- |
| 21 | + # Lines up here, before the `extends` section, go at the top of the file, before any other |
| 22 | + # content from the notebook itself. |
| 23 | + #----------- -#} |
| 24 | +
|
| 25 | +{%- if 'name' in nb.metadata.get('kernelspec', {}) and |
| 26 | + nb.metadata.kernelspec.name == 'julia' -%} |
| 27 | +# This file was generated from a Julia language jupyter notebook. |
| 28 | +{% endif -%} |
| 29 | +
|
| 30 | +{% extends 'script.tpl'%} |
| 31 | +
|
| 32 | +{% block markdowncell %} |
| 33 | + {#- Turn the contents of the markdown cell into a wrapped comment block, and trim empty lines. -#} |
| 34 | +
|
| 35 | + {#- |
| 36 | + # NOTE: We used `kernelspec.name` not `language_info.name`, for reasons specific to |
| 37 | + # our custom jupyter kernel. I think `language_info.name` might be more robust? |
| 38 | + -#} |
| 39 | + {%- if 'name' in nb.metadata.get('kernelspec', {}) and |
| 40 | + nb.metadata.kernelspec.name == 'julia' -%} |
| 41 | + {%- set commentprefix = '# ' -%} |
| 42 | + {#- |
| 43 | + # Add other languages here as if-else block, e.g. C++ would use '// ' |
| 44 | + -#} |
| 45 | + {%- else -%} |
| 46 | + {#- Assume python by default -#} |
| 47 | + {%- set commentprefix = '# ' -%} |
| 48 | + {%- endif -%} |
| 49 | +
|
| 50 | + {%- set commentlen = 92-(commentprefix|length) -%} |
| 51 | + {{- '\n' -}} |
| 52 | + {{- commentprefix ~ '-' * commentlen -}} |
| 53 | + {{- '\n' -}} |
| 54 | +
|
| 55 | + {#- Turn the contents of the markdown cell into a wrapped comment block, and trim empty lines. -#} |
| 56 | + {#- Note: `comment_lines` and `wrap_text` are defined in nbconvert/filters/strings.py -#} |
| 57 | + {{- cell.source | wrap_text(width=commentlen) | comment_lines(prefix=commentprefix) | replace(commentprefix~"\n", commentprefix|trim ~ "\n") -}} |
| 58 | +
|
| 59 | + {{- '\n' -}} |
| 60 | + {{- commentprefix ~ '-' * commentlen -}} |
| 61 | + {{- '\n' -}} |
| 62 | +
|
| 63 | +{% endblock markdowncell %} |
0 commit comments