gitlab-rdoc 6.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (196) hide show
  1. checksums.yaml +7 -0
  2. data/CONTRIBUTING.rdoc +220 -0
  3. data/CVE-2013-0256.rdoc +49 -0
  4. data/ExampleMarkdown.md +37 -0
  5. data/ExampleRDoc.rdoc +208 -0
  6. data/Gemfile +12 -0
  7. data/History.rdoc +1666 -0
  8. data/LEGAL.rdoc +50 -0
  9. data/LICENSE.rdoc +57 -0
  10. data/README.rdoc +133 -0
  11. data/RI.rdoc +57 -0
  12. data/Rakefile +101 -0
  13. data/TODO.rdoc +59 -0
  14. data/bin/console +7 -0
  15. data/bin/setup +6 -0
  16. data/exe/rdoc +44 -0
  17. data/exe/ri +12 -0
  18. data/lib/rdoc/alias.rb +112 -0
  19. data/lib/rdoc/anon_class.rb +11 -0
  20. data/lib/rdoc/any_method.rb +361 -0
  21. data/lib/rdoc/attr.rb +176 -0
  22. data/lib/rdoc/class_module.rb +802 -0
  23. data/lib/rdoc/code_object.rb +421 -0
  24. data/lib/rdoc/code_objects.rb +6 -0
  25. data/lib/rdoc/comment.rb +250 -0
  26. data/lib/rdoc/constant.rb +187 -0
  27. data/lib/rdoc/context/section.rb +232 -0
  28. data/lib/rdoc/context.rb +1266 -0
  29. data/lib/rdoc/cross_reference.rb +202 -0
  30. data/lib/rdoc/encoding.rb +136 -0
  31. data/lib/rdoc/erb_partial.rb +19 -0
  32. data/lib/rdoc/erbio.rb +42 -0
  33. data/lib/rdoc/extend.rb +10 -0
  34. data/lib/rdoc/generator/darkfish.rb +790 -0
  35. data/lib/rdoc/generator/json_index.rb +300 -0
  36. data/lib/rdoc/generator/markup.rb +160 -0
  37. data/lib/rdoc/generator/pot/message_extractor.rb +68 -0
  38. data/lib/rdoc/generator/pot/po.rb +84 -0
  39. data/lib/rdoc/generator/pot/po_entry.rb +141 -0
  40. data/lib/rdoc/generator/pot.rb +98 -0
  41. data/lib/rdoc/generator/ri.rb +31 -0
  42. data/lib/rdoc/generator/template/darkfish/.document +0 -0
  43. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +5 -0
  44. data/lib/rdoc/generator/template/darkfish/_head.rhtml +22 -0
  45. data/lib/rdoc/generator/template/darkfish/_sidebar_VCS_info.rhtml +19 -0
  46. data/lib/rdoc/generator/template/darkfish/_sidebar_classes.rhtml +9 -0
  47. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +15 -0
  48. data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +9 -0
  49. data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +15 -0
  50. data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +15 -0
  51. data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +12 -0
  52. data/lib/rdoc/generator/template/darkfish/_sidebar_navigation.rhtml +11 -0
  53. data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +12 -0
  54. data/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml +11 -0
  55. data/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml +14 -0
  56. data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +11 -0
  57. data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +18 -0
  58. data/lib/rdoc/generator/template/darkfish/class.rhtml +172 -0
  59. data/lib/rdoc/generator/template/darkfish/css/fonts.css +167 -0
  60. data/lib/rdoc/generator/template/darkfish/css/rdoc.css +639 -0
  61. data/lib/rdoc/generator/template/darkfish/fonts/Lato-Light.ttf +0 -0
  62. data/lib/rdoc/generator/template/darkfish/fonts/Lato-LightItalic.ttf +0 -0
  63. data/lib/rdoc/generator/template/darkfish/fonts/Lato-Regular.ttf +0 -0
  64. data/lib/rdoc/generator/template/darkfish/fonts/Lato-RegularItalic.ttf +0 -0
  65. data/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Bold.ttf +0 -0
  66. data/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Regular.ttf +0 -0
  67. data/lib/rdoc/generator/template/darkfish/images/add.png +0 -0
  68. data/lib/rdoc/generator/template/darkfish/images/arrow_up.png +0 -0
  69. data/lib/rdoc/generator/template/darkfish/images/brick.png +0 -0
  70. data/lib/rdoc/generator/template/darkfish/images/brick_link.png +0 -0
  71. data/lib/rdoc/generator/template/darkfish/images/bug.png +0 -0
  72. data/lib/rdoc/generator/template/darkfish/images/bullet_black.png +0 -0
  73. data/lib/rdoc/generator/template/darkfish/images/bullet_toggle_minus.png +0 -0
  74. data/lib/rdoc/generator/template/darkfish/images/bullet_toggle_plus.png +0 -0
  75. data/lib/rdoc/generator/template/darkfish/images/date.png +0 -0
  76. data/lib/rdoc/generator/template/darkfish/images/delete.png +0 -0
  77. data/lib/rdoc/generator/template/darkfish/images/find.png +0 -0
  78. data/lib/rdoc/generator/template/darkfish/images/loadingAnimation.gif +0 -0
  79. data/lib/rdoc/generator/template/darkfish/images/macFFBgHack.png +0 -0
  80. data/lib/rdoc/generator/template/darkfish/images/package.png +0 -0
  81. data/lib/rdoc/generator/template/darkfish/images/page_green.png +0 -0
  82. data/lib/rdoc/generator/template/darkfish/images/page_white_text.png +0 -0
  83. data/lib/rdoc/generator/template/darkfish/images/page_white_width.png +0 -0
  84. data/lib/rdoc/generator/template/darkfish/images/plugin.png +0 -0
  85. data/lib/rdoc/generator/template/darkfish/images/ruby.png +0 -0
  86. data/lib/rdoc/generator/template/darkfish/images/tag_blue.png +0 -0
  87. data/lib/rdoc/generator/template/darkfish/images/tag_green.png +0 -0
  88. data/lib/rdoc/generator/template/darkfish/images/transparent.png +0 -0
  89. data/lib/rdoc/generator/template/darkfish/images/wrench.png +0 -0
  90. data/lib/rdoc/generator/template/darkfish/images/wrench_orange.png +0 -0
  91. data/lib/rdoc/generator/template/darkfish/images/zoom.png +0 -0
  92. data/lib/rdoc/generator/template/darkfish/index.rhtml +22 -0
  93. data/lib/rdoc/generator/template/darkfish/js/darkfish.js +84 -0
  94. data/lib/rdoc/generator/template/darkfish/js/search.js +110 -0
  95. data/lib/rdoc/generator/template/darkfish/page.rhtml +18 -0
  96. data/lib/rdoc/generator/template/darkfish/servlet_not_found.rhtml +18 -0
  97. data/lib/rdoc/generator/template/darkfish/servlet_root.rhtml +62 -0
  98. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +58 -0
  99. data/lib/rdoc/generator/template/json_index/.document +1 -0
  100. data/lib/rdoc/generator/template/json_index/js/navigation.js +105 -0
  101. data/lib/rdoc/generator/template/json_index/js/searcher.js +229 -0
  102. data/lib/rdoc/generator.rb +51 -0
  103. data/lib/rdoc/ghost_method.rb +7 -0
  104. data/lib/rdoc/i18n/locale.rb +102 -0
  105. data/lib/rdoc/i18n/text.rb +126 -0
  106. data/lib/rdoc/i18n.rb +10 -0
  107. data/lib/rdoc/include.rb +10 -0
  108. data/lib/rdoc/known_classes.rb +73 -0
  109. data/lib/rdoc/markdown/entities.rb +2132 -0
  110. data/lib/rdoc/markdown/literals.kpeg +23 -0
  111. data/lib/rdoc/markdown/literals.rb +417 -0
  112. data/lib/rdoc/markdown.kpeg +1237 -0
  113. data/lib/rdoc/markdown.rb +16685 -0
  114. data/lib/rdoc/markup/attr_changer.rb +23 -0
  115. data/lib/rdoc/markup/attr_span.rb +36 -0
  116. data/lib/rdoc/markup/attribute_manager.rb +409 -0
  117. data/lib/rdoc/markup/attributes.rb +71 -0
  118. data/lib/rdoc/markup/blank_line.rb +28 -0
  119. data/lib/rdoc/markup/block_quote.rb +15 -0
  120. data/lib/rdoc/markup/document.rb +165 -0
  121. data/lib/rdoc/markup/formatter.rb +266 -0
  122. data/lib/rdoc/markup/hard_break.rb +32 -0
  123. data/lib/rdoc/markup/heading.rb +79 -0
  124. data/lib/rdoc/markup/include.rb +43 -0
  125. data/lib/rdoc/markup/indented_paragraph.rb +48 -0
  126. data/lib/rdoc/markup/list.rb +102 -0
  127. data/lib/rdoc/markup/list_item.rb +100 -0
  128. data/lib/rdoc/markup/paragraph.rb +29 -0
  129. data/lib/rdoc/markup/parser.rb +575 -0
  130. data/lib/rdoc/markup/pre_process.rb +296 -0
  131. data/lib/rdoc/markup/raw.rb +70 -0
  132. data/lib/rdoc/markup/regexp_handling.rb +41 -0
  133. data/lib/rdoc/markup/rule.rb +21 -0
  134. data/lib/rdoc/markup/table.rb +47 -0
  135. data/lib/rdoc/markup/to_ansi.rb +94 -0
  136. data/lib/rdoc/markup/to_bs.rb +77 -0
  137. data/lib/rdoc/markup/to_html.rb +444 -0
  138. data/lib/rdoc/markup/to_html_crossref.rb +176 -0
  139. data/lib/rdoc/markup/to_html_snippet.rb +285 -0
  140. data/lib/rdoc/markup/to_joined_paragraph.rb +47 -0
  141. data/lib/rdoc/markup/to_label.rb +75 -0
  142. data/lib/rdoc/markup/to_markdown.rb +192 -0
  143. data/lib/rdoc/markup/to_rdoc.rb +362 -0
  144. data/lib/rdoc/markup/to_table_of_contents.rb +89 -0
  145. data/lib/rdoc/markup/to_test.rb +70 -0
  146. data/lib/rdoc/markup/to_tt_only.rb +121 -0
  147. data/lib/rdoc/markup/verbatim.rb +84 -0
  148. data/lib/rdoc/markup.rb +867 -0
  149. data/lib/rdoc/meta_method.rb +7 -0
  150. data/lib/rdoc/method_attr.rb +419 -0
  151. data/lib/rdoc/mixin.rb +121 -0
  152. data/lib/rdoc/normal_class.rb +93 -0
  153. data/lib/rdoc/normal_module.rb +74 -0
  154. data/lib/rdoc/options.rb +1285 -0
  155. data/lib/rdoc/parser/c.rb +1225 -0
  156. data/lib/rdoc/parser/changelog.rb +335 -0
  157. data/lib/rdoc/parser/markdown.rb +24 -0
  158. data/lib/rdoc/parser/rd.rb +23 -0
  159. data/lib/rdoc/parser/ripper_state_lex.rb +590 -0
  160. data/lib/rdoc/parser/ruby.rb +2327 -0
  161. data/lib/rdoc/parser/ruby_tools.rb +167 -0
  162. data/lib/rdoc/parser/simple.rb +61 -0
  163. data/lib/rdoc/parser/text.rb +12 -0
  164. data/lib/rdoc/parser.rb +277 -0
  165. data/lib/rdoc/rd/block_parser.rb +1056 -0
  166. data/lib/rdoc/rd/block_parser.ry +639 -0
  167. data/lib/rdoc/rd/inline.rb +72 -0
  168. data/lib/rdoc/rd/inline_parser.rb +1208 -0
  169. data/lib/rdoc/rd/inline_parser.ry +593 -0
  170. data/lib/rdoc/rd.rb +100 -0
  171. data/lib/rdoc/rdoc.rb +579 -0
  172. data/lib/rdoc/require.rb +52 -0
  173. data/lib/rdoc/ri/driver.rb +1572 -0
  174. data/lib/rdoc/ri/formatter.rb +6 -0
  175. data/lib/rdoc/ri/paths.rb +171 -0
  176. data/lib/rdoc/ri/store.rb +7 -0
  177. data/lib/rdoc/ri/task.rb +71 -0
  178. data/lib/rdoc/ri.rb +21 -0
  179. data/lib/rdoc/rubygems_hook.rb +246 -0
  180. data/lib/rdoc/servlet.rb +451 -0
  181. data/lib/rdoc/single_class.rb +26 -0
  182. data/lib/rdoc/stats/normal.rb +58 -0
  183. data/lib/rdoc/stats/quiet.rb +60 -0
  184. data/lib/rdoc/stats/verbose.rb +46 -0
  185. data/lib/rdoc/stats.rb +462 -0
  186. data/lib/rdoc/store.rb +979 -0
  187. data/lib/rdoc/task.rb +329 -0
  188. data/lib/rdoc/text.rb +304 -0
  189. data/lib/rdoc/token_stream.rb +119 -0
  190. data/lib/rdoc/tom_doc.rb +263 -0
  191. data/lib/rdoc/top_level.rb +289 -0
  192. data/lib/rdoc/version.rb +8 -0
  193. data/lib/rdoc.rb +201 -0
  194. data/man/ri.1 +247 -0
  195. data/rdoc.gemspec +249 -0
  196. metadata +279 -0
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+ class RDoc::Markup
3
+
4
+ AttrChanger = Struct.new :turn_on, :turn_off # :nodoc:
5
+
6
+ end
7
+
8
+ ##
9
+ # An AttrChanger records a change in attributes. It contains a bitmap of the
10
+ # attributes to turn on, and a bitmap of those to turn off.
11
+
12
+ class RDoc::Markup::AttrChanger
13
+
14
+ def to_s # :nodoc:
15
+ "Attr: +#{turn_on}/-#{turn_off}"
16
+ end
17
+
18
+ def inspect # :nodoc:
19
+ '+%d/-%d' % [turn_on, turn_off]
20
+ end
21
+
22
+ end
23
+
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+ ##
3
+ # An array of attributes which parallels the characters in a string.
4
+
5
+ class RDoc::Markup::AttrSpan
6
+
7
+ ##
8
+ # Creates a new AttrSpan for +length+ characters
9
+
10
+ def initialize(length, exclusive)
11
+ @attrs = Array.new(length, 0)
12
+ @exclusive = exclusive
13
+ end
14
+
15
+ ##
16
+ # Toggles +bits+ from +start+ to +length+
17
+ def set_attrs(start, length, bits)
18
+ updated = false
19
+ for i in start ... (start+length)
20
+ if (@exclusive & @attrs[i]) == 0 || (@exclusive & bits) != 0
21
+ @attrs[i] |= bits
22
+ updated = true
23
+ end
24
+ end
25
+ updated
26
+ end
27
+
28
+ ##
29
+ # Accesses flags for character +n+
30
+
31
+ def [](n)
32
+ @attrs[n]
33
+ end
34
+
35
+ end
36
+
@@ -0,0 +1,409 @@
1
+ # frozen_string_literal: true
2
+ ##
3
+ # Manages changes of attributes in a block of text
4
+
5
+ class RDoc::Markup::AttributeManager
6
+
7
+ ##
8
+ # The NUL character
9
+
10
+ NULL = "\000".freeze
11
+
12
+ #--
13
+ # We work by substituting non-printing characters in to the text. For now
14
+ # I'm assuming that I can substitute a character in the range 0..8 for a 7
15
+ # bit character without damaging the encoded string, but this might be
16
+ # optimistic
17
+ #++
18
+
19
+ A_PROTECT = 004 # :nodoc:
20
+
21
+ ##
22
+ # Special mask character to prevent inline markup handling
23
+
24
+ PROTECT_ATTR = A_PROTECT.chr # :nodoc:
25
+
26
+ ##
27
+ # The attributes enabled for this markup object.
28
+
29
+ attr_reader :attributes
30
+
31
+ ##
32
+ # This maps delimiters that occur around words (such as *bold* or +tt+)
33
+ # where the start and end delimiters and the same. This lets us optimize
34
+ # the regexp
35
+
36
+ attr_reader :matching_word_pairs
37
+
38
+ ##
39
+ # And this is used when the delimiters aren't the same. In this case the
40
+ # hash maps a pattern to the attribute character
41
+
42
+ attr_reader :word_pair_map
43
+
44
+ ##
45
+ # This maps HTML tags to the corresponding attribute char
46
+
47
+ attr_reader :html_tags
48
+
49
+ ##
50
+ # A \ in front of a character that would normally be processed turns off
51
+ # processing. We do this by turning \< into <#{PROTECT}
52
+
53
+ attr_reader :protectable
54
+
55
+ ##
56
+ # And this maps _regexp handling_ sequences to a name. A regexp handling
57
+ # sequence is something like a WikiWord
58
+
59
+ attr_reader :regexp_handlings
60
+
61
+ ##
62
+ # A bits of exclusive maps
63
+ attr_reader :exclusive_bitmap
64
+
65
+ ##
66
+ # Creates a new attribute manager that understands bold, emphasized and
67
+ # teletype text.
68
+
69
+ def initialize
70
+ @html_tags = {}
71
+ @matching_word_pairs = {}
72
+ @protectable = %w[<]
73
+ @regexp_handlings = []
74
+ @word_pair_map = {}
75
+ @exclusive_bitmap = 0
76
+ @attributes = RDoc::Markup::Attributes.new
77
+
78
+ add_word_pair "*", "*", :BOLD, true
79
+ add_word_pair "_", "_", :EM, true
80
+ add_word_pair "+", "+", :TT, true
81
+
82
+ add_html "em", :EM, true
83
+ add_html "i", :EM, true
84
+ add_html "b", :BOLD, true
85
+ add_html "tt", :TT, true
86
+ add_html "code", :TT, true
87
+ end
88
+
89
+ ##
90
+ # Return an attribute object with the given turn_on and turn_off bits set
91
+
92
+ def attribute(turn_on, turn_off)
93
+ RDoc::Markup::AttrChanger.new turn_on, turn_off
94
+ end
95
+
96
+ ##
97
+ # Changes the current attribute from +current+ to +new+
98
+
99
+ def change_attribute current, new
100
+ diff = current ^ new
101
+ attribute(new & diff, current & diff)
102
+ end
103
+
104
+ ##
105
+ # Used by the tests to change attributes by name from +current_set+ to
106
+ # +new_set+
107
+
108
+ def changed_attribute_by_name current_set, new_set
109
+ current = new = 0
110
+ current_set.each do |name|
111
+ current |= @attributes.bitmap_for(name)
112
+ end
113
+
114
+ new_set.each do |name|
115
+ new |= @attributes.bitmap_for(name)
116
+ end
117
+
118
+ change_attribute(current, new)
119
+ end
120
+
121
+ ##
122
+ # Copies +start_pos+ to +end_pos+ from the current string
123
+
124
+ def copy_string(start_pos, end_pos)
125
+ res = @str[start_pos...end_pos]
126
+ res.gsub!(/\000/, '')
127
+ res
128
+ end
129
+
130
+ def exclusive?(attr)
131
+ (attr & @exclusive_bitmap) != 0
132
+ end
133
+
134
+ NON_PRINTING_START = "\1" # :nodoc:
135
+ NON_PRINTING_END = "\2" # :nodoc:
136
+
137
+ ##
138
+ # Map attributes like <b>text</b>to the sequence
139
+ # \001\002<char>\001\003<char>, where <char> is a per-attribute specific
140
+ # character
141
+
142
+ def convert_attrs(str, attrs, exclusive = false)
143
+ convert_attrs_matching_word_pairs(str, attrs, exclusive)
144
+ convert_attrs_word_pair_map(str, attrs, exclusive)
145
+ end
146
+
147
+ def convert_attrs_matching_word_pairs(str, attrs, exclusive)
148
+ # first do matching ones
149
+ tags = @matching_word_pairs.select { |start, bitmap|
150
+ if exclusive && exclusive?(bitmap)
151
+ true
152
+ elsif !exclusive && !exclusive?(bitmap)
153
+ true
154
+ else
155
+ false
156
+ end
157
+ }.keys
158
+ return if tags.empty?
159
+ all_tags = @matching_word_pairs.keys
160
+
161
+ re = /(^|\W|[#{all_tags.join("")}])([#{tags.join("")}])(\2*[#\\]?[\w:.\/\[\]-]+?\S?)\2(?!\2)([#{all_tags.join("")}]|\W|$)/
162
+
163
+ 1 while str.gsub!(re) { |orig|
164
+ attr = @matching_word_pairs[$2]
165
+ attr_updated = attrs.set_attrs($`.length + $1.length + $2.length, $3.length, attr)
166
+ if attr_updated
167
+ $1 + NULL * $2.length + $3 + NULL * $2.length + $4
168
+ else
169
+ $1 + NON_PRINTING_START + $2 + NON_PRINTING_END + $3 + NON_PRINTING_START + $2 + NON_PRINTING_END + $4
170
+ end
171
+ }
172
+ str.delete!(NON_PRINTING_START + NON_PRINTING_END)
173
+ end
174
+
175
+ def convert_attrs_word_pair_map(str, attrs, exclusive)
176
+ # then non-matching
177
+ unless @word_pair_map.empty? then
178
+ @word_pair_map.each do |regexp, attr|
179
+ if !exclusive
180
+ next if exclusive?(attr)
181
+ else
182
+ next if !exclusive?(attr)
183
+ end
184
+ 1 while str.gsub!(regexp) { |orig|
185
+ updated = attrs.set_attrs($`.length + $1.length, $2.length, attr)
186
+ if updated
187
+ NULL * $1.length + $2 + NULL * $3.length
188
+ else
189
+ orig
190
+ end
191
+ }
192
+ end
193
+ end
194
+ end
195
+
196
+ ##
197
+ # Converts HTML tags to RDoc attributes
198
+
199
+ def convert_html(str, attrs, exclusive = false)
200
+ tags = @html_tags.select { |start, bitmap|
201
+ if exclusive && exclusive?(bitmap)
202
+ true
203
+ elsif !exclusive && !exclusive?(bitmap)
204
+ true
205
+ else
206
+ false
207
+ end
208
+ }.keys.join '|'
209
+
210
+ 1 while str.gsub!(/<(#{tags})>(.*?)<\/\1>/i) { |orig|
211
+ attr = @html_tags[$1.downcase]
212
+ html_length = $1.length + 2
213
+ seq = NULL * html_length
214
+ attrs.set_attrs($`.length + html_length, $2.length, attr)
215
+ seq + $2 + seq + NULL
216
+ }
217
+ end
218
+
219
+ ##
220
+ # Converts regexp handling sequences to RDoc attributes
221
+
222
+ def convert_regexp_handlings str, attrs, exclusive = false
223
+ @regexp_handlings.each do |regexp, attribute|
224
+ if exclusive
225
+ next if !exclusive?(attribute)
226
+ else
227
+ next if exclusive?(attribute)
228
+ end
229
+ str.scan(regexp) do
230
+ capture = $~.size == 1 ? 0 : 1
231
+
232
+ s, e = $~.offset capture
233
+
234
+ attrs.set_attrs s, e - s, attribute | @attributes.regexp_handling
235
+ end
236
+ end
237
+ end
238
+
239
+ ##
240
+ # Escapes regexp handling sequences of text to prevent conversion to RDoc
241
+
242
+ def mask_protected_sequences
243
+ # protect __send__, __FILE__, etc.
244
+ @str.gsub!(/__([a-z]+)__/i,
245
+ "_#{PROTECT_ATTR}_#{PROTECT_ATTR}\\1_#{PROTECT_ATTR}_#{PROTECT_ATTR}")
246
+ @str.gsub!(/(\A|[^\\])\\([#{Regexp.escape @protectable.join}])/m,
247
+ "\\1\\2#{PROTECT_ATTR}")
248
+ @str.gsub!(/\\(\\[#{Regexp.escape @protectable.join}])/m, "\\1")
249
+ end
250
+
251
+ ##
252
+ # Unescapes regexp handling sequences of text
253
+
254
+ def unmask_protected_sequences
255
+ @str.gsub!(/(.)#{PROTECT_ATTR}/, "\\1\000")
256
+ end
257
+
258
+ ##
259
+ # Adds a markup class with +name+ for words wrapped in the +start+ and
260
+ # +stop+ character. To make words wrapped with "*" bold:
261
+ #
262
+ # am.add_word_pair '*', '*', :BOLD
263
+
264
+ def add_word_pair(start, stop, name, exclusive = false)
265
+ raise ArgumentError, "Word flags may not start with '<'" if
266
+ start[0,1] == '<'
267
+
268
+ bitmap = @attributes.bitmap_for name
269
+
270
+ if start == stop then
271
+ @matching_word_pairs[start] = bitmap
272
+ else
273
+ pattern = /(#{Regexp.escape start})(\S+)(#{Regexp.escape stop})/
274
+ @word_pair_map[pattern] = bitmap
275
+ end
276
+
277
+ @protectable << start[0,1]
278
+ @protectable.uniq!
279
+
280
+ @exclusive_bitmap |= bitmap if exclusive
281
+ end
282
+
283
+ ##
284
+ # Adds a markup class with +name+ for words surrounded by HTML tag +tag+.
285
+ # To process emphasis tags:
286
+ #
287
+ # am.add_html 'em', :EM
288
+
289
+ def add_html(tag, name, exclusive = false)
290
+ bitmap = @attributes.bitmap_for name
291
+ @html_tags[tag.downcase] = bitmap
292
+ @exclusive_bitmap |= bitmap if exclusive
293
+ end
294
+
295
+ ##
296
+ # Adds a regexp handling for +pattern+ with +name+. A simple URL handler
297
+ # would be:
298
+ #
299
+ # @am.add_regexp_handling(/((https?:)\S+\w)/, :HYPERLINK)
300
+
301
+ def add_regexp_handling pattern, name, exclusive = false
302
+ bitmap = @attributes.bitmap_for(name)
303
+ @regexp_handlings << [pattern, bitmap]
304
+ @exclusive_bitmap |= bitmap if exclusive
305
+ end
306
+
307
+ ##
308
+ # Processes +str+ converting attributes, HTML and regexp handlings
309
+
310
+ def flow str
311
+ @str = str.dup
312
+
313
+ mask_protected_sequences
314
+
315
+ @attrs = RDoc::Markup::AttrSpan.new @str.length, @exclusive_bitmap
316
+
317
+ convert_attrs @str, @attrs, true
318
+ convert_html @str, @attrs, true
319
+ convert_regexp_handlings @str, @attrs, true
320
+ convert_attrs @str, @attrs
321
+ convert_html @str, @attrs
322
+ convert_regexp_handlings @str, @attrs
323
+
324
+ unmask_protected_sequences
325
+
326
+ split_into_flow
327
+ end
328
+
329
+ ##
330
+ # Debug method that prints a string along with its attributes
331
+
332
+ def display_attributes
333
+ puts
334
+ puts @str.tr(NULL, "!")
335
+ bit = 1
336
+ 16.times do |bno|
337
+ line = ""
338
+ @str.length.times do |i|
339
+ if (@attrs[i] & bit) == 0
340
+ line << " "
341
+ else
342
+ if bno.zero?
343
+ line << "S"
344
+ else
345
+ line << ("%d" % (bno+1))
346
+ end
347
+ end
348
+ end
349
+ puts(line) unless line =~ /^ *$/
350
+ bit <<= 1
351
+ end
352
+ end
353
+
354
+ ##
355
+ # Splits the string into chunks by attribute change
356
+
357
+ def split_into_flow
358
+ res = []
359
+ current_attr = 0
360
+
361
+ str_len = @str.length
362
+
363
+ # skip leading invisible text
364
+ i = 0
365
+ i += 1 while i < str_len and @str[i].chr == "\0"
366
+ start_pos = i
367
+
368
+ # then scan the string, chunking it on attribute changes
369
+ while i < str_len
370
+ new_attr = @attrs[i]
371
+ if new_attr != current_attr
372
+ if i > start_pos
373
+ res << copy_string(start_pos, i)
374
+ start_pos = i
375
+ end
376
+
377
+ res << change_attribute(current_attr, new_attr)
378
+ current_attr = new_attr
379
+
380
+ if (current_attr & @attributes.regexp_handling) != 0 then
381
+ i += 1 while
382
+ i < str_len and (@attrs[i] & @attributes.regexp_handling) != 0
383
+
384
+ res << RDoc::Markup::RegexpHandling.new(current_attr,
385
+ copy_string(start_pos, i))
386
+ start_pos = i
387
+ next
388
+ end
389
+ end
390
+
391
+ # move on, skipping any invisible characters
392
+ begin
393
+ i += 1
394
+ end while i < str_len and @str[i].chr == "\0"
395
+ end
396
+
397
+ # tidy up trailing text
398
+ if start_pos < str_len
399
+ res << copy_string(start_pos, str_len)
400
+ end
401
+
402
+ # and reset to all attributes off
403
+ res << change_attribute(current_attr, 0) if current_attr != 0
404
+
405
+ res
406
+ end
407
+
408
+ end
409
+