CouscousPHP/Couscous — pull request #69 by mnapoli (2014-12-21 06:43:17+00:00)
Title: Table of contents extracted from Markdown documents

A new step extracts a table of contents from Markdown documents (list of headers) and makes it available as file metadata. Uses the latest changes in [commonmark](https://github.com/thephpleague/commonmark) (we end up with 2 Markdown parser because this one doesn't support Markdown Extra).

With this new step, we now have this metadata available in Twig layouts:

```twig

{{ tableOfContents.title }}

Table of contents:

{% for header in tableOfContents.getHeaders(2) %}

{{ header }}

{% endfor %}

```

API of `tableOfContents`:

- `title`: the title of the current document (i.e. header of level 1)
- `getHeaders($level)`: returns the list of headers (`string[]`)

TODO:

- [ ] Documentation
- [ ] Require a stable dependency in `composer.json` (i.e. wait for a new release of [commonmark](https://github.com/thephpleague/commonmark))
- [ ] Should the metadata key be `document` instead of `tableOfContents`?
- [ ] The headers list should be indexed by the header `id` (so that we can link to it). The problem is that I'm not sure CommonMark doesn't support Markdown Extra (which allows to define headers ID), and what if headers IDs are not defined? Related to #39