Page filter that supports easy construction of a Table Of Contents from your layout. This filter searches for tags matching the specified regular expression(s) (H tags by default), and stores them to be used for TOC generation in the layout. HTML Named-anchors are created based on the headings found.
Additional attributes for the A tags can be passed via the attrs parameter.
Methods
Classes and Modules
Class Rote::Filters::TOC::HeadingAttributes
| [R] | headings |
Array of heading links with the heading title as the link text. Suitable
for joining and outputting:
<%= links.join(" - ") %>
Note that this isn‘t populated until after the filter is run. The @links array will usually be used in layout. |
Public Class methods
[ show source ]
# File lib/rote/filters/toc.rb, line 47
47: def initialize(tags_re = /h\d+/, attrs = {})
48: @tags_re = tags_re
49: @attrs = attrs
50: @headings = []
51: end
Public Instance methods
[ show source ]
# File lib/rote/filters/toc.rb, line 65
65: def filter(text, page)
66: # find headings *and insert named anchors*
67: text.gsub(%r[<(#{@tags_re})>(.*?)</\1>]) do
68: headings << (h = Heading[$1,$2])
69: %Q[<a name='#{h.anchor}'></a>#{$&}]
70: end
71: end