diff --git a/IPython/nbconvert/exporters/__init__.py b/IPython/nbconvert/exporters/__init__.py index dca2a59..10d570d 100755 --- a/IPython/nbconvert/exporters/__init__.py +++ b/IPython/nbconvert/exporters/__init__.py @@ -1,11 +1,7 @@ -from .basichtml import BasicHTMLExporter +from .html import HTMLExporter from .export import * from .exporter import Exporter -from .fullhtml import FullHTMLExporter -from .reveal import RevealExporter from .latex import LatexExporter from .markdown import MarkdownExporter from .python import PythonExporter from .rst import RSTExporter -from .sphinx_howto import SphinxHowtoExporter -from .sphinx_manual import SphinxManualExporter diff --git a/IPython/nbconvert/exporters/_fullhtml.py b/IPython/nbconvert/exporters/_fullhtml.py deleted file mode 100644 index e0f2fcd..0000000 --- a/IPython/nbconvert/exporters/_fullhtml.py +++ /dev/null @@ -1,39 +0,0 @@ -""" -Exporter for exporting full HTML documents. -""" - -#----------------------------------------------------------------------------- -# Copyright (c) 2013, the IPython Development Team. -# -# Distributed under the terms of the Modified BSD License. -# -# The full license is in the file COPYING.txt, distributed with this software. -#----------------------------------------------------------------------------- - -#----------------------------------------------------------------------------- -# Imports -#----------------------------------------------------------------------------- - -from IPython.utils.traitlets import Unicode - -from .basichtml import BasicHTMLExporter -from IPython.config import Config - -#----------------------------------------------------------------------------- -# Classes -#----------------------------------------------------------------------------- - -class FullHTMLExporter(BasicHTMLExporter): - """ - Exports a full HTML document. - """ - - template_file = Unicode( - 'fullhtml', config=True, - help="Name of the template file to use") - - @property - def default_config(self): - c = Config({'CSSHTMLHeaderTransformer':{'enabled':True}}) - c.merge(super(FullHTMLExporter,self).default_config) - return c diff --git a/IPython/nbconvert/exporters/_reveal.py b/IPython/nbconvert/exporters/_reveal.py deleted file mode 100644 index ec87bcf..0000000 --- a/IPython/nbconvert/exporters/_reveal.py +++ /dev/null @@ -1,51 +0,0 @@ -""" -Reveal slide show exporter. -""" -#----------------------------------------------------------------------------- -# Copyright (c) 2013, the IPython Development Team. -# -# Distributed under the terms of the Modified BSD License. -# -# The full license is in the file COPYING.txt, distributed with this software. -#----------------------------------------------------------------------------- - -#----------------------------------------------------------------------------- -# Imports -#----------------------------------------------------------------------------- - -from IPython.utils.traitlets import Unicode, List -from IPython.config import Config - -from .basichtml import BasicHTMLExporter -from IPython.nbconvert import transformers - -#----------------------------------------------------------------------------- -# Classes -#----------------------------------------------------------------------------- - -class RevealExporter(BasicHTMLExporter): - """ - Exports a Reveal slide show (.HTML) which may be rendered in a web browser. - """ - - file_extension = Unicode( - 'reveal.html', config=True, - help="Extension of the file that should be written to disk") - - template_file = Unicode( - 'reveal', config=True, - help="Name of the template file to use") - - - @property - def default_config(self): - c = Config({ - 'CSSHTMLHeaderTransformer':{ - 'enabled':True - }, - 'RevealHelpTransformer':{ - 'enabled':True, - }, - }) - c.merge(super(RevealExporter,self).default_config) - return c diff --git a/IPython/nbconvert/exporters/_sphinx_howto.py b/IPython/nbconvert/exporters/_sphinx_howto.py deleted file mode 100644 index b771978..0000000 --- a/IPython/nbconvert/exporters/_sphinx_howto.py +++ /dev/null @@ -1,44 +0,0 @@ -""" -Exporter for exporting notebooks to Sphinx 'HowTo' style latex. Latex -formatted for use with PDFLatex. -""" -#----------------------------------------------------------------------------- -# Copyright (c) 2013, the IPython Development Team. -# -# Distributed under the terms of the Modified BSD License. -# -# The full license is in the file COPYING.txt, distributed with this software. -#----------------------------------------------------------------------------- - -#----------------------------------------------------------------------------- -# Imports -#----------------------------------------------------------------------------- - -from IPython.utils.traitlets import Unicode, List -from IPython.config import Config - -# local import -from .latex import LatexExporter - -from IPython.nbconvert import transformers - -#----------------------------------------------------------------------------- -# Classes -#----------------------------------------------------------------------------- - -class SphinxHowtoExporter(LatexExporter): - """ - Exports Sphinx "HowTo" LaTeX documents. The Sphinx "HowTo" exporter - produces short document format latex for use with PDFLatex. - """ - - template_file = Unicode( - 'sphinx_howto', config=True, - help="Name of the template file to use") - - - @property - def default_config(self): - c = Config({'SphinxTransformer': {'enabled':True}}) - c.merge(super(SphinxHowtoExporter,self).default_config) - return c diff --git a/IPython/nbconvert/exporters/_sphinx_manual.py b/IPython/nbconvert/exporters/_sphinx_manual.py deleted file mode 100644 index 6dd6896..0000000 --- a/IPython/nbconvert/exporters/_sphinx_manual.py +++ /dev/null @@ -1,34 +0,0 @@ -""" -Exporter for exporting notebooks to Sphinx 'Manual' style latex. Latex -formatted for use with PDFLatex. -""" -#----------------------------------------------------------------------------- -# Copyright (c) 2013, the IPython Development Team. -# -# Distributed under the terms of the Modified BSD License. -# -# The full license is in the file COPYING.txt, distributed with this software. -#----------------------------------------------------------------------------- - -#----------------------------------------------------------------------------- -# Imports -#----------------------------------------------------------------------------- - -from IPython.utils.traitlets import Unicode - -from .sphinx_howto import SphinxHowtoExporter - -#----------------------------------------------------------------------------- -# Classes -#----------------------------------------------------------------------------- - -class SphinxManualExporter(SphinxHowtoExporter): - """ - Exports Sphinx "Manual" LaTeX documents. The Sphinx "Manual" exporter - produces book like latex output for use with PDFLatex. - """ - - template_file = Unicode( - 'sphinx_manual', config=True, - help="Name of the template file to use") - \ No newline at end of file diff --git a/IPython/nbconvert/exporters/export.py b/IPython/nbconvert/exporters/export.py index 83d3bcf..903fe68 100755 --- a/IPython/nbconvert/exporters/export.py +++ b/IPython/nbconvert/exporters/export.py @@ -19,15 +19,11 @@ from IPython.nbformat.v3.nbbase import NotebookNode from IPython.config import Config from .exporter import Exporter -from .basichtml import BasicHTMLExporter -from .fullhtml import FullHTMLExporter +from .html import HTMLExporter from .latex import LatexExporter from .markdown import MarkdownExporter from .python import PythonExporter -from .reveal import RevealExporter from .rst import RSTExporter -from .sphinx_howto import SphinxHowtoExporter -from .sphinx_manual import SphinxManualExporter #----------------------------------------------------------------------------- # Classes @@ -69,14 +65,10 @@ def DocDecorator(f): __all__ = [ 'export', - 'export_sphinx_manual', - 'export_sphinx_howto', - 'export_basic_html', - 'export_full_html', + 'export_html', 'export_latex', 'export_markdown', 'export_python', - 'export_reveal', 'export_rst', 'export_by_name', 'get_export_names', @@ -126,35 +118,11 @@ def export(exporter, nb, **kw): @DocDecorator -def export_sphinx_manual(nb, **kw): - """ - Export a notebook object to Sphinx Manual LaTeX - """ - return export(SphinxManualExporter, nb, **kw) - - -@DocDecorator -def export_sphinx_howto(nb, **kw): - """ - Export a notebook object to Sphinx HowTo LaTeX - """ - return export(SphinxHowtoExporter, nb, **kw) - - -@DocDecorator -def export_basic_html(nb, **kw): +def export_html(nb, **kw): """ Export a notebook object to Basic HTML """ - return export(BasicHTMLExporter, nb, **kw) - - -@DocDecorator -def export_full_html(nb, **kw): - """ - Export a notebook object to Full HTML - """ - return export(FullHTMLExporter, nb, **kw) + return export(HTMLExporter, nb, **kw) @DocDecorator @@ -182,14 +150,6 @@ def export_python(nb, **kw): @DocDecorator -def export_reveal(nb, **kw): - """ - Export a notebook object to a Reveal.js presentation - """ - return export(RevealExporter, nb, **kw) - - -@DocDecorator def export_rst(nb, **kw): """ Export a notebook object to reStructuredText diff --git a/IPython/nbconvert/exporters/exporter.py b/IPython/nbconvert/exporters/exporter.py index c6cde2f..1f14099 100755 --- a/IPython/nbconvert/exporters/exporter.py +++ b/IPython/nbconvert/exporters/exporter.py @@ -86,16 +86,17 @@ class Exporter(Configurable): transformers provided by default suffice, there is no need to inherit from this class. Instead, override the template_file and file_extension traits via a config file. - - {filters} """ # finish the docstring __doc__ = __doc__.format(filters = '- '+'\n - '.join(default_filters.keys())) + flavor = Unicode(config=True, help="""Flavor of the data format to use. + I.E. 'full' or 'basic'""") + template_file = Unicode( - '', config=True, + config=True, help="Name of the template file to use") file_extension = Unicode( @@ -155,6 +156,9 @@ class Exporter(Configurable): extra_loaders : list[of Jinja Loaders] ordered list of Jinja loder to find templates. Will be tried in order before the default FileSysteme ones. + flavor : str + Flavor to use when exporting. This determines what template to use + if one hasn't been specifically provided. """ #Call the base class constructor @@ -165,6 +169,7 @@ class Exporter(Configurable): super(Exporter, self).__init__(config=c, **kw) #Init + self._init_template(**kw) self._init_environment(extra_loaders=extra_loaders) self._init_transformers() self._init_filters() @@ -329,6 +334,25 @@ class Exporter(Configurable): raise TypeError('filter') + def _init_template(self, **kw): + """ + Make sure a template name is specified. If one isn't specified, try to + build one from the information we know. + """ + + # Set the template_file if it has not been set explicitly. + if not self.template_file: + + # Build the template file name from the name of the exporter and the + # flavor (if available). The flavor can be set on the traitlet + # or passed in as a kw arg. The flavor specified in kw overrides + # what is set in the flavor traitlet. + if self.flavor or 'flavor' in kw: + self.template_file = self.__name__ + '_' + kw.get('flavor', self.flavor) + else: + self.template_file = self.__name__ + + def _init_environment(self, extra_loaders=None): """ Create the Jinja templating environment. diff --git a/IPython/nbconvert/exporters/html.py b/IPython/nbconvert/exporters/html.py index e90c16f..e17f965 100644 --- a/IPython/nbconvert/exporters/html.py +++ b/IPython/nbconvert/exporters/html.py @@ -24,7 +24,7 @@ from .exporter import Exporter # Classes #----------------------------------------------------------------------------- -class BasicHTMLExporter(Exporter): +class HTMLExporter(Exporter): """ Exports a basic HTML document. This exporter assists with the export of HTML. Inherit from it if you are writing your own HTML template and need @@ -37,6 +37,18 @@ class BasicHTMLExporter(Exporter): help="Extension of the file that should be written to disk" ) - template_file = Unicode( - 'basichtml', config=True, - help="Name of the template file to use") + flavor = Unicode('full', config=True, help="""Flavor of the data format to + use. I.E. 'full' or 'basic'""") + + @property + def default_config(self): + c = Config({ + 'CSSHTMLHeaderTransformer':{ + 'enabled':True + }, + 'RevealHelpTransformer':{ + 'enabled':True, + }, + }) + c.merge(super(RevealExporter,self).default_config) + return c diff --git a/IPython/nbconvert/exporters/latex.py b/IPython/nbconvert/exporters/latex.py index 66751ce..c3e0da0 100755 --- a/IPython/nbconvert/exporters/latex.py +++ b/IPython/nbconvert/exporters/latex.py @@ -44,9 +44,8 @@ class LatexExporter(Exporter): 'tex', config=True, help="Extension of the file that should be written to disk") - template_file = Unicode( - 'base', config=True, - help="Name of the template file to use") + flavor = Unicode('article', config=True, help="""Flavor of the data format to + use. I.E. 'full' or 'basic'""") #Latex constants default_template_path = Unicode( @@ -68,6 +67,7 @@ class LatexExporter(Exporter): #Extension that the template files use. template_extension = Unicode(".tplx", config=True) + @property def default_config(self): c = Config({ @@ -83,6 +83,9 @@ class LatexExporter(Exporter): 'LatexTransformer': { 'enabled':True } + 'SphinxTransformer': { + 'enabled':True + } }) c.merge(super(LatexExporter,self).default_config) return c diff --git a/IPython/nbconvert/exporters/markdown.py b/IPython/nbconvert/exporters/markdown.py index 7c38f43..160fd67 100644 --- a/IPython/nbconvert/exporters/markdown.py +++ b/IPython/nbconvert/exporters/markdown.py @@ -29,7 +29,3 @@ class MarkdownExporter(Exporter): file_extension = Unicode( 'md', config=True, help="Extension of the file that should be written to disk") - - template_file = Unicode( - 'markdown', config=True, - help="Name of the template file to use") diff --git a/IPython/nbconvert/exporters/python.py b/IPython/nbconvert/exporters/python.py index b6bae64..9fe2a94 100644 --- a/IPython/nbconvert/exporters/python.py +++ b/IPython/nbconvert/exporters/python.py @@ -29,7 +29,3 @@ class PythonExporter(Exporter): file_extension = Unicode( 'py', config=True, help="Extension of the file that should be written to disk") - - template_file = Unicode( - 'python', config=True, - help="Name of the template file to use") diff --git a/IPython/nbconvert/exporters/rst.py b/IPython/nbconvert/exporters/rst.py index 1388a63..0204e13 100644 --- a/IPython/nbconvert/exporters/rst.py +++ b/IPython/nbconvert/exporters/rst.py @@ -31,10 +31,6 @@ class RSTExporter(Exporter): 'rst', config=True, help="Extension of the file that should be written to disk") - template_file = Unicode( - 'rst', config=True, - help="Name of the template file to use") - @property def default_config(self): c = Config({'ExtractOutputTransformer':{'enabled':True}}) diff --git a/IPython/nbconvert/templates/basichtml.tpl b/IPython/nbconvert/templates/html_basic.tpl similarity index 100% rename from IPython/nbconvert/templates/basichtml.tpl rename to IPython/nbconvert/templates/html_basic.tpl diff --git a/IPython/nbconvert/templates/fullhtml.tpl b/IPython/nbconvert/templates/html_full.tpl similarity index 100% rename from IPython/nbconvert/templates/fullhtml.tpl rename to IPython/nbconvert/templates/html_full.tpl diff --git a/IPython/nbconvert/templates/reveal.tpl b/IPython/nbconvert/templates/html_slides.tpl similarity index 100% rename from IPython/nbconvert/templates/reveal.tpl rename to IPython/nbconvert/templates/html_slides.tpl diff --git a/IPython/nbconvert/templates/latex/base.tplx b/IPython/nbconvert/templates/latex/latex.tplx similarity index 100% rename from IPython/nbconvert/templates/latex/base.tplx rename to IPython/nbconvert/templates/latex/latex.tplx diff --git a/IPython/nbconvert/templates/latex/sphinx_howto.tplx b/IPython/nbconvert/templates/latex/latex_article.tplx similarity index 100% rename from IPython/nbconvert/templates/latex/sphinx_howto.tplx rename to IPython/nbconvert/templates/latex/latex_article.tplx diff --git a/IPython/nbconvert/templates/latex/sphinx_manual.tplx b/IPython/nbconvert/templates/latex/latex_book.tplx similarity index 100% rename from IPython/nbconvert/templates/latex/sphinx_manual.tplx rename to IPython/nbconvert/templates/latex/latex_book.tplx diff --git a/IPython/nbconvert/templates/latex/sphinx_base.tplx b/IPython/nbconvert/templates/latex/sphinx.tplx similarity index 100% rename from IPython/nbconvert/templates/latex/sphinx_base.tplx rename to IPython/nbconvert/templates/latex/sphinx.tplx