diff --git a/converters/template.py b/converters/template.py index 890c9c7..c42896a 100755 --- a/converters/template.py +++ b/converters/template.py @@ -39,6 +39,8 @@ from IPython.utils.traitlets import (List, Unicode, Type, Bool, Dict, CaselessSt # Our own imports from IPython.utils.text import indent from .utils import remove_ansi +from markdown import markdown +from .utils import highlight #----------------------------------------------------------------------------- # Class declarations #----------------------------------------------------------------------------- @@ -56,6 +58,8 @@ env.filters['pycomment'] = python_comment env.filters['indent'] = indent env.filters['rm_fake'] = rm_fake env.filters['rm_ansi'] = remove_ansi +env.filters['markdown'] = markdown +env.filters['highlight'] = highlight class ConverterTemplate(Configurable): @@ -69,8 +73,8 @@ class ConverterTemplate(Configurable): infile_dir = Unicode() - def __init__(self, config=None, **kw): - self.template = env.get_template('python.tpl') + def __init__(self, tplfile='fullhtml', config=None, **kw): + self.template = env.get_template(tplfile+'.tpl') super(ConverterTemplate,self).__init__(config=config) def _get_prompt_number(self, cell): diff --git a/runme.py b/runme.py index ec48df1..6b05f08 100644 --- a/runme.py +++ b/runme.py @@ -1,7 +1,9 @@ # coding: utf-8 +import sys from converters.template import * -C = ConverterTemplate() +C = ConverterTemplate(tplfile=sys.argv[1]) C.read('tests/ipynbref/IntroNumPy.orig.ipynb') + S = C.convert() with open('temp.txt','w') as f: f.write(S) diff --git a/templates/basichtml.tpl b/templates/basichtml.tpl new file mode 100644 index 0000000..9b6e7d8 --- /dev/null +++ b/templates/basichtml.tpl @@ -0,0 +1,61 @@ +{%- extends 'basic.tpl' -%} + + + + +{% block codecell scoped %} +<div class="cell border-box-sizing code_cell vbox"> +<div class="input hbox"> +<div class="prompt input_prompt">In [{{cell.prompt_number if cell.prompt_number else ' '}}]:</div> +<div class="input_area box-flex1"> +{{ cell.input|highlight -}} +</div> +</div> +{% if cell.outputs %} +{%- for output in cell.outputs -%} +<div class="vbox output_wrapper"> +<div class="output vbox"> +<div class="hbox output_area"> +<div class="prompt output_prompt"></div> + {%- if output.output_type in ['pyout','stream'] %} +<div class="output_subarea output_stream output_stdout"> +<pre>{{ output.text }}</pre> +</div> +</div> +</div> + {%- elif output.output_type in ['display_data'] %} +<div class="output_subarea output_display_data"> +{{"# image file: fucking display_data"}} +</div> + {%- elif output.output_type in ['pyerr'] %} + {%- for line in output.traceback %} +{{ line |indent| rm_ansi}} + {%- endfor %} + {%- endif %} +{%- endfor -%} +{% endif %} +</div> +</div> +{% endblock codecell %} + +{% block markdowncell scoped -%} +<div class="text_cell_render border-box-sizing rendered_html"> +{{ cell.source | markdown| rm_fake}} +</div> +{%- endblock markdowncell %} + +{% block headingcell scoped %} +<div class="text_cell_render border-box-sizing rendered_html"> +<h{{cell.level}}> + {{cell.source}} +</h{{cell.level}}> +</div> +{% endblock headingcell %} + +{% block rawcell scoped %} +{{ cell.source | pycomment }} +{% endblock rawcell %} + +{% block unknowncell scoped %} +unknown type {{cell.type}} +{% endblock unknowncell %} diff --git a/templates/fullhtml.tpl b/templates/fullhtml.tpl new file mode 100644 index 0000000..a602b56 --- /dev/null +++ b/templates/fullhtml.tpl @@ -0,0 +1,787 @@ +{%- extends 'basichtml.tpl' -%} + +{%- block header -%} +<html> +<head> +<style type="text/css"> +/** + * HTML5 Boilerplate + * + * style.css contains a reset, font normalization and some base styles. + * + * Credit is left where credit is due. + * Much inspiration was taken from these projects: + * - yui.yahooapis.com/2.8.1/build/base/base.css + * - camendesign.com/design/ + * - praegnanz.de/weblog/htmlcssjs-kickstart + */ + + +/** + * html5doctor.com Reset Stylesheet (Eric Meyer's Reset Reloaded + HTML5 baseline) + * v1.6.1 2010-09-17 | Authors: Eric Meyer & Richard Clark + * html5doctor.com/html-5-reset-stylesheet/ + */ + +html, body, div, span, object, iframe, +h1, h2, h3, h4, h5, h6, p, blockquote, pre, +abbr, address, cite, code, del, dfn, em, img, ins, kbd, q, samp, +small, strong, sub, sup, var, b, i, dl, dt, dd, ol, ul, li, +fieldset, form, label, legend, +table, caption, tbody, tfoot, thead, tr, th, td, +article, aside, canvas, details, figcaption, figure, +footer, header, hgroup, menu, nav, section, summary, +time, mark, audio, video { + margin: 0; + padding: 0; + border: 0; + font-size: 100%; + font: inherit; + vertical-align: baseline; +} + +sup { vertical-align: super; } +sub { vertical-align: sub; } + +article, aside, details, figcaption, figure, +footer, header, hgroup, menu, nav, section { + display: block; +} + +blockquote, q { quotes: none; } + +blockquote:before, blockquote:after, +q:before, q:after { content: ""; content: none; } + +ins { background-color: #ff9; color: #000; text-decoration: none; } + +mark { background-color: #ff9; color: #000; font-style: italic; font-weight: bold; } + +del { text-decoration: line-through; } + +abbr[title], dfn[title] { border-bottom: 1px dotted; cursor: help; } + +table { border-collapse: collapse; border-spacing: 0; } + +hr { display: block; height: 1px; border: 0; border-top: 1px solid #ccc; margin: 1em 0; padding: 0; } + +input, select { vertical-align: middle; } + + +/** + * Font normalization inspired by YUI Library's fonts.css: developer.yahoo.com/yui/ + */ + +body { font:13px/1.231 sans-serif; *font-size:small; } /* Hack retained to preserve specificity */ +select, input, textarea, button { font:99% sans-serif; } + +/* Normalize monospace sizing: + en.wikipedia.org/wiki/MediaWiki_talk:Common.css/Archive_11#Teletype_style_fix_for_Chrome */ +pre, code, kbd, samp { font-family: monospace, sans-serif; } + +em,i { font-style: italic; } +b,strong { font-weight: bold; } + +</style> +<style type="text/css"> + +/* Flexible box model classes */ +/* Taken from Alex Russell http://infrequently.org/2009/08/css-3-progress/ */ + +.hbox { + display: -webkit-box; + -webkit-box-orient: horizontal; + -webkit-box-align: stretch; + + display: -moz-box; + -moz-box-orient: horizontal; + -moz-box-align: stretch; + + display: box; + box-orient: horizontal; + box-align: stretch; +} + +.hbox > * { + -webkit-box-flex: 0; + -moz-box-flex: 0; + box-flex: 0; +} + +.vbox { + display: -webkit-box; + -webkit-box-orient: vertical; + -webkit-box-align: stretch; + + display: -moz-box; + -moz-box-orient: vertical; + -moz-box-align: stretch; + + display: box; + box-orient: vertical; + box-align: stretch; +} + +.vbox > * { + -webkit-box-flex: 0; + -moz-box-flex: 0; + box-flex: 0; +} + +.reverse { + -webkit-box-direction: reverse; + -moz-box-direction: reverse; + box-direction: reverse; +} + +.box-flex0 { + -webkit-box-flex: 0; + -moz-box-flex: 0; + box-flex: 0; +} + +.box-flex1, .box-flex { + -webkit-box-flex: 1; + -moz-box-flex: 1; + box-flex: 1; +} + +.box-flex2 { + -webkit-box-flex: 2; + -moz-box-flex: 2; + box-flex: 2; +} + +.box-group1 { + -webkit-box-flex-group: 1; + -moz-box-flex-group: 1; + box-flex-group: 1; +} + +.box-group2 { + -webkit-box-flex-group: 2; + -moz-box-flex-group: 2; + box-flex-group: 2; +} + +.start { + -webkit-box-pack: start; + -moz-box-pack: start; + box-pack: start; +} + +.end { + -webkit-box-pack: end; + -moz-box-pack: end; + box-pack: end; +} + +.center { + -webkit-box-pack: center; + -moz-box-pack: center; + box-pack: center; +} + +</style> +<style type="text/css"> +/** + * Primary styles + * + * Author: IPython Development Team + */ + + +body { + overflow: hidden; +} + +blockquote { + border-left: 4px solid #DDD; + padding: 0 15px; + color: #777; +} + +span#save_widget { + padding: 5px; + margin: 0px 0px 0px 300px; + display:inline-block; +} + +span#notebook_name { + height: 1em; + line-height: 1em; + padding: 3px; + border: none; + font-size: 146.5%; +} + +.ui-menubar-item .ui-button .ui-button-text { + padding: 0.4em 1.0em; + font-size: 100%; +} + +.ui-menu { + -moz-box-shadow: 0px 6px 10px -1px #adadad; + -webkit-box-shadow: 0px 6px 10px -1px #adadad; + box-shadow: 0px 6px 10px -1px #adadad; +} + +.ui-menu .ui-menu-item a { + border: 1px solid transparent; + padding: 2px 1.6em; +} + +.ui-menu .ui-menu-item a.ui-state-focus { + margin: 0; +} + +.ui-menu hr { + margin: 0.3em 0; +} + +#menubar_container { + position: relative; +} + +#notification_area { + position: absolute; + right: 0px; + top: 0px; + height: 25px; + padding: 3px 0px; + padding-right: 3px; + z-index: 10; +} + +.notification_widget{ + float : right; + right: 0px; + top: 1px; + height: 25px; + padding: 3px 6px; + z-index: 10; +} + +.toolbar { + padding: 3px 15px; +} + +#cell_type { + font-size: 85%; +} + + +div#main_app { + width: 100%; + position: relative; +} + +span#quick_help_area { + position: static; + padding: 5px 0px; + margin: 0px 0px 0px 0px; +} + +.help_string { + float: right; + width: 170px; + padding: 0px 5px; + text-align: left; + font-size: 85%; +} + +.help_string_label { + float: right; + font-size: 85%; +} + +div#notebook_panel { + margin: 0px 0px 0px 0px; + padding: 0px; +} + +div#notebook { + overflow-y: scroll; + overflow-x: auto; + width: 100%; + /* This spaces the cell away from the edge of the notebook area */ + padding: 5px 5px 15px 5px; + margin: 0px; + background-color: white; +} + +div#pager_splitter { + height: 8px; +} + +#pager_container { + position : relative; +} + +div#pager { + padding: 15px; + overflow: auto; + display: none; +} + +div.ui-widget-content { + border: 1px solid #aaa; + outline: none; +} + +.cell { + border: 1px solid transparent; +} + +div.cell { + width: 100%; + padding: 5px 5px 5px 0px; + /* This acts as a spacer between cells, that is outside the border */ + margin: 2px 0px 2px 0px; +} + +div.code_cell { + background-color: white; +} + +/* any special styling for code cells that are currently running goes here */ +div.code_cell.running { +} + +div.prompt { + /* This needs to be wide enough for 3 digit prompt numbers: In[100]: */ + width: 11ex; + /* This 0.4em is tuned to match the padding on the CodeMirror editor. */ + padding: 0.4em; + margin: 0px; + font-family: monospace; + text-align:right; +} + +div.input { + page-break-inside: avoid; +} + +/* input_area and input_prompt must match in top border and margin for alignment */ +div.input_area { + color: black; + border: 1px solid #ddd; + border-radius: 3px; + background: #f7f7f7; +} + +div.input_prompt { + color: navy; + border-top: 1px solid transparent; +} + +div.output_wrapper { + /* This is a spacer between the input and output of each cell */ + margin-top: 5px; + margin-left: 5px; + /* FF needs explicit width to stretch */ + width: 100%; + /* this position must be relative to enable descendents to be absolute within it */ + position: relative; +} + +/* class for the output area when it should be height-limited */ +div.output_scroll { + /* ideally, this would be max-height, but FF barfs all over that */ + height: 24em; + /* FF needs this *and the wrapper* to specify full width, or it will shrinkwrap */ + width: 100%; + + overflow: auto; + border-radius: 3px; + box-shadow: inset 0 2px 8px rgba(0, 0, 0, .8); +} + +/* output div while it is collapsed */ +div.output_collapsed { + margin-right: 5px; +} + +div.out_prompt_overlay { + height: 100%; + padding: 0px; + position: absolute; + border-radius: 3px; +} + +div.out_prompt_overlay:hover { + /* use inner shadow to get border that is computed the same on WebKit/FF */ + box-shadow: inset 0 0 1px #000; + background: rgba(240, 240, 240, 0.5); +} + +div.output_prompt { + color: darkred; + /* 5px right shift to account for margin in parent container */ + margin: 0 5px 0 -5px; +} + +/* This class is the outer container of all output sections. */ +div.output_area { + padding: 0px; + page-break-inside: avoid; +} + +/* This class is for the output subarea inside the output_area and after + the prompt div. */ +div.output_subarea { + padding: 0.44em 0.4em 0.4em 1px; +} + +/* The rest of the output_* classes are for special styling of the different + output types */ + +/* all text output has this class: */ +div.output_text { + text-align: left; + color: black; + font-family: monospace; +} + +/* stdout/stderr are 'text' as well as 'stream', but pyout/pyerr are *not* streams */ +div.output_stream { + padding-top: 0.0em; + padding-bottom: 0.0em; +} +div.output_stdout { +} +div.output_stderr { + background: #fdd; /* very light red background for stderr */ +} + +div.output_latex { + text-align: left; + color: black; +} + +div.output_html { +} + +div.output_png { +} + +div.output_jpeg { +} + +div.text_cell { + background-color: white; + padding: 5px 5px 5px 5px; +} + +div.text_cell_input { + color: black; + border: 1px solid #ddd; + border-radius: 3px; + background: #f7f7f7; +} + +div.text_cell_render { + font-family: "Helvetica Neue", Arial, Helvetica, Geneva, sans-serif; + outline: none; + resize: none; + width: inherit; + border-style: none; + padding: 5px; + color: black; +} + +/* The following gets added to the <head> if it is detected that the user has a + * monospace font with inconsistent normal/bold/italic height. See + * notebookmain.js. Such fonts will have keywords vertically offset with + * respect to the rest of the text. The user should select a better font. + * See: https://github.com/ipython/ipython/issues/1503 + * + * .CodeMirror span { + * vertical-align: bottom; + * } + */ + +.CodeMirror { + line-height: 1.231; /* Changed from 1em to our global default */ +} + +.CodeMirror-scroll { + height: auto; /* Changed to auto to autogrow */ + /* The CodeMirror docs are a bit fuzzy on if overflow-y should be hidden or visible.*/ + /* We have found that if it is visible, vertical scrollbars appear with font size changes.*/ + overflow-y: hidden; + overflow-x: auto; /* Changed from auto to remove scrollbar */ +} + +/* CSS font colors for translated ANSI colors. */ + + +.ansiblack {color: black;} +.ansired {color: darkred;} +.ansigreen {color: darkgreen;} +.ansiyellow {color: brown;} +.ansiblue {color: darkblue;} +.ansipurple {color: darkviolet;} +.ansicyan {color: steelblue;} +.ansigrey {color: grey;} +.ansibold {font-weight: bold;} + +.completions { + position: absolute; + z-index: 10; + overflow: hidden; + border: 1px solid grey; +} + +.completions select { + background: white; + outline: none; + border: none; + padding: 0px; + margin: 0px; + overflow: auto; + font-family: monospace; +} + +option.context { + background-color: #DEF7FF; +} +option.introspection { + background-color: #EBF4EB; +} + +/*fixed part of the completion*/ +.completions p b { + font-weight:bold; +} + +.completions p { + background: #DDF; + /*outline: none; + padding: 0px;*/ + border-bottom: black solid 1px; + padding: 1px; + font-family: monospace; +} + +pre.dialog { + background-color: #f7f7f7; + border: 1px solid #ddd; + border-radius: 3px; + padding: 0.4em; + padding-left: 2em; +} + +p.dialog { + padding : 0.2em; +} + +.shortcut_key { + display: inline-block; + width: 15ex; + text-align: right; + font-family: monospace; +} + +.shortcut_descr { +} + +/* Word-wrap output correctly. This is the CSS3 spelling, though Firefox seems + to not honor it correctly. Webkit browsers (Chrome, rekonq, Safari) do. + */ +pre, code, kbd, samp { white-space: pre-wrap; } + +#fonttest { + font-family: monospace; +} + +.js-error { + color: darkred; +} + +</style> +<style type="text/css"> +.rendered_html {color: black;} +.rendered_html em {font-style: italic;} +.rendered_html strong {font-weight: bold;} +.rendered_html u {text-decoration: underline;} +.rendered_html :link { text-decoration: underline } +.rendered_html :visited { text-decoration: underline } +.rendered_html h1 {font-size: 197%; margin: .65em 0; font-weight: bold;} +.rendered_html h2 {font-size: 153.9%; margin: .75em 0; font-weight: bold;} +.rendered_html h3 {font-size: 123.1%; margin: .85em 0; font-weight: bold;} +.rendered_html h4 {font-size: 100% margin: 0.95em 0; font-weight: bold;} +.rendered_html h5 {font-size: 85%; margin: 1.5em 0; font-weight: bold;} +.rendered_html h6 {font-size: 77%; margin: 1.65em 0; font-weight: bold;} +.rendered_html ul {list-style:disc; margin: 1em 2em;} +.rendered_html ul ul {list-style:square; margin: 0em 2em;} +.rendered_html ul ul ul {list-style:circle; margin-left: 0em 2em;} +.rendered_html ol {list-style:upper-roman; margin: 1em 2em;} +.rendered_html ol ol {list-style:upper-alpha; margin: 0em 2em;} +.rendered_html ol ol ol {list-style:decimal; margin: 0em 2em;} +.rendered_html ol ol ol ol {list-style:lower-alpha; margin: 0em 2em;} +.rendered_html ol ol ol ol ol {list-style:lower-roman; margin: 0em 2em;} + +.rendered_html hr { + color: black; + background-color: black; +} + +.rendered_html pre { + margin: 1em 2em; +} + +.rendered_html blockquote { + margin: 1em 2em; +} + +.rendered_html table { + border: 1px solid black; + border-collapse: collapse; + margin: 1em 2em; +} + +.rendered_html td { + border: 1px solid black; + text-align: left; + vertical-align: middle; + padding: 4px; +} + +.rendered_html th { + border: 1px solid black; + text-align: left; + vertical-align: middle; + padding: 4px; + font-weight: bold; +} + +.rendered_html tr { + border: 1px solid black; +} + +.rendered_html p + p { + margin-top: 1em; +} + + +</style> +<style type="text/css"> +/* Overrides of notebook CSS for static HTML export + +*/ +body { + overflow: visible; + padding: 8px; +} +.input_area { + padding: 0.4em; +} + +</style> +<meta charset="UTF-8"> +<style type="text/css"> +.highlight .hll { background-color: #ffffcc } +.highlight { background: #f8f8f8; } +.highlight .c { color: #408080; font-style: italic } /* Comment */ +.highlight .err { border: 1px solid #FF0000 } /* Error */ +.highlight .k { color: #008000; font-weight: bold } /* Keyword */ +.highlight .o { color: #666666 } /* Operator */ +.highlight .cm { color: #408080; font-style: italic } /* Comment.Multiline */ +.highlight .cp { color: #BC7A00 } /* Comment.Preproc */ +.highlight .c1 { color: #408080; font-style: italic } /* Comment.Single */ +.highlight .cs { color: #408080; font-style: italic } /* Comment.Special */ +.highlight .gd { color: #A00000 } /* Generic.Deleted */ +.highlight .ge { font-style: italic } /* Generic.Emph */ +.highlight .gr { color: #FF0000 } /* Generic.Error */ +.highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */ +.highlight .gi { color: #00A000 } /* Generic.Inserted */ +.highlight .go { color: #808080 } /* Generic.Output */ +.highlight .gp { color: #000080; font-weight: bold } /* Generic.Prompt */ +.highlight .gs { font-weight: bold } /* Generic.Strong */ +.highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */ +.highlight .gt { color: #0040D0 } /* Generic.Traceback */ +.highlight .kc { color: #008000; font-weight: bold } /* Keyword.Constant */ +.highlight .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */ +.highlight .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */ +.highlight .kp { color: #008000 } /* Keyword.Pseudo */ +.highlight .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */ +.highlight .kt { color: #B00040 } /* Keyword.Type */ +.highlight .m { color: #666666 } /* Literal.Number */ +.highlight .s { color: #BA2121 } /* Literal.String */ +.highlight .na { color: #7D9029 } /* Name.Attribute */ +.highlight .nb { color: #008000 } /* Name.Builtin */ +.highlight .nc { color: #0000FF; font-weight: bold } /* Name.Class */ +.highlight .no { color: #880000 } /* Name.Constant */ +.highlight .nd { color: #AA22FF } /* Name.Decorator */ +.highlight .ni { color: #999999; font-weight: bold } /* Name.Entity */ +.highlight .ne { color: #D2413A; font-weight: bold } /* Name.Exception */ +.highlight .nf { color: #0000FF } /* Name.Function */ +.highlight .nl { color: #A0A000 } /* Name.Label */ +.highlight .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */ +.highlight .nt { color: #008000; font-weight: bold } /* Name.Tag */ +.highlight .nv { color: #19177C } /* Name.Variable */ +.highlight .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */ +.highlight .w { color: #bbbbbb } /* Text.Whitespace */ +.highlight .mf { color: #666666 } /* Literal.Number.Float */ +.highlight .mh { color: #666666 } /* Literal.Number.Hex */ +.highlight .mi { color: #666666 } /* Literal.Number.Integer */ +.highlight .mo { color: #666666 } /* Literal.Number.Oct */ +.highlight .sb { color: #BA2121 } /* Literal.String.Backtick */ +.highlight .sc { color: #BA2121 } /* Literal.String.Char */ +.highlight .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */ +.highlight .s2 { color: #BA2121 } /* Literal.String.Double */ +.highlight .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */ +.highlight .sh { color: #BA2121 } /* Literal.String.Heredoc */ +.highlight .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */ +.highlight .sx { color: #008000 } /* Literal.String.Other */ +.highlight .sr { color: #BB6688 } /* Literal.String.Regex */ +.highlight .s1 { color: #BA2121 } /* Literal.String.Single */ +.highlight .ss { color: #19177C } /* Literal.String.Symbol */ +.highlight .bp { color: #008000 } /* Name.Builtin.Pseudo */ +.highlight .vc { color: #19177C } /* Name.Variable.Class */ +.highlight .vg { color: #19177C } /* Name.Variable.Global */ +.highlight .vi { color: #19177C } /* Name.Variable.Instance */ +.highlight .il { color: #666666 } /* Literal.Number.Integer.Long */ +</style> +<script src="https://c328740.ssl.cf1.rackcdn.com/mathjax/latest/MathJax.js?config=TeX-AMS_HTML" type="text/javascript"> + +</script> +<script type="text/javascript"> +init_mathjax = function() { + if (window.MathJax) { + // MathJax loaded + MathJax.Hub.Config({ + tex2jax: { + inlineMath: [ ['$','$'], ["\\(","\\)"] ], + displayMath: [ ['$$','$$'], ["\\[","\\]"] ] + }, + displayAlign: 'left', // Change this to 'center' to center equations. + "HTML-CSS": { + styles: {'.MathJax_Display': {"margin": 0}} + } + }); + MathJax.Hub.Queue(["Typeset",MathJax.Hub]); + } +} +init_mathjax(); +</script> +</head> +{%- endblock header -%} + + +{% block body %} +<body>{{ super() }}<body/> + +{% endblock body %} + + + + + + + + +{% block footer %} +</html> +{% endblock footer %} diff --git a/templates/null.tpl b/templates/null.tpl new file mode 100644 index 0000000..bf51c9a --- /dev/null +++ b/templates/null.tpl @@ -0,0 +1,38 @@ +{%- extends 'basic.tpl' -%} + +{% block codecell scoped %} +{% block in_prompt %}{% endblock in_prompt %} +{% block input %}{% endblock input %} +{% if cell.outputs %} +{% block output_prompt %}{% endblock output_prompt %} +{%- for output in cell.outputs -%} + {%- if output.output_type in ['pyout']%} + {% block pyout scoped %}{% endblock pyout %} + {%- elif output.output_type in ['stream'] %} + {% block stream scoped %}{% endblock stream %} + {%- elif output.output_type in ['display_data'] %} + {% block display_data scoped %}{% endblock display_data %} + {%- elif output.output_type in ['pyerr'] %} + {% block pyerr scoped %} + {%- for line in output.traceback %} + {% block traceback_line scoped %} + {% endblock traceback_line %} + {%- endfor %} + {% endblock pyerr %} + {%- endif %} +{%- endfor -%} +{% endif %} + +{% endblock codecell %} + +{% block markdowncell scoped %} +{% endblock markdowncell %} + +{% block headingcell scoped %} +{% endblock headingcell %} + +{% block rawcell scoped %} +{% endblock rawcell %} + +{% block unknowncell scoped %} +{% endblock unknowncell %} diff --git a/templates/python.tpl b/templates/python.tpl index 40cfc5e..7ad1c02 100644 --- a/templates/python.tpl +++ b/templates/python.tpl @@ -1,5 +1,20 @@ -{%- extends 'basic.tpl' -%} +{%- extends 'null.tpl' -%} +{% block in_prompt %} +# In[{{cell.prompt_number if cell.prompt_number else ' '}}]: +{% endblock in_prompt %} + +{% block traceback_line %} +{{ line |indent| rm_ansi }} +{% endblock traceback_line %} + + +{% block pyout %} +{{ output.text| indent | pycomment}} +{% endblock pyout %} + + +{# {% block codecell scoped %} # In[{{cell.prompt_number if cell.prompt_number else ' '}}]: {{ cell.input }} @@ -7,31 +22,27 @@ # Out[{{cell.prompt_number}}]: {%- for output in cell.outputs -%} {%- if output.output_type in ['pyout','stream']%} -{{ output.text| indent | pycomment}} + {%- elif output.output_type in ['display_data'] %} {{"# image file: fucking display_data"}} - {%- elif output.output_type in ['pyerr'] %} - {%- for line in output.traceback %} -{{ line |indent| rm_ansi}} - {%- endfor %} - {%- endif %} {%- endfor -%} {% endif %} {% endblock codecell %} +#} {% block markdowncell scoped %} -{{ cell.source | pycomment | rm_fake}} +{#{{ cell.source | pycomment | rm_fake}}#} {% endblock markdowncell %} {% block headingcell scoped %} -{{ '#' * cell.level }}{{ cell.source | pycomment}} +{#{{ '#' * cell.level }}{{ cell.source | pycomment}}#} {% endblock headingcell %} {% block rawcell scoped %} -{{ cell.source | pycomment }} +{#{{ cell.source | pycomment }}#} {% endblock rawcell %} {% block unknowncell scoped %} -unknown type {{cell.type}} +{#unknown type {{cell.type}}#} {% endblock unknowncell %}