Class: Banzai::Filter::TableOfContentsTagFilter

Inherits:
HTML::Pipeline::Filter
  • Object
show all
Defined in:
lib/banzai/filter/table_of_contents_tag_filter.rb

Overview

Using `[[TOC]]`, inserts a Table of Contents list. This syntax is based on the Gollum syntax. This way we have some consistency between with wiki and normal markdown. If there ever emerges a markdown standard, we can implement that here.

The support for this has been removed from GollumTagsFilter

Based on Banzai::Filter::GollumTagsFilter

Constant Summary collapse

TEXT_QUERY =
%q(descendant-or-self::text()[ancestor::p and contains(., 'TOC')])

Instance Method Summary collapse

Instance Method Details

#callObject


17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/banzai/filter/table_of_contents_tag_filter.rb', line 17

def call
  return doc if context[:no_header_anchors]

  doc.xpath(TEXT_QUERY).each do |node|
    # A Gollum ToC tag is `[[_TOC_]]`, but due to MarkdownFilter running
    # before this one, it will be converted into `[[<em>TOC</em>]]`, so it
    # needs special-case handling
    process_toc_tag(node) if toc_tag?(node)
  end

  doc
end