Marcus Ramberg > MojoMojo-1.10 > MojoMojo::Formatter::TOC



Annotate this POD


View/Report Bugs
Source   Latest Release: MojoMojo-1.11


Return true if the module is loaded.


MojoMojo::Formatter::TOC - generate table of contents


This formatter will replace {{toc}} with a table of contents, using HTML::GenToc. If you don't want an element to be included in the TOC, make it have class="notoc"



The TOC formatter expects HTML input so it needs to run after the main formatter. Since comment-type formatters (order 91) could add a heading for the comment section, the TOC formatter will run with a priority of 95.


Calls the formatter. Takes a ref to the content as well as the context object. The syntax for the TOC plugin invocation is:

  {{toc M- }}     # start from Header level M
  {{toc -N }}     # stop at Header level N
  {{toc M-N }}    # process only header levels M..N

where M is the minimum heading level to include in the TOC, and N is the maximum level (depth). For example, suppose you only have one H1 on the page so it doesn't make sense to add it to the TOC; also, assume you and don't want to include any headers smaller than H3. The {{toc}} markup to achieve that would be:

  {{toc 2-3}}

Defaults to 1-6.

SEO-friendly anchors

Anchors should be generated with SEO- (and human-) friendly names, i.e. out of the entire token text, instead of being numeric or reduced to the first word(s) of the token. In the spirit of, compare:

"Which one speaks your language more, which one will you rather click?"

The anchor names generated are compliant with XHTML1.0 Strict. Also, per the HTML 4.01 spec, anchor names should be restricted to ASCII characters and anchors that differ only in case may not appear in the same document. In particular, an anchor name may be defined only once in a document (logically, because otherwise the user agent wouldn't know which #foo to scroll to). This is currently a problem with HTML::Toc v1.11, which doesn't have support for passing the already existing anchors to the templateAnchorName sub.



MojoMojo and Module::Pluggable::Ordered.


Dan Dascalescu,


This library is free software. You can redistribute it and/or modify it under the same terms as Perl itself.

syntax highlighting: