class RDoc::Markup::AttributeManager

Manages changes of attributes in a block of text

Constants

NULL

The NUL character

Attributes

attributes[R]

The attributes enabled for this markup object.

exclusive_bitmap[R]

A bits of exclusive maps

html_tags[R]

This maps HTML tags to the corresponding attribute char

matching_word_pairs[R]

This maps delimiters that occur around words (such as bold or tt) where the start and end delimiters and the same. This lets us optimize the regexp

protectable[R]

A \ in front of a character that would normally be processed turns off processing. We do this by turning < into <#{PROTECT}

regexp_handlings[R]

And this maps _regexp handling_ sequences to a name. A regexp handling sequence is something like a WikiWord

word_pair_map[R]

And this is used when the delimiters aren’t the same. In this case the hash maps a pattern to the attribute character

Public Class Methods

new() click to toggle source

Creates a new attribute manager that understands bold, emphasized and teletype text.

# File rdoc/markup/attribute_manager.rb, line 80
def initialize
  @html_tags = {}
  @matching_word_pairs = {}
  @protectable = %w[<]
  @regexp_handlings = []
  @word_pair_map = {}
  @exclusive_bitmap = 0
  @attributes = RDoc::Markup::Attributes.new

  add_word_pair "*", "*", :BOLD, true
  add_word_pair "_", "_", :EM, true
  add_word_pair "+", "+", :TT, true

  add_html "em", :EM, true
  add_html "i",  :EM, true
  add_html "b",  :BOLD, true
  add_html "tt",   :TT, true
  add_html "code", :TT, true
end

Public Instance Methods

attribute(turn_on, turn_off) click to toggle source

Return an attribute object with the given turn_on and turn_off bits set

# File rdoc/markup/attribute_manager.rb, line 103
def attribute(turn_on, turn_off)
  RDoc::Markup::AttrChanger.new turn_on, turn_off
end
change_attribute(current, new) click to toggle source

Changes the current attribute from current to new

# File rdoc/markup/attribute_manager.rb, line 110
def change_attribute current, new
  diff = current ^ new
  attribute(new & diff, current & diff)
end
changed_attribute_by_name(current_set, new_set) click to toggle source

Used by the tests to change attributes by name from current_set to new_set

# File rdoc/markup/attribute_manager.rb, line 119
def changed_attribute_by_name current_set, new_set
  current = new = 0
  current_set.each do |name|
    current |= @attributes.bitmap_for(name)
  end

  new_set.each do |name|
    new |= @attributes.bitmap_for(name)
  end

  change_attribute(current, new)
end
copy_string(start_pos, end_pos) click to toggle source

Copies start_pos to end_pos from the current string

# File rdoc/markup/attribute_manager.rb, line 135
def copy_string(start_pos, end_pos)
  res = @str[start_pos...end_pos]
  res.gsub!(/\000/, '')
  res
end