NAME
MojoMojo::Formatter::TOC - replace =toc with table of contents
DESCRIPTION
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"
METHODS
- format_content_order
-
The TOC formatter expects HTML input so it needs to run after the main formatter. Since comment-type formatters could add a heading for the comment section, the TOC formatter will run with a priority of 95
- format_content
-
Calls the formatter. Takes a ref to the content as well as the context object. The format 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 http://seo2.0.onreact.com/top-10-fatal-url-design-mistakes, compare:
http://beachfashion.com/photos/Pamela_Anderson#In_red_swimsuit_in_Baywatch vs. http://beachfashion.com/photos/Pamela_Anderson#in
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, anchors that differ only in case may not appear in the same document and anchor names should be restricted to ASCII characters.
The sub below overrides make_anchor_name in HTML::GenToc to create friendly anchor names.
SEE ALSO
MojoMojo and Module::Pluggable::Ordered.
AUTHORS
Dan Dascalescu <ddascalescu at g-mail>
LICENSE
This module is licensed under the same terms as Perl itself.