From 61e201605e18fcd2d5e98b31f5a0687ce1afd82d 2013-02-13 19:30:02 From: Matthias BUSSONNIER Date: 2013-02-13 19:30:02 Subject: [PATCH] deal with worksheets --- diff --git a/converters/template.py b/converters/template.py index c42896a..c3853f3 100755 --- a/converters/template.py +++ b/converters/template.py @@ -70,7 +70,7 @@ class ConverterTemplate(Configurable): #------------------------------------------------------------------------- infile = Any() - + infile_dir = Unicode() def __init__(self, tplfile='fullhtml', config=None, **kw): @@ -87,17 +87,12 @@ class ConverterTemplate(Configurable): for worksheet in self.nb.worksheets: for cell in worksheet.cells: cell.type = cell.cell_type - converted_cells.append(cell) - continue - if cell.cell_type in ('code'): - converted_cells.append({'type':'code','source':cell.input}) - else : - converted_cells.append({'type':cell.cell_type,'source': python_comment(cell.source)}) + converted_cells.append(worksheet) return converted_cells def convert(self, cell_separator='\n'): - return self.template.render(cells=self.process()) + return self.template.render(worksheets=self.process()) def read(self, filename): diff --git a/templates/basic.tpl b/templates/basic.tpl index 613c756..0eae91c 100644 --- a/templates/basic.tpl +++ b/templates/basic.tpl @@ -1,25 +1,27 @@ {%- block header -%} {%- endblock header -%} {%- block body -%} -{%- for cell in cells -%} - {%- block any_cell scoped -%} - {%- if cell.type in ['code'] -%} - {%- block codecell scoped-%} - {%- endblock codecell-%} - {%- elif cell.type in ['markdown'] -%} - {%- block markdowncell scoped-%} - {%- endblock markdowncell -%} - {%- elif cell.type in ['heading'] -%} - {%- block headingcell scoped-%} - {%- endblock headingcell -%} - {%- elif cell.type in ['raw'] -%} - {%- block rawcell scoped-%} - {%- endblock rawcell -%} - {%- else -%} - {%- block unknowncell scoped-%} - {%- endblock unknowncell -%} - {%- endif -%} - {%- endblock any_cell -%} +{%- for worksheet in worksheets -%} + {%- for cell in worksheet.cells -%} + {%- block any_cell scoped -%} + {%- if cell.type in ['code'] -%} + {%- block codecell scoped-%} + {%- endblock codecell-%} + {%- elif cell.type in ['markdown'] -%} + {%- block markdowncell scoped-%} + {%- endblock markdowncell -%} + {%- elif cell.type in ['heading'] -%} + {%- block headingcell scoped-%} + {%- endblock headingcell -%} + {%- elif cell.type in ['raw'] -%} + {%- block rawcell scoped-%} + {%- endblock rawcell -%} + {%- else -%} + {%- block unknowncell scoped-%} + {%- endblock unknowncell -%} + {%- endif -%} + {%- endblock any_cell -%} + {%- endfor -%} {%- endfor -%} {%- endblock body -%} diff --git a/templates/null.tpl b/templates/null.tpl index 7c30267..ba89138 100644 --- a/templates/null.tpl +++ b/templates/null.tpl @@ -40,12 +40,10 @@ consider calling super even if block is leave block, we might insert more block {% endblock pyerr %} {%- endif %} {%- endfor -%} -{% endif %} +{% endif -%} +{%- endblock codecell %} -{% endblock codecell %} - -{% block markdowncell scoped %} -{% endblock markdowncell %} +{% block markdowncell scoped %}{% endblock markdowncell %} {% block headingcell scoped %} {% endblock headingcell %} diff --git a/templates/python-armor.tpl b/templates/python-armor.tpl index 018af6f..6deb991 100644 --- a/templates/python-armor.tpl +++ b/templates/python-armor.tpl @@ -1,9 +1,31 @@ {%- extends 'python.tpl' -%} -{% block any_cell %} +{#% block any_cell %} ============================== =======start {{cell.type}}========= {{ super() }} ======= end {{cell.type}} ========= -=============================={% endblock any_cell %} +=============================={% endblock any_cell %#} + + + +{% block markdowncell %}---- Start MD ----{{ super() }} +---- End MD ---- +{% endblock markdowncell %} + +{% block codecell %}---- Start Code ----{{ super() }} +---- End Code ---- +{% endblock codecell %} + +{% block headingcell scoped %}---- Start heading ----{{ super() }} +---- End heading ---- +{% endblock headingcell %} + +{% block rawcell scoped %}---- Start Raw ---- +{{ super() }} +---- End Raw ----{% endblock rawcell %} + +{% block unknowncell scoped %} +unknown type {{cell.type}} +{% endblock unknowncell %} diff --git a/templates/python.tpl b/templates/python.tpl index fcc56a0..8576f9f 100644 --- a/templates/python.tpl +++ b/templates/python.tpl @@ -23,23 +23,9 @@ {% block display_data scoped %} # image file:{% endblock display_data %} -{# -{% block codecell scoped %} -# In[{{cell.prompt_number if cell.prompt_number else ' '}}]: -{% if cell.outputs %} -{%- for output in cell.outputs -%} - {%- if output.output_type in ['pyout','stream']%} - - {%- elif output.output_type in ['display_data'] %} -{{"# image file: fucking display_data"}} -{%- endfor -%} -{% endif %} - -{% endblock codecell %} -#} - {% block markdowncell scoped %} -{{ cell.source | pycomment | rm_fake}}{% endblock markdowncell %} +{{ cell.source | pycomment }} +{% endblock markdowncell %} {% block headingcell scoped %} {{ '#' * cell.level }}{{ cell.source | pycomment}}