a Table-of-Contents from HTML markup. It does so by parsing *H1...H6* tags. It can also automatically add appropriate *id* anchor attributes to header tags.
1. The hierarchy of your content is defined solely by the header (*H1*...*H6*) tags. All other tags are ignored.
2. The link titles in the Table of Contents match either the `title` attribute of the header tag, or if there is no `title`, the plaintext body of the header tag.
This library includes a [Twig](http://twig.sensiolabs.org) extension that enables you to load TOC lists and add anchors to markup from your Twig templates.
You may have content in hard-coded in your Twig Template that you want to generate a TOC for. An easy way to do this is to make sure the content is surrounded by `{% block %}...{% endblock %}`
tags, and then just pass in that block to the *toc* function.
You can choose to include only specific *h1...h6* heading levels in your TOC. To do this, pass two additional arguments to the `TocGenerator::getHtmlMenu()` method: `$topLevel` and `$depth`. For example:
```php
$tocGenerator = new TOC\TocGenerator();
// Get TOC using h2, h3, h4
$toc->getHtmlMenu($someHtmlContent, 2, 3);
// Get TOC using h1, h2
$toc->getHtmlMenu($someHtmlContent, 1, 2);
// Get TOC using h4, h5, h6
$toc->getHtmlMenu($someHtmlContent, 4, 3);
```
Most other methods in the package take this arguments as well:
```php
$tocGenerator = new TOC\TocGenerator();
$markupFixer = new TOC\MarkupFixer();
// Get KnpMenu using h1, h2, h3
$tocGenerator->getMenu($someHtmlContent, 1, 3);
// Fix markup for h3, h4 tags only
$markupFixer->fix($someHtmlContent, 3, 2);
```
Twig functions and filters accept this arguments too:
You can customize the rendering of lists that the `TocGenerator` class outputs. By default, `TocGenerator` uses the [KnpMenu ListRenderer](https://github.com/KnpLabs/KnpMenu/blob/master/src/Knp/Menu/Renderer/ListRenderer.php) class to output the HTML.
You can pass your own instance of the `ListRenderer` class to `TocGenerator::getHtmlMenu()`. Or, you can pass in your own renderer (implements [`Knp\Menu\Renderer\RendererInterface`](https://github.com/KnpLabs/KnpMenu/blob/master/src/Knp/Menu/Renderer/RendererInterface.php)).
The KnpMenu library offers more robust integration with the [Twig Templating System](http://twig.sensiolabs.org/)
than is offered by default with this library. You can take advantage of it by using the [TwigRenderer](https://github.com/KnpLabs/KnpMenu/blob/master/doc/02-Twig-Integration.markdown#using-the-twigrenderer)