-
-
Save wanchaol/e2264ab748d53af12cadcecad9a409a1 to your computer and use it in GitHub Desktop.
IPython to Jekyll Markdown
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try: | |
from urllib.parse import quote # Py 3 | |
except ImportError: | |
from urllib2 import quote # Py 2 | |
import os | |
import sys | |
BLOG_DIR = os.environ['BLOG_DIR'] | |
# BLOG_DIR = '/Users/cscorley/git/cscorley.github.io/' | |
f = None | |
for arg in sys.argv: | |
if arg.endswith('.ipynb'): | |
f = arg.split('.ipynb')[0] | |
break | |
c = get_config() | |
c.NbConvertApp.export_format = 'markdown' | |
c.MarkdownExporter.template_path = ['/Users/cscorley/.ipython/templates'] | |
c.MarkdownExporter.template_file = 'jekyll' | |
#c.Exporter.file_extension = 'md' | |
def path2support(path): | |
"""Turn a file path into a URL""" | |
parts = path.split(os.path.sep) | |
return '{{ site.baseurl}}notebooks/' + '/'.join(quote(part) for part in parts) | |
c.MarkdownExporter.filters = {'path2support': path2support} | |
if f: | |
c.NbConvertApp.output_base = f.lower().replace(' ', '-') | |
c.FilesWriter.build_directory = BLOG_DIR + '/notebooks' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% extends 'display_priority.tpl' %} | |
{%- block header -%} | |
--- | |
layout: post | |
title: "{{resources['metadata']['name']}}" | |
tags: | |
- python | |
- notebook | |
--- | |
{%- endblock header -%} | |
{% block in_prompt %} | |
**In [{{ cell.prompt_number }}]:** | |
{% endblock in_prompt %} | |
{% block output_prompt %} | |
{%- endblock output_prompt %} | |
{% block input %} | |
{{ '{% highlight python %}' }} | |
{{ cell.input }} | |
{{ '{% endhighlight %}' }} | |
{% endblock input %} | |
{% block pyerr %} | |
{{ super() }} | |
{% endblock pyerr %} | |
{% block traceback_line %} | |
{{ line | indent | strip_ansi }} | |
{% endblock traceback_line %} | |
{% block pyout %} | |
{% block data_priority scoped %} | |
{{ super() }} | |
{% endblock %} | |
{% endblock pyout %} | |
{% block stream %} | |
{{ output.text | indent }} | |
{% endblock stream %} | |
{% block data_svg %} | |
 | |
{% endblock data_svg %} | |
{% block data_png %} | |
 | |
{% endblock data_png %} | |
{% block data_jpg %} | |
 | |
{% endblock data_jpg %} | |
{% block data_latex %} | |
{{ output.latex }} | |
{% endblock data_latex %} | |
{% block data_html scoped %} | |
{{ output.html }} | |
{% endblock data_html %} | |
{% block data_text scoped %} | |
{{ output.text | indent }} | |
{% endblock data_text %} | |
{% block markdowncell scoped %} | |
{{ cell.source | wrap_text(80) }} | |
{% endblock markdowncell %} | |
{% block headingcell scoped %} | |
{{ '#' * cell.level }} {{ cell.source | replace('\n', ' ') }} | |
{% endblock headingcell %} | |
{% block unknowncell scoped %} | |
unknown type {{ cell.type }} | |
{% endblock unknowncell %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment