summaryrefslogtreecommitdiff
path: root/lib/rdoc/markup/attribute_manager.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rdoc/markup/attribute_manager.rb')
-rw-r--r--lib/rdoc/markup/attribute_manager.rb33
1 files changed, 26 insertions, 7 deletions
diff --git a/lib/rdoc/markup/attribute_manager.rb b/lib/rdoc/markup/attribute_manager.rb
index e86e7f6812..2ee243ab0b 100644
--- a/lib/rdoc/markup/attribute_manager.rb
+++ b/lib/rdoc/markup/attribute_manager.rb
@@ -15,9 +15,12 @@ class RDoc::Markup::AttributeManager
# optimistic
#++
- A_PROTECT = 004 # :nodoc:
+ A_PROTECT = 004 # :nodoc:
- PROTECT_ATTR = A_PROTECT.chr # :nodoc:
+ ##
+ # Special mask character to prevent inline markup handling
+
+ PROTECT_ATTR = A_PROTECT.chr # :nodoc:
##
# This maps delimiters that occur around words (such as *bold* or +tt+)
@@ -56,7 +59,7 @@ class RDoc::Markup::AttributeManager
def initialize
@html_tags = {}
@matching_word_pairs = {}
- @protectable = %w[<\\]
+ @protectable = %w[<]
@special = {}
@word_pair_map = {}
@@ -79,12 +82,19 @@ class RDoc::Markup::AttributeManager
RDoc::Markup::AttrChanger.new turn_on, turn_off
end
- def change_attribute(current, new)
+ ##
+ # Changes the current attribute from +current+ to +new+
+
+ def change_attribute current, new
diff = current ^ new
attribute(new & diff, current & diff)
end
- def changed_attribute_by_name(current_set, new_set)
+ ##
+ # Used by the tests to change attributes by name from +current_set+ to
+ # +new_set+
+
+ def changed_attribute_by_name current_set, new_set
current = new = 0
current_set.each do |name|
current |= RDoc::Markup::Attribute.bitmap_for(name)
@@ -97,6 +107,9 @@ class RDoc::Markup::AttributeManager
change_attribute(current, new)
end
+ ##
+ # Copies +start_pos+ to +end_pos+ from the current string
+
def copy_string(start_pos, end_pos)
res = @str[start_pos...end_pos]
res.gsub!(/\000/, '')
@@ -112,7 +125,7 @@ class RDoc::Markup::AttributeManager
# first do matching ones
tags = @matching_word_pairs.keys.join("")
- re = /(^|[^\w#{NULL}])([#{tags}])([#:\\]?[\w.\/-]+?\S?)\2(\W|$)/
+ re = /(^|\W)([#{tags}])([#:\\]?[\w.\/-]+?\S?)\2(\W|$)/
1 while str.gsub!(re) do
attr = @matching_word_pairs[$2]
@@ -164,6 +177,9 @@ class RDoc::Markup::AttributeManager
# Escapes special sequences of text to prevent conversion to RDoc
def mask_protected_sequences
+ # protect __send__, __FILE__, etc.
+ @str.gsub!(/__([a-z]+)__/i,
+ "_#{PROTECT_ATTR}_#{PROTECT_ATTR}\\1_#{PROTECT_ATTR}_#{PROTECT_ATTR}")
@str.gsub!(/\\([#{Regexp.escape @protectable.join('')}])/,
"\\1#{PROTECT_ATTR}")
end
@@ -228,8 +244,8 @@ class RDoc::Markup::AttributeManager
@attrs = RDoc::Markup::AttrSpan.new @str.length
- convert_html @str, @attrs
convert_attrs @str, @attrs
+ convert_html @str, @attrs
convert_specials @str, @attrs
unmask_protected_sequences
@@ -262,6 +278,9 @@ class RDoc::Markup::AttributeManager
end
end
+ ##
+ # Splits the string into chunks by attribute change
+
def split_into_flow
res = []
current_attr = 0