Class: Kramdown::Converter::Toc

### Home Classes Methods

### In Files

- lib/kramdown/converter/toc.rb

### Parent

Kramdown::Converter::Base

### Methods

- ::new
- #convert

### Class/Module Index

Quicksearch

- Kramdown
- Kramdown::Converter
- Kramdown::Converter::Base
- Kramdown::Converter::Html
- Kramdown::Converter::Kramdown
- Kramdown::Converter::Latex
- Kramdown::Converter::MathEngine
- Kramdown::Converter::MathEngine::Itex2MML
- Kramdown::Converter::MathEngine::Mathjax
- Kramdown::Converter::MathEngine::Ritex
- Kramdown::Converter::RemoveHtmlTags
- Kramdown::Converter::SyntaxHighlighter
- Kramdown::Converter::SyntaxHighlighter::Coderay
- Kramdown::Converter::SyntaxHighlighter::Rouge
- Kramdown::Converter::Toc
- Kramdown::Document
- Kramdown::Element
- Kramdown::Error
- Kramdown::Options
- Kramdown::Options::Boolean
- Kramdown::Parser
- Kramdown::Parser::Base
- Kramdown::Parser::GFM
- Kramdown::Parser::Html
- Kramdown::Parser::Html::Constants
- Kramdown::Parser::Html::ElementConverter
- Kramdown::Parser::Html::Parser
- Kramdown::Parser::Kramdown
- Kramdown::Parser::Markdown
- Kramdown::Utils
- Kramdown::Utils::Configurable
- Kramdown::Utils::Entities
- Kramdown::Utils::Entities::Entity
- Kramdown::Utils::Html
- Kramdown::Utils::OrderedHash
- Kramdown::Utils::StringScanner
- Kramdown::Utils::Unidecoder

No matching classes.

# Kramdown::Converter::Toc

Converts a Kramdown::Document to an element tree that represents the table of contents.

The returned tree consists of Element objects of type :toc where the root element is just used as container object. Each :toc element contains as value the wrapped :header element and under the attribute key :id the header ID that should be used (note that this ID may not exist in the wrapped element).

Since the TOC tree consists of special :toc elements, one cannot directly feed this tree to other converters!

### Public Class Methods

new(root, options) click to toggle source

    # File lib/kramdown/converter/toc.rb, line 26
    def initialize(root, options)
      super
      @toc = Element.new(:toc)
      @stack = []
      @options[:template] = ''
    end

### Public Instance Methods

convert(el) click to toggle source

    # File lib/kramdown/converter/toc.rb, line 33
    def convert(el)
      if el.type == :header && in_toc?(el)
        attr = el.attr.dup
        attr['id'] = generate_id(el.options[:raw_text]) if @options[:auto_ids] && !attr['id']
        add_to_toc(el, attr['id']) if attr['id']
      else
        el.children.each {|child| convert(child)}
      end
      @toc
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.