---
title: frontmatter
description: A YAML and formatted-markdown frontmatter processor
order: 7
---
<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

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

### FrontmatterProc

```python
def FrontmatterProc(
    nb
):
```

*A YAML and formatted-markdown frontmatter processor*

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

### extract\_nb\_frontmatter

```python
def extract_nb_frontmatter(
    nb, # `Notebook` object to read metadata from
    strip:bool=False, # Clear consumed frontmatter cells' `source` in place?
)->dict:
```

*Extract combined YAML and Markdown frontmatter from `nb`, optionally clearing consumed cells.*

YAML frontmatter can be added to notebooks in one of these ways:

1. By adding a raw notebook cell with `---` as the first and last lines, and YAML between them, or
2. A markdown cell that is entirely a literal `---` block (same as a raw cell), or
3. A specially formatted markdown cell. The first line should be start with a single `#` (creating an H1 heading), and becomes the title. Then, optionally, a line beginning with `>` (creating a quote block), which becomes the description. Finally, zero or more lines beginning with ` -  ` (creating a list), each of which contains YAML. (If you already have "title" defined in frontmatter in a raw cell, then markdown cells will be ignored.)

For instance, our test notebook contains the following markdown cell:

```
# a title
> A description
- key1: value1
- key2: value2
- categories: [c1, c2]
```

It also contains the following raw cell:

```
---
execute:
  echo: false
---
```

When we process with [`FrontmatterProc`](frontmatter.md#frontmatterproc), these are stripped from the cells and combined into the notebook's `frontmatter_` dict:

```python
nbp = NBProcessor(_test_file, procs=FrontmatterProc)
nbp.process()
```

```output
---
categories:
- c1
- c2
description: A description
execute:
  echo: false
key1: value1
key2: value2
output-file: docs_test.html
title: a title

---
```

```python
d = nbp.nb.frontmatter_
d
```

```output
{'execute': {'echo': False},
 'title': 'a title',
 'description': 'A description',
 'key1': 'value1',
 'key2': 'value2',
 'categories': ['c1', 'c2'],
 'output-file': 'docs_test.html'}
```
