-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add jupyter notebook loader and custom template #210
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,5 +51,20 @@ def render_rest(content): | |
LANGUAGES.append((['.rst', '.rest'], render_rest)) | ||
|
||
|
||
for loader in [_load_markdown, _load_restructured_text]: | ||
def _load_notebook(): | ||
try: | ||
import nbformat | ||
import nbconvert | ||
except ImportError: | ||
return | ||
|
||
def render_notebook(content): | ||
nb = nbformat.reads(content, nbformat.NO_CONVERT) | ||
(output, resources) = nbconvert.HTMLExporter(template_file='./klaus/templates/my_full.tpl').from_notebook_node(nb) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's just a little CSS modification of nbconvert template 'full', cause the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see! In this case could we simply use the default template and add the CSS fixes to klaus' CSS file? Or if that doesn't work, can we use inheritance to override the CSS instead of copy-pasting the whole file? |
||
return output | ||
|
||
LANGUAGES.append((['.ipynb'], render_notebook)) | ||
|
||
|
||
for loader in [_load_markdown, _load_restructured_text, _load_notebook]: | ||
loader() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
{%- extends 'basic.tpl' -%} | ||
{% from 'mathjax.tpl' import mathjax %} | ||
|
||
|
||
{%- block header -%} | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
{%- block html_head -%} | ||
<meta charset="utf-8" /> | ||
<title>{{resources['metadata']['name']}}</title> | ||
|
||
{%- if "widgets" in nb.metadata -%} | ||
<script src="https://unpkg.com/[email protected].*/dist/embed.js"></script> | ||
{%- endif-%} | ||
|
||
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.10/require.min.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script> | ||
|
||
{% for css in resources.inlining.css -%} | ||
<style type="text/css"> | ||
{{ css }} | ||
</style> | ||
{% endfor %} | ||
|
||
<style type="text/css"> | ||
/* Overrides of notebook CSS for static HTML export */ | ||
body { | ||
overflow: visible; | ||
padding: 8px; | ||
} | ||
|
||
div#notebook { | ||
overflow: visible; | ||
border-top: none; | ||
} | ||
|
||
{%- if resources.global_content_filter.no_prompt-%} | ||
div#notebook-container{ | ||
padding: 6ex 12ex 8ex 12ex; | ||
} | ||
{%- endif -%} | ||
|
||
@media print { | ||
div.cell { | ||
display: block; | ||
page-break-inside: avoid; | ||
} | ||
div.output_wrapper { | ||
display: block; | ||
page-break-inside: avoid; | ||
} | ||
div.output { | ||
display: block; | ||
page-break-inside: avoid; | ||
} | ||
} | ||
|
||
@media (min-width: 768px) { | ||
.container { | ||
width: 728px; | ||
} | ||
} | ||
@media (min-width: 992px) { | ||
.container { | ||
width: 900px; | ||
} | ||
} | ||
@media (min-width: 1200px) { | ||
.container { | ||
width: 1100px; | ||
} | ||
} | ||
</style> | ||
|
||
<!-- Custom stylesheet, it must be in the same directory as the html file --> | ||
<link rel="stylesheet" href="custom.css"> | ||
|
||
<!-- Loading mathjax macro --> | ||
{{ mathjax() }} | ||
{%- endblock html_head -%} | ||
</head> | ||
{%- endblock header -%} | ||
|
||
{% block body %} | ||
<body> | ||
<div tabindex="-1" id="notebook" class="border-box-sizing"> | ||
<div class="container" id="notebook-container"> | ||
{{ super() }} | ||
</div> | ||
</div> | ||
</body> | ||
{%- endblock body %} | ||
|
||
{% block footer %} | ||
{{ super() }} | ||
</html> | ||
{% endblock footer %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
klaus | ||
pytest | ||
requests | ||
markdown | ||
docutils | ||
nbformat | ||
nbconvert | ||
python-ctags3>=1.2.1 | ||
mock; python_version < '3' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes seem unrelated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry! These changes are for my self usage. Didn't notice these commits will be related to this pull request. I've checkout a new branch and made a new pull request. It was my first time doing pull request, don't know if it's the right way 😃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#211 new request, I've moved some of your comments to there