---
title: processors
description: Some processors for NBProcessor
order: 8
---
<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

On this page we'll be using this private helper to process a notebook and return the results, to simplify testing:

```python
def _run_procs(procs=None, return_nb=False, path=_test_file):
    nbp = NBProcessor(path, procs)
    nbp.process()
    if return_nb: return nbp.nb
    return '\n'.join([str(cell) for cell in nbp.nb.cells])
```

[source](https://github.com/AnswerDotAI/fastship/blob/main/fastship/processors.py#L30)

### populate\_language

```python
def populate_language(
    nb
):
```

*Set cell language based on NB metadata and magics*

[source](https://github.com/AnswerDotAI/fastship/blob/main/fastship/processors.py#L40)

### insert\_warning

```python
def insert_warning(
    nb
):
```

*Insert Autogenerated Warning Into Notebook after the first cell.*

This preprocessor inserts a warning in the markdown destination that the file is autogenerated.  This warning is inserted in the second cell so we do not interfere with front matter.

```python
res = _run_procs(insert_warning)
assert "<!-- WARNING: THIS FILE WAS AUTOGENERATED!" in res
```

```python
L('foo', None, 'a').filter(lambda x:x == 1)
_tstre = re.compile('a')
```

[source](https://github.com/AnswerDotAI/fastship/blob/main/fastship/processors.py#L70)

### add\_show\_docs

```python
def add_show_docs(
    nb
):
```

*Add show\_doc cells after exported cells, unless they are already documented*

[source](https://github.com/AnswerDotAI/fastship/blob/main/fastship/processors.py#L63)

### cell\_lang

```python
def cell_lang(
    cell
):
```

```python
res = _run_procs([populate_language, add_show_docs])
assert "show_doc(some_func)'" in res
assert "show_doc(and_another)'" in res
assert "show_doc(another_func)'" not in res
```

[source](https://github.com/AnswerDotAI/fastship/blob/main/fastship/processors.py#L87)

### mv\_exports

```python
def mv_exports(
    nb
):
```

*Move `exports` cells to after the [`show_doc`](showdoc.md#show_doc)*

[source](https://github.com/AnswerDotAI/fastship/blob/main/fastship/processors.py#L109)

### add\_links

```python
def add_links(
    cell, nl=None
):
```

*Add links to markdown cells*

```python
res = _run_procs(add_links)
assert "[`numpy.array`](https://numpy.org/doc/stable/reference/generated/numpy.array.html#numpy.array)" in res
assert "[`ModuleMaker`](https://ship.fast.ai/api/maker.html#modulemaker) but not a link to `foobar`." in res
assert "A link in a docstring: [`ModuleMaker`](https://ship.fast.ai/api/maker.html#modulemaker)." in res
assert "And not a link to <code>dict2nb</code>." in res

# nbformat also allows mime data as a *list* of lines -- `add_links` must handle both forms
c = AttrDict(cell_type='code', outputs=[AttrDict(data=AttrDict({'text/markdown': ['A link to\n', '`ModuleMaker`.\n']}))])
add_links(c)
assert 'maker.html#modulemaker' in c.outputs[0].data['text/markdown']
```

[source](https://github.com/AnswerDotAI/fastship/blob/main/fastship/processors.py#L119)

### add\_fold

```python
def add_fold(
    cell
):
```

*Add `code-fold` to `exports` cells*

```python
res = _run_procs(add_fold)
assert "#| code-fold: show" in res
```

Gets rid of colors that are streamed from standard out, which can interfere with static site generators:

[source](https://github.com/AnswerDotAI/fastship/blob/main/fastship/processors.py#L127)

### strip\_ansi

```python
def strip_ansi(
    cell
):
```

*Strip Ansi Characters.*

```python
res = _run_procs(strip_ansi)
assert not _re_ansi_escape.findall(res)
assert r"'hello\n'" in res  # text survives intact, not exploded into chars
```

[source](https://github.com/AnswerDotAI/fastship/blob/main/fastship/processors.py#L133)

### strip\_hidden\_metadata

```python
def strip_hidden_metadata(
    cell
):
```

*Strips "hidden" metadata property from code cells so it doesn't interfere with docs rendering*

[source](https://github.com/AnswerDotAI/fastship/blob/main/fastship/processors.py#L138)

### hide\_

```python
def hide_(
    cell
):
```

*Hide cell from output*

```python
res = _run_procs(hide_)
assert 'you will not be able to see this cell at all either' not in res
```

[source](https://github.com/AnswerDotAI/fastship/blob/main/fastship/processors.py#L145)

### clean\_magics

```python
def clean_magics(
    nb
):
```

*Remove housekeeping magics: those named in the `strip_magics` config (space-separated, default `_def_strip_magics`)*

By default only housekeeping line magics (`%load_ext`, `%autoreload`, `%reload_ext`, `%matplotlib`, `%config`) are removed from docs; magics that are part of the content, such as `%%bash` or a custom cell magic, stay. Set `strip_magics` in your fastship config to change the list (an empty value keeps every magic).

```python
res = _run_procs(clean_magics)
assert '%%bash' in res and '%%time' in res  # cell magics are content, and are kept

c = dict2obj(dict(cell_type='code', source='%load_ext autoreload\n%autoreload 2\nx = 1\n%matplotlib inline'))
p = clean_magics(None); p.begin(); p.cell(c)
test_eq(c.source, 'x = 1')
```

[source](https://github.com/AnswerDotAI/fastship/blob/main/fastship/processors.py#L158)

### rm\_header\_dash

```python
def rm_header_dash(
    cell
):
```

*Remove headings that end with a dash -*

```python
res = _run_procs(rm_header_dash)
assert 'some words' in res
assert 'A heading to Hide' not in res
assert 'Yet another heading to hide' not in res
```

[source](https://github.com/AnswerDotAI/fastship/blob/main/fastship/processors.py#L167)

### rm\_export

```python
def rm_export(
    cell
):
```

*Remove code cells that are exported or hidden*

```python
res = _run_procs(rm_export)
assert 'dontshow' not in res
```

[source](https://github.com/AnswerDotAI/fastship/blob/main/fastship/processors.py#L179)

### clean\_show\_doc

```python
def clean_show_doc(
    cell
):
```

*Remove ShowDoc input cells*

[source](https://github.com/AnswerDotAI/fastship/blob/main/fastship/processors.py#L208)

### exec\_show\_docs

```python
def exec_show_docs(
    nb
):
```

*Execute cells needed for `show_docs` output, including exported cells and imports, or every cell under `exec_all`*

[`exec_show_docs`](processors.md#exec_show_docs) runs the cells the docs need: exports, imports, and [`show_doc`](showdoc.md#show_doc) calls. With `exec_all` set it runs every cell instead. A notebook whose frontmatter sets `skip_showdoc: true` is not executed at all during docs rendering, whatever else is set, and its stored outputs are used as-is.

```python
res = _run_procs([add_show_docs, exec_show_docs])
assert res
```

`exec_all: true` in a notebook's frontmatter, or `exec-all = true` in `ship.toml` / `[tool.fastship]` for a whole project, runs every code cell the test runner would run, so a notebook with no exports or [`show_doc`](showdoc.md#show_doc) calls is executed too. Cells that `ship-test` skips, through `eval: false` or a `tst_flags` flag such as `notest`, are skipped here as well:

```python
cells = [mk_cell('---\nexec_all: true\n---', 'raw'), mk_cell('%pwd\nx = 1'), mk_cell('x + 1'),
    mk_cell('#| notest\nraise Exception("skipped by tst_flags")'), mk_cell('#| eval: false\nraise Exception("skipped by eval")')]
nb = dict2nb(dict(cells=cells, metadata={}, nbformat=4, nbformat_minor=5))
nb.path_ = 'exec_all.ipynb'
NBProcessor(nb=nb, procs=[FrontmatterProc, add_show_docs, exec_show_docs]).process()
test_eq(nb.cells[1].outputs[0].data['text/plain'], ['2'])
```

When a cell fails, the error names the exception as well as the cell. The last lines of a docs build log then state the cause.

```python
nb = dict2nb(dict(cells=[mk_cell('#| export\ndef f(): pass'), mk_cell('import not_a_real_module')], metadata={}, nbformat=4, nbformat_minor=5))
with ExceptionExpected(regex='ModuleNotFoundError'): NBProcessor(nb=nb, procs=[add_show_docs, exec_show_docs]).process()
```

[source](https://github.com/AnswerDotAI/fastship/blob/main/fastship/processors.py#L237)

### FilterDefaults

```python
def FilterDefaults():
```

*Override [`FilterDefaults`](processors.md#filterdefaults) to change which notebook processors are used*
