diff --git a/nbconvert/api/exporter.py b/nbconvert/api/exporter.py index 3e338e0..49d02a7 100755 --- a/nbconvert/api/exporter.py +++ b/nbconvert/api/exporter.py @@ -23,6 +23,7 @@ from __future__ import print_function, absolute_import # Stdlib imports import io import os +import inspect # IPython imports from IPython.config.configurable import Configurable @@ -151,20 +152,26 @@ class Exporter(Configurable): def register_transformer(self, transformer): - if isinstance(transformer, MetaHasTraits): + if inspect.isfunction(transformer): + self.preprocessors.append(transformer) + return transformer + elif isinstance(transformer, MetaHasTraits): transformer_instance = transformer(config=self.config) self.preprocessors.append(transformer_instance) return transformer_instance else: - self.preprocessors.append(transformer) - return transformer + transformer_instance = transformer() + self.preprocessors.append(transformer_instance) + return transformer_instance def register_filter(self, name, filter): - if isinstance(filter, MetaHasTraits): + if inspect.isfunction(filter): + self.environment.filters[name] = filter + elif isinstance(filter, MetaHasTraits): self.environment.filters[name] = filter(config=self.config) else: - self.environment.filters[name] = filter + self.environment.filters[name] = filter() return self.environment.filters[name] diff --git a/nbconvert/filters/datatypefilter.py b/nbconvert/filters/datatypefilter.py index c384ef6..7025722 100755 --- a/nbconvert/filters/datatypefilter.py +++ b/nbconvert/filters/datatypefilter.py @@ -19,16 +19,7 @@ GlobalConfigurable.display_data_priority class DataTypeFilter(object): """ Returns the preferred display format """ - display_data_priority = None - - def __init__(self, display_data_priority): - - #Make sure that the display data priority variably is not None. - if display_data_priority is None: - raise TypeError - else: - self.display_data_priority = display_data_priority - + display_data_priority = ['html', 'pdf', 'svg', 'latex', 'png', 'jpg', 'jpeg' , 'text'] def __call__(self, output): """ Return the first available format in the priority """