class RDoc::Markup::ToTtOnly

Extracts sections of text enclosed in plus, tt or code. Used to discover undocumented parameters.

Attributes

Stack of list types

Output accumulator

Public Instance Methods

Adds tts from block_quote to the output

# File lib/rdoc/markup/to_tt_only.rb, line 23
def accept_block_quote(block_quote)
  tt_sections block_quote.text
end

Pops the list type for list from list_type

# File lib/rdoc/markup/to_tt_only.rb, line 30
def accept_list_end(list)
  @list_type.pop
end

Prepares the visitor for consuming list_item

# File lib/rdoc/markup/to_tt_only.rb, line 44
def accept_list_item_start(list_item)
  case @list_type.last
  when :NOTE, :LABEL
    Array(list_item.label).map do |label|
      tt_sections label
    end.flatten
  end
end

Pushes the list type for list onto list_type

# File lib/rdoc/markup/to_tt_only.rb, line 37
def accept_list_start(list)
  @list_type << list.type
end

Adds paragraph to the output

# File lib/rdoc/markup/to_tt_only.rb, line 56
def accept_paragraph(paragraph)
  tt_sections(paragraph.text)
end

Does nothing to markup_item because it doesn’t have any user-built content

# File lib/rdoc/markup/to_tt_only.rb, line 64
def do_nothing(markup_item)
end

Returns an Array of items that were wrapped in plus, tt or code.

# File lib/rdoc/markup/to_tt_only.rb, line 96
def end_accepting
  @res.compact
end

Prepares the visitor for gathering tt sections

# File lib/rdoc/markup/to_tt_only.rb, line 103
def start_accepting
  @res = []

  @list_type = []
end

Extracts tt sections from text

# File lib/rdoc/markup/to_tt_only.rb, line 77
def tt_sections(text)
  parsed = Markup::InlineParser.new(text).parse
  traverse = -> node {
    next if String === node
    if node[:type] == :TT
      res << nil
      res << node[:children][0] || ''
      res << nil
    else
      node[:children].each(&traverse)
    end
  }
  parsed.each(&traverse)
  res
end