From d5a4e2e2cc13f82059f103581caf629021e98cc8 2013-05-14 06:09:45 From: Jonathan Frederic Date: 2013-05-14 06:09:45 Subject: [PATCH] Almost have nbconvert working again... --- diff --git a/nbconvert.py b/nbconvert.py index 92777c7..9d70d42 100755 --- a/nbconvert.py +++ b/nbconvert.py @@ -92,7 +92,7 @@ class NbconvertApp(Application): #Export output, resources, exporter = export_by_name(ipynb_file, export_type) - + destination_filename = None destination_directory = None if exporter.write: @@ -149,7 +149,7 @@ def main(): app = NbconvertApp.instance() app.description = __doc__ - app.run(argv=sys.argv) + app.start(argv=sys.argv) if __name__ == '__main__': main() \ No newline at end of file diff --git a/nbconvert/api/exporter.py b/nbconvert/api/exporter.py index 2be0057..3e338e0 100755 --- a/nbconvert/api/exporter.py +++ b/nbconvert/api/exporter.py @@ -39,7 +39,7 @@ import nbconvert.filters.strings import nbconvert.filters.markdown import nbconvert.filters.latex import nbconvert.filters.datatypefilter -import nbconvert.filters.pygments +import nbconvert.filters.highlight import nbconvert.filters.ansi import nbconvert.transformers.extractfigure @@ -184,9 +184,9 @@ class Exporter(Configurable): self.register_filter('ansi2html', nbconvert.filters.ansi.ansi2html) self.register_filter('filter_data_type', nbconvert.filters.datatypefilter.DataTypeFilter) self.register_filter('get_lines', nbconvert.filters.strings.get_lines) - self.register_filter('highlight', nbconvert.filters.pygments.highlight) - self.register_filter('highlight2html', nbconvert.filters.pygments.highlight) - self.register_filter('highlight2latex', nbconvert.filters.pygments.highlight2latex) + self.register_filter('highlight', nbconvert.filters.highlight.highlight) + self.register_filter('highlight2html', nbconvert.filters.highlight.highlight) + self.register_filter('highlight2latex', nbconvert.filters.highlight.highlight2latex) self.register_filter('markdown2latex', nbconvert.filters.markdown.markdown2latex) self.register_filter('markdown2rst', nbconvert.filters.markdown.markdown2rst) self.register_filter('pycomment', nbconvert.filters.strings.python_comment) diff --git a/nbconvert/api/html.py b/nbconvert/api/html.py index ab81256..9fe3060 100644 --- a/nbconvert/api/html.py +++ b/nbconvert/api/html.py @@ -35,7 +35,7 @@ class HtmlExporter(exporter.Exporter): def _register_transformers(self): #Register the transformers of the base class. - super(exporter.Exporter, self)._register_transformers() + super(HtmlExporter, self)._register_transformers() #Register latex transformer self.register_transformer(nbconvert.transformers.csshtmlheader.CSSHtmlHeaderTransformer) diff --git a/nbconvert/api/latex.py b/nbconvert/api/latex.py index b449b30..abafb86 100755 --- a/nbconvert/api/latex.py +++ b/nbconvert/api/latex.py @@ -22,15 +22,15 @@ from jinja2 import Environment, FileSystemLoader # local import import exporter import nbconvert.filters.latex -import nbconvert.filters.pygments +import nbconvert.filters.highlight from nbconvert.transformers.latex import LatexTransformer #----------------------------------------------------------------------------- # Globals and constants #----------------------------------------------------------------------------- #Latex Jinja2 constants -LATEX_TEMPLATE_PATH = "/../templates/tex/" -LATEX_TEMPLATE_SKELETON_PATH = "/../templates/tex/skeleton/" +LATEX_TEMPLATE_PATH = "/../templates/latex/" +LATEX_TEMPLATE_SKELETON_PATH = "/../templates/latex/skeleton/" #Special Jinja2 syntax that will not conflict when exporting latex. LATEX_JINJA_COMMENT_BLOCK = ["((=", "=))"] @@ -50,13 +50,13 @@ class LatexExporter(exporter.Exporter): help="Extension of the file that should be written to disk") template_file = Unicode( - 'latex_base', config=True, + 'base', config=True, help="Name of the template file to use") def __init__(self, preprocessors=None, jinja_filters=None, config=None, **kw): #Call base class constructor. - super(exporter.Exporter, self).__init__(preprocessors, jinja_filters, config, **kw) + super(LatexExporter, self).__init__(preprocessors, jinja_filters, config, **kw) self.extract_figure_transformer.display_data_priority = ['latex', 'svg', 'png', 'jpg', 'jpeg' , 'text'] self.extract_figure_transformer.extra_ext_map={'svg':'pdf'} @@ -83,16 +83,16 @@ class LatexExporter(exporter.Exporter): def _register_filters(self): #Register the filters of the base class. - super(exporter.Exporter, self)._register_filters() + super(LatexExporter, self)._register_filters() #Add latex filters to the Jinja2 environment - self.register_filter('escape_tex', filters.latex.escape_tex) - self.register_filter('highlight', filters.pygments.highlight2latex) + self.register_filter('escape_tex', nbconvert.filters.latex.escape_tex) + self.register_filter('highlight', nbconvert.filters.highlight.highlight2latex) def _register_transformers(self): #Register the transformers of the base class. - super(exporter.Exporter, self)._register_transformers() + super(LatexExporter, self)._register_transformers() #Register latex transformer self.register_transformer(LatexTransformer) diff --git a/nbconvert/api/python.py b/nbconvert/api/python.py index bebc8fa..6084f5f 100644 --- a/nbconvert/api/python.py +++ b/nbconvert/api/python.py @@ -33,7 +33,7 @@ class PythonExporter(exporter.Exporter): def __init__(self, preprocessors=None, jinja_filters=None, config=None, armor=False, **kw): #Call base class constructor. - super(exporter.Exporter, self).__init__(preprocessors, jinja_filters, config, **kw) + super(PythonExporter, self).__init__(preprocessors, jinja_filters, config, **kw) #Set defaults self.extract_figure_transformer.enabled = False diff --git a/nbconvert/api/reveal.py b/nbconvert/api/reveal.py index 1b95290..4a14bb0 100644 --- a/nbconvert/api/reveal.py +++ b/nbconvert/api/reveal.py @@ -34,8 +34,8 @@ class RevealExporter(html.HtmlExporter): def _register_transformers(self): #Register the transformers of the base class. - super(html_exporter.HtmlExporter, self)._register_transformers() + super(RevealExporter, self)._register_transformers() #Register reveal help transformer - self.register_transformer(transformers.revealhelp.RevealHelpTransformer) + self.register_transformer(nbconvert.transformers.revealhelp.RevealHelpTransformer) \ No newline at end of file diff --git a/nbconvert/api/sphinx.py b/nbconvert/api/sphinx.py index ed5b096..8b97822 100644 --- a/nbconvert/api/sphinx.py +++ b/nbconvert/api/sphinx.py @@ -21,13 +21,13 @@ from nbconvert.transformers.sphinx import SphinxTransformer class SphinxExporter(latex.LatexExporter): template_file = Unicode( - 'sphinxhowto', config=True, + 'sphinx_howto', config=True, help="Name of the template file to use") def _register_transformers(self): #Register the transformers of the base class. - super(latex.LatexExporter, self)._register_transformers() + super(SphinxExporter, self)._register_transformers() #Register sphinx latex transformer self.register_transformer(SphinxTransformer) diff --git a/nbconvert/filters/datatypefilter.py b/nbconvert/filters/datatypefilter.py index db7aba2..c384ef6 100755 --- a/nbconvert/filters/datatypefilter.py +++ b/nbconvert/filters/datatypefilter.py @@ -22,10 +22,9 @@ class DataTypeFilter(object): display_data_priority = None def __init__(self, display_data_priority): - super(object, self).__init__() #Make sure that the display data priority variably is not None. - if self.display_data_priority is None: + if display_data_priority is None: raise TypeError else: self.display_data_priority = display_data_priority diff --git a/nbconvert/filters/highlight.py b/nbconvert/filters/highlight.py index e6229b4..3a953c0 100644 --- a/nbconvert/filters/highlight.py +++ b/nbconvert/filters/highlight.py @@ -1,3 +1,9 @@ + +from pygments import highlight as pygements_highlight +from pygments.lexers import get_lexer_by_name +from pygments.formatters import HtmlFormatter +from pygments.formatters import LatexFormatter + # Our own imports from nbconvert.utils.lexers import IPythonLexer @@ -14,26 +20,22 @@ def highlight(src, lang='ipython'): """ Return a syntax-highlighted version of the input source as html output. """ - from pygments.formatters import HtmlFormatter - return pygment_highlight(src, HtmlFormatter(), lang) + + return _pygment_highlight(src, HtmlFormatter(), lang) def highlight2latex(src, lang='ipython'): """ Return a syntax-highlighted version of the input source as latex output. """ - from pygments.formatters import LatexFormatter - return pygment_highlight(src, LatexFormatter(), lang) + return _pygment_highlight(src, LatexFormatter(), lang) -def pygment_highlight(src, output_formatter, lang='ipython'): +def _pygment_highlight(src, output_formatter, lang='ipython'): """ Return a syntax-highlighted version of the input source """ - from pygments import highlight - from pygments.lexers import get_lexer_by_name - if lang == 'ipython': lexer = IPythonLexer() else: lexer = get_lexer_by_name(lang, stripall=True) - return highlight(src, lexer, output_formatter) + return pygements_highlight(src, lexer, output_formatter) diff --git a/nbconvert/templates/latex/skeleton/null.tplx b/nbconvert/templates/latex/skeleton/null.tplx index e818d65..7c14be9 100644 --- a/nbconvert/templates/latex/skeleton/null.tplx +++ b/nbconvert/templates/latex/skeleton/null.tplx @@ -28,7 +28,7 @@ consider calling super even if it is a leave block, we might insert more blocks ((*- for worksheet in nb.worksheets -*)) ((*- for cell in worksheet.cells -*)) ((*- block any_cell scoped -*)) - ((*- if cell.type in ['code'] -*)) + ((*- if cell.cell_type in ['code'] -*)) ((*- block codecell scoped -*)) ((*- block input_group -*)) ((*- block in_prompt -*))((*- endblock in_prompt -*)) @@ -70,13 +70,13 @@ consider calling super even if it is a leave block, we might insert more blocks ((*- endblock output_group -*)) ((*- endif -*)) ((*- endblock codecell -*)) - ((*- elif cell.type in ['markdown'] -*)) + ((*- elif cell.cell_type in ['markdown'] -*)) ((*- block markdowncell scoped-*)) ((*- endblock markdowncell -*)) - ((*- elif cell.type in ['heading'] -*)) + ((*- elif cell.cell_type in ['heading'] -*)) ((*- block headingcell scoped-*)) ((*- endblock headingcell -*)) - ((*- elif cell.type in ['raw'] -*)) + ((*- elif cell.cell_type in ['raw'] -*)) ((*- block rawcell scoped-*)) ((*- endblock rawcell -*)) ((*- else -*)) diff --git a/nbconvert/templates/latex/sphinx_base.tplx b/nbconvert/templates/latex/sphinx_base.tplx index bd945fd..19feeea 100644 --- a/nbconvert/templates/latex/sphinx_base.tplx +++ b/nbconvert/templates/latex/sphinx_base.tplx @@ -3,7 +3,7 @@ Purpose: Allow export of PDF friendly Latex inspired by Sphinx. Most of the template is derived directly from Sphinx source. -Inheritance: null>display_priority>latex_base +Inheritance: null>display_priority Note: For best display, use latex syntax highlighting. =)) diff --git a/nbconvert/templates/latex/sphinx_howto.tplx b/nbconvert/templates/latex/sphinx_howto.tplx index b6bafb4..b82f855 100644 --- a/nbconvert/templates/latex/sphinx_howto.tplx +++ b/nbconvert/templates/latex/sphinx_howto.tplx @@ -8,7 +8,7 @@ ==========================================================================)) -((*- extends 'latex_sphinx_base.tplx' -*)) +((*- extends 'sphinx_base.tplx' -*)) ((* set parentdocumentclass = 'article' *)) ((* set documentclass = 'howto' *)) diff --git a/nbconvert/templates/latex/sphinx_manual.tplx b/nbconvert/templates/latex/sphinx_manual.tplx index bbdda55..ddb04b4 100644 --- a/nbconvert/templates/latex/sphinx_manual.tplx +++ b/nbconvert/templates/latex/sphinx_manual.tplx @@ -8,7 +8,7 @@ ==========================================================================)) -((*- extends 'latex_sphinx_base.tplx' -*)) +((*- extends 'sphinx_base.tplx' -*)) ((* set parentdocumentclass = 'report' *)) ((* set documentclass = 'manual' *)) diff --git a/nbconvert/templates/skeleton/null.tpl b/nbconvert/templates/skeleton/null.tpl index e048b69..b0d4f3d 100644 --- a/nbconvert/templates/skeleton/null.tpl +++ b/nbconvert/templates/skeleton/null.tpl @@ -27,7 +27,7 @@ consider calling super even if it is a leave block, we might insert more blocks {%- for worksheet in nb.worksheets -%} {%- for cell in worksheet.cells -%} {%- block any_cell scoped -%} - {%- if cell.type in ['code'] -%} + {%- if cell.cell_type in ['code'] -%} {%- block codecell scoped -%} {%- block input_group -%} {%- block in_prompt -%}{%- endblock in_prompt -%} @@ -69,13 +69,13 @@ consider calling super even if it is a leave block, we might insert more blocks {%- endblock output_group -%} {%- endif -%} {%- endblock codecell -%} - {%- elif cell.type in ['markdown'] -%} + {%- elif cell.cell_type in ['markdown'] -%} {%- block markdowncell scoped-%} {%- endblock markdowncell -%} - {%- elif cell.type in ['heading'] -%} + {%- elif cell.cell_type in ['heading'] -%} {%- block headingcell scoped-%} {%- endblock headingcell -%} - {%- elif cell.type in ['raw'] -%} + {%- elif cell.cell_type in ['raw'] -%} {%- block rawcell scoped-%} {%- endblock rawcell -%} {%- else -%} diff --git a/nbconvert/transformers/activatable.py b/nbconvert/transformers/activatable.py index 80c0eb9..662295a 100755 --- a/nbconvert/transformers/activatable.py +++ b/nbconvert/transformers/activatable.py @@ -10,7 +10,7 @@ class ActivatableTransformer(ConfigurableTransformer): c.YourTransformerName.enabled = True """ - enabled = Bool(False, config=True) + enabled = Bool(True, config=True) def __call__(self, nb, other): if not self.enabled :