IPython Documentation

Table Of Contents

Previous topic

Module: nbconvert.post_processors.serve

Next topic

Module: nbconvert.transformers.coalescestreams

This Page

Module: nbconvert.transformers.base

Module that re-groups transformer that would be applied to ipynb files before going through the templating machinery.

It exposes a convenient class to inherit from to access configurability.

1 Class

class IPython.nbconvert.transformers.base.Transformer(**kw)

Bases: IPython.nbconvert.utils.base.NbConvertBase

A configurable transformer

Inherit from this class if you wish to have configurability for your transformer.

Any configurable traitlets this class exposed will be configurable in profiles using c.SubClassName.atribute=value

you can overwrite transform_cell() to apply a transformation independently on each cell or call() if you prefer your own logic. See corresponding docstring for informations.

Disabled by default and can be enabled via the config by
‘c.YourTransformerName.enabled = True’
__init__(**kw)

Public constructor

Parameters:

config : Config

Configuration file structure

**kw : misc

Additional arguments

call(nb, resources)

Transformation to apply on each notebook.

You should return modified nb, resources. If you wish to apply your transform on each cell, you might want to overwrite transform_cell method instead.

Parameters:

nb : NotebookNode

Notebook being converted

resources : dictionary

Additional resources used in the conversion process. Allows transformers to pass variables into the Jinja engine.

transform_cell(cell, resources, index)

Overwrite if you want to apply a transformation on each cell. You should return modified cell and resource dictionary.

Parameters:

cell : NotebookNode cell

Notebook cell being processed

resources : dictionary

Additional resources used in the conversion process. Allows transformers to pass variables into the Jinja engine.

index : int

Index of the cell being processed