diff options
Diffstat (limited to 'lib/rdoc/markup/attribute_manager.rb')
-rw-r--r-- | lib/rdoc/markup/attribute_manager.rb | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/lib/rdoc/markup/attribute_manager.rb b/lib/rdoc/markup/attribute_manager.rb index d2402f1b1d..71d5e2b2cc 100644 --- a/lib/rdoc/markup/attribute_manager.rb +++ b/lib/rdoc/markup/attribute_manager.rb @@ -23,6 +23,11 @@ class RDoc::Markup::AttributeManager PROTECT_ATTR = A_PROTECT.chr # :nodoc: ## + # The attributes enabled for this markup object. + + attr_reader :attributes + + ## # 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 @@ -60,8 +65,9 @@ class RDoc::Markup::AttributeManager @html_tags = {} @matching_word_pairs = {} @protectable = %w[<] - @special = {} + @special = [] @word_pair_map = {} + @attributes = RDoc::Markup::Attributes.new add_word_pair "*", "*", :BOLD add_word_pair "_", "_", :EM @@ -96,11 +102,11 @@ class RDoc::Markup::AttributeManager def changed_attribute_by_name current_set, new_set current = new = 0 current_set.each do |name| - current |= RDoc::Markup::Attribute.bitmap_for(name) + current |= @attributes.bitmap_for(name) end new_set.each do |name| - new |= RDoc::Markup::Attribute.bitmap_for(name) + new |= @attributes.bitmap_for(name) end change_attribute(current, new) @@ -161,12 +167,15 @@ class RDoc::Markup::AttributeManager ## # Converts special sequences to RDoc attributes - def convert_specials(str, attrs) + def convert_specials str, attrs unless @special.empty? - @special.each do |regexp, attr| + @special.each do |regexp, attribute| str.scan(regexp) do - attrs.set_attrs($`.length, $&.length, - attr | RDoc::Markup::Attribute::SPECIAL) + capture = $~.size == 1 ? 0 : 1 + + s, e = $~.offset capture + + attrs.set_attrs s, e - s, attribute | @attributes.special end end end @@ -200,7 +209,7 @@ class RDoc::Markup::AttributeManager raise ArgumentError, "Word flags may not start with '<'" if start[0,1] == '<' - bitmap = RDoc::Markup::Attribute.bitmap_for name + bitmap = @attributes.bitmap_for name if start == stop then @matching_word_pairs[start] = bitmap @@ -220,7 +229,7 @@ class RDoc::Markup::AttributeManager # am.add_html 'em', :EM def add_html(tag, name) - @html_tags[tag.downcase] = RDoc::Markup::Attribute.bitmap_for name + @html_tags[tag.downcase] = @attributes.bitmap_for name end ## @@ -229,14 +238,14 @@ class RDoc::Markup::AttributeManager # # @am.add_special(/((https?:)\S+\w)/, :HYPERLINK) - def add_special(pattern, name) - @special[pattern] = RDoc::Markup::Attribute.bitmap_for name + def add_special pattern, name + @special << [pattern, @attributes.bitmap_for(name)] end ## # Processes +str+ converting attributes, HTML and specials - def flow(str) + def flow str @str = str mask_protected_sequences @@ -303,9 +312,9 @@ class RDoc::Markup::AttributeManager res << change_attribute(current_attr, new_attr) current_attr = new_attr - if (current_attr & RDoc::Markup::Attribute::SPECIAL) != 0 then + if (current_attr & @attributes.special) != 0 then i += 1 while - i < str_len and (@attrs[i] & RDoc::Markup::Attribute::SPECIAL) != 0 + i < str_len and (@attrs[i] & @attributes.special) != 0 res << RDoc::Markup::Special.new(current_attr, copy_string(start_pos, i)) |