rdoc 3.1 → 6.3.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rdoc might be problematic. Click here for more details.

Files changed (247) 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 +129 -0
  11. data/RI.rdoc +57 -0
  12. data/Rakefile +84 -81
  13. data/TODO.rdoc +59 -0
  14. data/bin/console +7 -0
  15. data/bin/setup +6 -0
  16. data/{bin → exe}/rdoc +11 -2
  17. data/exe/ri +12 -0
  18. data/lib/rdoc/alias.rb +1 -2
  19. data/lib/rdoc/anon_class.rb +3 -2
  20. data/lib/rdoc/any_method.rb +234 -40
  21. data/lib/rdoc/attr.rb +79 -11
  22. data/lib/rdoc/class_module.rb +443 -71
  23. data/lib/rdoc/code_object.rb +216 -20
  24. data/lib/rdoc/code_objects.rb +4 -21
  25. data/lib/rdoc/comment.rb +250 -0
  26. data/lib/rdoc/constant.rb +110 -9
  27. data/lib/rdoc/context/section.rb +232 -0
  28. data/lib/rdoc/context.rb +392 -172
  29. data/lib/rdoc/cross_reference.rb +202 -0
  30. data/lib/rdoc/encoding.rb +83 -28
  31. data/lib/rdoc/erb_partial.rb +19 -0
  32. data/lib/rdoc/erbio.rb +8 -3
  33. data/lib/rdoc/extend.rb +10 -0
  34. data/lib/rdoc/generator/darkfish.rb +507 -84
  35. data/lib/rdoc/generator/json_index.rb +300 -0
  36. data/lib/rdoc/generator/markup.rb +27 -74
  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 +8 -62
  42. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +5 -0
  43. data/lib/rdoc/generator/template/darkfish/_head.rhtml +22 -0
  44. data/lib/rdoc/generator/template/darkfish/_sidebar_VCS_info.rhtml +19 -0
  45. data/lib/rdoc/generator/template/darkfish/_sidebar_classes.rhtml +9 -0
  46. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +15 -0
  47. data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +9 -0
  48. data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +15 -0
  49. data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +15 -0
  50. data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +12 -0
  51. data/lib/rdoc/generator/template/darkfish/_sidebar_navigation.rhtml +11 -0
  52. data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +12 -0
  53. data/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml +11 -0
  54. data/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml +14 -0
  55. data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +11 -0
  56. data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +18 -0
  57. data/lib/rdoc/generator/template/darkfish/class.rhtml +172 -0
  58. data/lib/rdoc/generator/template/darkfish/css/fonts.css +167 -0
  59. data/lib/rdoc/generator/template/darkfish/css/rdoc.css +639 -0
  60. data/lib/rdoc/generator/template/darkfish/fonts/Lato-Light.ttf +0 -0
  61. data/lib/rdoc/generator/template/darkfish/fonts/Lato-LightItalic.ttf +0 -0
  62. data/lib/rdoc/generator/template/darkfish/fonts/Lato-Regular.ttf +0 -0
  63. data/lib/rdoc/generator/template/darkfish/fonts/Lato-RegularItalic.ttf +0 -0
  64. data/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Bold.ttf +0 -0
  65. data/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Regular.ttf +0 -0
  66. data/lib/rdoc/generator/template/darkfish/images/add.png +0 -0
  67. data/lib/rdoc/generator/template/darkfish/images/arrow_up.png +0 -0
  68. data/lib/rdoc/generator/template/darkfish/images/delete.png +0 -0
  69. data/lib/rdoc/generator/template/darkfish/images/tag_blue.png +0 -0
  70. data/lib/rdoc/generator/template/darkfish/images/transparent.png +0 -0
  71. data/lib/rdoc/generator/template/darkfish/index.rhtml +18 -60
  72. data/lib/rdoc/generator/template/darkfish/js/darkfish.js +51 -83
  73. data/lib/rdoc/generator/template/darkfish/js/search.js +110 -0
  74. data/lib/rdoc/generator/template/darkfish/page.rhtml +18 -0
  75. data/lib/rdoc/generator/template/darkfish/servlet_not_found.rhtml +18 -0
  76. data/lib/rdoc/generator/template/darkfish/servlet_root.rhtml +62 -0
  77. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +58 -0
  78. data/lib/rdoc/generator/template/json_index/.document +1 -0
  79. data/lib/rdoc/generator/template/json_index/js/navigation.js +105 -0
  80. data/lib/rdoc/generator/template/json_index/js/searcher.js +229 -0
  81. data/lib/rdoc/generator.rb +24 -13
  82. data/lib/rdoc/ghost_method.rb +1 -2
  83. data/lib/rdoc/i18n/locale.rb +102 -0
  84. data/lib/rdoc/i18n/text.rb +126 -0
  85. data/lib/rdoc/i18n.rb +10 -0
  86. data/lib/rdoc/include.rb +5 -95
  87. data/lib/rdoc/known_classes.rb +5 -2
  88. data/lib/rdoc/markdown/entities.rb +2132 -0
  89. data/lib/rdoc/markdown/literals.kpeg +23 -0
  90. data/lib/rdoc/markdown/literals.rb +416 -0
  91. data/lib/rdoc/markdown.kpeg +1237 -0
  92. data/lib/rdoc/markdown.rb +16684 -0
  93. data/lib/rdoc/markup/attr_changer.rb +23 -0
  94. data/lib/rdoc/markup/attr_span.rb +36 -0
  95. data/lib/rdoc/markup/attribute_manager.rb +135 -62
  96. data/lib/rdoc/markup/attributes.rb +71 -0
  97. data/lib/rdoc/markup/blank_line.rb +1 -0
  98. data/lib/rdoc/markup/block_quote.rb +15 -0
  99. data/lib/rdoc/markup/document.rb +96 -9
  100. data/lib/rdoc/markup/formatter.rb +138 -25
  101. data/lib/rdoc/markup/hard_break.rb +32 -0
  102. data/lib/rdoc/markup/heading.rb +61 -2
  103. data/lib/rdoc/markup/include.rb +43 -0
  104. data/lib/rdoc/markup/indented_paragraph.rb +48 -0
  105. data/lib/rdoc/markup/list.rb +25 -4
  106. data/lib/rdoc/markup/list_item.rb +18 -4
  107. data/lib/rdoc/markup/paragraph.rb +15 -0
  108. data/lib/rdoc/markup/parser.rb +180 -88
  109. data/lib/rdoc/markup/pre_process.rb +183 -38
  110. data/lib/rdoc/markup/raw.rb +6 -5
  111. data/lib/rdoc/markup/regexp_handling.rb +41 -0
  112. data/lib/rdoc/markup/rule.rb +1 -0
  113. data/lib/rdoc/markup/table.rb +47 -0
  114. data/lib/rdoc/markup/to_ansi.rb +17 -7
  115. data/lib/rdoc/markup/to_bs.rb +5 -8
  116. data/lib/rdoc/markup/to_html.rb +238 -137
  117. data/lib/rdoc/markup/to_html_crossref.rb +125 -152
  118. data/lib/rdoc/markup/to_html_snippet.rb +285 -0
  119. data/lib/rdoc/markup/to_joined_paragraph.rb +47 -0
  120. data/lib/rdoc/markup/to_label.rb +75 -0
  121. data/lib/rdoc/markup/to_markdown.rb +192 -0
  122. data/lib/rdoc/markup/to_rdoc.rb +85 -15
  123. data/lib/rdoc/markup/to_table_of_contents.rb +89 -0
  124. data/lib/rdoc/markup/to_test.rb +2 -4
  125. data/lib/rdoc/markup/to_tt_only.rb +121 -0
  126. data/lib/rdoc/markup/verbatim.rb +39 -0
  127. data/lib/rdoc/markup.rb +388 -110
  128. data/lib/rdoc/meta_method.rb +1 -2
  129. data/lib/rdoc/method_attr.rb +87 -21
  130. data/lib/rdoc/mixin.rb +121 -0
  131. data/lib/rdoc/normal_class.rb +39 -10
  132. data/lib/rdoc/normal_module.rb +22 -7
  133. data/lib/rdoc/options.rb +613 -73
  134. data/lib/rdoc/parser/c.rb +621 -287
  135. data/lib/rdoc/parser/changelog.rb +335 -0
  136. data/lib/rdoc/parser/markdown.rb +24 -0
  137. data/lib/rdoc/parser/rd.rb +23 -0
  138. data/lib/rdoc/parser/ripper_state_lex.rb +590 -0
  139. data/lib/rdoc/parser/ruby.rb +1368 -762
  140. data/lib/rdoc/parser/ruby_tools.rb +42 -35
  141. data/lib/rdoc/parser/simple.rb +23 -11
  142. data/lib/rdoc/parser/text.rb +12 -0
  143. data/lib/rdoc/parser.rb +162 -89
  144. data/lib/rdoc/rd/block_parser.rb +1056 -0
  145. data/lib/rdoc/rd/block_parser.ry +639 -0
  146. data/lib/rdoc/rd/inline.rb +72 -0
  147. data/lib/rdoc/rd/inline_parser.rb +1208 -0
  148. data/lib/rdoc/rd/inline_parser.ry +593 -0
  149. data/lib/rdoc/rd.rb +100 -0
  150. data/lib/rdoc/rdoc.rb +208 -115
  151. data/lib/rdoc/require.rb +1 -2
  152. data/lib/rdoc/ri/driver.rb +734 -239
  153. data/lib/rdoc/ri/formatter.rb +1 -0
  154. data/lib/rdoc/ri/paths.rb +91 -48
  155. data/lib/rdoc/ri/store.rb +3 -261
  156. data/lib/rdoc/ri/task.rb +71 -0
  157. data/lib/rdoc/ri.rb +5 -2
  158. data/lib/rdoc/rubygems_hook.rb +246 -0
  159. data/lib/rdoc/servlet.rb +451 -0
  160. data/lib/rdoc/single_class.rb +14 -2
  161. data/lib/rdoc/stats/normal.rb +19 -12
  162. data/lib/rdoc/stats/quiet.rb +1 -0
  163. data/lib/rdoc/stats/verbose.rb +1 -0
  164. data/lib/rdoc/stats.rb +262 -104
  165. data/lib/rdoc/store.rb +979 -0
  166. data/lib/rdoc/task.rb +84 -44
  167. data/lib/rdoc/text.rb +117 -72
  168. data/lib/rdoc/token_stream.rb +73 -4
  169. data/lib/rdoc/tom_doc.rb +263 -0
  170. data/lib/rdoc/top_level.rb +111 -261
  171. data/lib/rdoc/version.rb +8 -0
  172. data/lib/rdoc.rb +127 -64
  173. data/man/ri.1 +247 -0
  174. data/rdoc.gemspec +249 -0
  175. metadata +171 -291
  176. data/.autotest +0 -16
  177. data/.document +0 -5
  178. data/History.txt +0 -594
  179. data/LICENSE.txt +0 -57
  180. data/Manifest.txt +0 -158
  181. data/README.txt +0 -45
  182. data/RI.txt +0 -58
  183. data/bin/ri +0 -5
  184. data/lib/rdoc/gauntlet.rb +0 -52
  185. data/lib/rdoc/generator/template/darkfish/classpage.rhtml +0 -296
  186. data/lib/rdoc/generator/template/darkfish/filepage.rhtml +0 -124
  187. data/lib/rdoc/generator/template/darkfish/js/jquery.js +0 -32
  188. data/lib/rdoc/generator/template/darkfish/js/quicksearch.js +0 -114
  189. data/lib/rdoc/generator/template/darkfish/js/thickbox-compressed.js +0 -10
  190. data/lib/rdoc/generator/template/darkfish/rdoc.css +0 -706
  191. data/lib/rdoc/markup/formatter_test_case.rb +0 -689
  192. data/lib/rdoc/markup/inline.rb +0 -137
  193. data/lib/rdoc/markup/text_formatter_test_case.rb +0 -116
  194. data/lib/rdoc/ruby_lex.rb +0 -1291
  195. data/lib/rdoc/ruby_token.rb +0 -416
  196. data/test/README +0 -1
  197. data/test/binary.dat +0 -0
  198. data/test/hidden.zip.txt +0 -1
  199. data/test/test.ja.rdoc +0 -10
  200. data/test/test.ja.txt +0 -8
  201. data/test/test.txt +0 -1
  202. data/test/test_attribute_manager.rb +0 -120
  203. data/test/test_rdoc_alias.rb +0 -13
  204. data/test/test_rdoc_any_method.rb +0 -126
  205. data/test/test_rdoc_attr.rb +0 -61
  206. data/test/test_rdoc_class_module.rb +0 -233
  207. data/test/test_rdoc_code_object.rb +0 -165
  208. data/test/test_rdoc_constant.rb +0 -15
  209. data/test/test_rdoc_context.rb +0 -370
  210. data/test/test_rdoc_encoding.rb +0 -166
  211. data/test/test_rdoc_generator_darkfish.rb +0 -119
  212. data/test/test_rdoc_generator_ri.rb +0 -76
  213. data/test/test_rdoc_include.rb +0 -96
  214. data/test/test_rdoc_markup.rb +0 -37
  215. data/test/test_rdoc_markup_attribute_manager.rb +0 -240
  216. data/test/test_rdoc_markup_document.rb +0 -51
  217. data/test/test_rdoc_markup_paragraph.rb +0 -9
  218. data/test/test_rdoc_markup_parser.rb +0 -1395
  219. data/test/test_rdoc_markup_pre_process.rb +0 -185
  220. data/test/test_rdoc_markup_raw.rb +0 -27
  221. data/test/test_rdoc_markup_to_ansi.rb +0 -328
  222. data/test/test_rdoc_markup_to_bs.rb +0 -341
  223. data/test/test_rdoc_markup_to_html.rb +0 -335
  224. data/test/test_rdoc_markup_to_html_crossref.rb +0 -169
  225. data/test/test_rdoc_markup_to_rdoc.rb +0 -327
  226. data/test/test_rdoc_method_attr.rb +0 -122
  227. data/test/test_rdoc_normal_class.rb +0 -17
  228. data/test/test_rdoc_normal_module.rb +0 -31
  229. data/test/test_rdoc_options.rb +0 -342
  230. data/test/test_rdoc_parser.rb +0 -83
  231. data/test/test_rdoc_parser_c.rb +0 -912
  232. data/test/test_rdoc_parser_ruby.rb +0 -1754
  233. data/test/test_rdoc_parser_simple.rb +0 -99
  234. data/test/test_rdoc_rdoc.rb +0 -164
  235. data/test/test_rdoc_require.rb +0 -25
  236. data/test/test_rdoc_ri_driver.rb +0 -846
  237. data/test/test_rdoc_ri_paths.rb +0 -43
  238. data/test/test_rdoc_ri_store.rb +0 -352
  239. data/test/test_rdoc_ruby_lex.rb +0 -23
  240. data/test/test_rdoc_stats.rb +0 -38
  241. data/test/test_rdoc_task.rb +0 -92
  242. data/test/test_rdoc_text.rb +0 -251
  243. data/test/test_rdoc_top_level.rb +0 -120
  244. data/test/xref_data.rb +0 -62
  245. data/test/xref_test_case.rb +0 -61
  246. data.tar.gz.sig +0 -3
  247. metadata.gz.sig +0 -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
+
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  ##
2
3
  # Manages changes of attributes in a block of text
3
4
 
@@ -22,6 +23,11 @@ class RDoc::Markup::AttributeManager
22
23
 
23
24
  PROTECT_ATTR = A_PROTECT.chr # :nodoc:
24
25
 
26
+ ##
27
+ # The attributes enabled for this markup object.
28
+
29
+ attr_reader :attributes
30
+
25
31
  ##
26
32
  # This maps delimiters that occur around words (such as *bold* or +tt+)
27
33
  # where the start and end delimiters and the same. This lets us optimize
@@ -47,10 +53,14 @@ class RDoc::Markup::AttributeManager
47
53
  attr_reader :protectable
48
54
 
49
55
  ##
50
- # And this maps _special_ sequences to a name. A special sequence is
51
- # something like a WikiWord
56
+ # And this maps _regexp handling_ sequences to a name. A regexp handling
57
+ # sequence is something like a WikiWord
52
58
 
53
- attr_reader :special
59
+ attr_reader :regexp_handlings
60
+
61
+ ##
62
+ # A bits of exclusive maps
63
+ attr_reader :exclusive_bitmap
54
64
 
55
65
  ##
56
66
  # Creates a new attribute manager that understands bold, emphasized and
@@ -60,21 +70,22 @@ class RDoc::Markup::AttributeManager
60
70
  @html_tags = {}
61
71
  @matching_word_pairs = {}
62
72
  @protectable = %w[<]
63
- @special = {}
73
+ @regexp_handlings = []
64
74
  @word_pair_map = {}
65
-
66
- add_word_pair "*", "*", :BOLD
67
- add_word_pair "_", "_", :EM
68
- add_word_pair "+", "+", :TT
69
-
70
- add_html "em", :EM
71
- add_html "i", :EM
72
- add_html "b", :BOLD
73
- add_html "tt", :TT
74
- add_html "code", :TT
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
75
87
  end
76
88
 
77
-
78
89
  ##
79
90
  # Return an attribute object with the given turn_on and turn_off bits set
80
91
 
@@ -97,11 +108,11 @@ class RDoc::Markup::AttributeManager
97
108
  def changed_attribute_by_name current_set, new_set
98
109
  current = new = 0
99
110
  current_set.each do |name|
100
- current |= RDoc::Markup::Attribute.bitmap_for(name)
111
+ current |= @attributes.bitmap_for(name)
101
112
  end
102
113
 
103
114
  new_set.each do |name|
104
- new |= RDoc::Markup::Attribute.bitmap_for(name)
115
+ new |= @attributes.bitmap_for(name)
105
116
  end
106
117
 
107
118
  change_attribute(current, new)
@@ -116,29 +127,67 @@ class RDoc::Markup::AttributeManager
116
127
  res
117
128
  end
118
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
+
119
137
  ##
120
138
  # Map attributes like <b>text</b>to the sequence
121
139
  # \001\002<char>\001\003<char>, where <char> is a per-attribute specific
122
140
  # character
123
141
 
124
- def convert_attrs(str, attrs)
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)
125
148
  # first do matching ones
126
- tags = @matching_word_pairs.keys.join("")
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
127
160
 
128
- re = /(^|\W)([#{tags}])([#:\\]?[\w.\/-]+?\S?)\2(\W|$)/
161
+ re = /(^|\W|[#{all_tags.join("")}])([#{tags.join("")}])(\2*[#\\]?[\w:.\/\[\]-]+?\S?)\2(?!\2)([#{all_tags.join("")}]|\W|$)/
129
162
 
130
- 1 while str.gsub!(re) do
163
+ 1 while str.gsub!(re) { |orig|
131
164
  attr = @matching_word_pairs[$2]
132
- attrs.set_attrs($`.length + $1.length + $2.length, $3.length, attr)
133
- $1 + NULL * $2.length + $3 + NULL * $2.length + $4
134
- end
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
135
174
 
175
+ def convert_attrs_word_pair_map(str, attrs, exclusive)
136
176
  # then non-matching
137
177
  unless @word_pair_map.empty? then
138
178
  @word_pair_map.each do |regexp, attr|
139
- str.gsub!(regexp) {
140
- attrs.set_attrs($`.length + $1.length, $2.length, attr)
141
- NULL * $1.length + $2 + NULL * $3.length
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
142
191
  }
143
192
  end
144
193
  end
@@ -147,10 +196,18 @@ class RDoc::Markup::AttributeManager
147
196
  ##
148
197
  # Converts HTML tags to RDoc attributes
149
198
 
150
- def convert_html(str, attrs)
151
- tags = @html_tags.keys.join '|'
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 '|'
152
209
 
153
- 1 while str.gsub!(/<(#{tags})>(.*?)<\/\1>/i) {
210
+ 1 while str.gsub!(/<(#{tags})>(.*?)<\/\1>/i) { |orig|
154
211
  attr = @html_tags[$1.downcase]
155
212
  html_length = $1.length + 2
156
213
  seq = NULL * html_length
@@ -160,32 +217,39 @@ class RDoc::Markup::AttributeManager
160
217
  end
161
218
 
162
219
  ##
163
- # Converts special sequences to RDoc attributes
164
-
165
- def convert_specials(str, attrs)
166
- unless @special.empty?
167
- @special.each do |regexp, attr|
168
- str.scan(regexp) do
169
- attrs.set_attrs($`.length, $&.length,
170
- attr | RDoc::Markup::Attribute::SPECIAL)
171
- end
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
172
235
  end
173
236
  end
174
237
  end
175
238
 
176
239
  ##
177
- # Escapes special sequences of text to prevent conversion to RDoc
240
+ # Escapes regexp handling sequences of text to prevent conversion to RDoc
178
241
 
179
242
  def mask_protected_sequences
180
243
  # protect __send__, __FILE__, etc.
181
244
  @str.gsub!(/__([a-z]+)__/i,
182
245
  "_#{PROTECT_ATTR}_#{PROTECT_ATTR}\\1_#{PROTECT_ATTR}_#{PROTECT_ATTR}")
183
- @str.gsub!(/\\([#{Regexp.escape @protectable.join('')}])/,
184
- "\\1#{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")
185
249
  end
186
250
 
187
251
  ##
188
- # Unescapes special sequences of text
252
+ # Unescapes regexp handling sequences of text
189
253
 
190
254
  def unmask_protected_sequences
191
255
  @str.gsub!(/(.)#{PROTECT_ATTR}/, "\\1\000")
@@ -197,11 +261,11 @@ class RDoc::Markup::AttributeManager
197
261
  #
198
262
  # am.add_word_pair '*', '*', :BOLD
199
263
 
200
- def add_word_pair(start, stop, name)
264
+ def add_word_pair(start, stop, name, exclusive = false)
201
265
  raise ArgumentError, "Word flags may not start with '<'" if
202
266
  start[0,1] == '<'
203
267
 
204
- bitmap = RDoc::Markup::Attribute.bitmap_for name
268
+ bitmap = @attributes.bitmap_for name
205
269
 
206
270
  if start == stop then
207
271
  @matching_word_pairs[start] = bitmap
@@ -212,6 +276,8 @@ class RDoc::Markup::AttributeManager
212
276
 
213
277
  @protectable << start[0,1]
214
278
  @protectable.uniq!
279
+
280
+ @exclusive_bitmap |= bitmap if exclusive
215
281
  end
216
282
 
217
283
  ##
@@ -220,33 +286,40 @@ class RDoc::Markup::AttributeManager
220
286
  #
221
287
  # am.add_html 'em', :EM
222
288
 
223
- def add_html(tag, name)
224
- @html_tags[tag.downcase] = RDoc::Markup::Attribute.bitmap_for name
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
225
293
  end
226
294
 
227
295
  ##
228
- # Adds a special handler for +pattern+ with +name+. A simple URL handler
296
+ # Adds a regexp handling for +pattern+ with +name+. A simple URL handler
229
297
  # would be:
230
298
  #
231
- # @am.add_special(/((https?:)\S+\w)/, :HYPERLINK)
299
+ # @am.add_regexp_handling(/((https?:)\S+\w)/, :HYPERLINK)
232
300
 
233
- def add_special(pattern, name)
234
- @special[pattern] = RDoc::Markup::Attribute.bitmap_for name
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
235
305
  end
236
306
 
237
307
  ##
238
- # Processes +str+ converting attributes, HTML and specials
308
+ # Processes +str+ converting attributes, HTML and regexp handlings
239
309
 
240
- def flow(str)
241
- @str = str
310
+ def flow str
311
+ @str = str.dup
242
312
 
243
313
  mask_protected_sequences
244
314
 
245
- @attrs = RDoc::Markup::AttrSpan.new @str.length
315
+ @attrs = RDoc::Markup::AttrSpan.new @str.length, @exclusive_bitmap
246
316
 
247
- convert_attrs @str, @attrs
248
- convert_html @str, @attrs
249
- convert_specials @str, @attrs
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
250
323
 
251
324
  unmask_protected_sequences
252
325
 
@@ -304,12 +377,12 @@ class RDoc::Markup::AttributeManager
304
377
  res << change_attribute(current_attr, new_attr)
305
378
  current_attr = new_attr
306
379
 
307
- if (current_attr & RDoc::Markup::Attribute::SPECIAL) != 0 then
380
+ if (current_attr & @attributes.regexp_handling) != 0 then
308
381
  i += 1 while
309
- i < str_len and (@attrs[i] & RDoc::Markup::Attribute::SPECIAL) != 0
382
+ i < str_len and (@attrs[i] & @attributes.regexp_handling) != 0
310
383
 
311
- res << RDoc::Markup::Special.new(current_attr,
312
- copy_string(start_pos, i))
384
+ res << RDoc::Markup::RegexpHandling.new(current_attr,
385
+ copy_string(start_pos, i))
313
386
  start_pos = i
314
387
  next
315
388
  end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+ ##
3
+ # We manage a set of attributes. Each attribute has a symbol name and a bit
4
+ # value.
5
+
6
+ class RDoc::Markup::Attributes
7
+
8
+ ##
9
+ # The regexp handling attribute type. See RDoc::Markup#add_regexp_handling
10
+
11
+ attr_reader :regexp_handling
12
+
13
+ ##
14
+ # Creates a new attributes set.
15
+
16
+ def initialize
17
+ @regexp_handling = 1
18
+
19
+ @name_to_bitmap = [
20
+ [:_REGEXP_HANDLING_, @regexp_handling],
21
+ ]
22
+
23
+ @next_bitmap = @regexp_handling << 1
24
+ end
25
+
26
+ ##
27
+ # Returns a unique bit for +name+
28
+
29
+ def bitmap_for name
30
+ bitmap = @name_to_bitmap.assoc name
31
+
32
+ unless bitmap then
33
+ bitmap = @next_bitmap
34
+ @next_bitmap <<= 1
35
+ @name_to_bitmap << [name, bitmap]
36
+ else
37
+ bitmap = bitmap.last
38
+ end
39
+
40
+ bitmap
41
+ end
42
+
43
+ ##
44
+ # Returns a string representation of +bitmap+
45
+
46
+ def as_string bitmap
47
+ return 'none' if bitmap.zero?
48
+ res = []
49
+
50
+ @name_to_bitmap.each do |name, bit|
51
+ res << name if (bitmap & bit) != 0
52
+ end
53
+
54
+ res.join ','
55
+ end
56
+
57
+ ##
58
+ # yields each attribute name in +bitmap+
59
+
60
+ def each_name_of bitmap
61
+ return enum_for __method__, bitmap unless block_given?
62
+
63
+ @name_to_bitmap.each do |name, bit|
64
+ next if bit == @regexp_handling
65
+
66
+ yield name.to_s if (bitmap & bit) != 0
67
+ end
68
+ end
69
+
70
+ end
71
+
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  ##
2
3
  # An empty line. This class is a singleton.
3
4
 
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+ ##
3
+ # A quoted section which contains markup items.
4
+
5
+ class RDoc::Markup::BlockQuote < RDoc::Markup::Raw
6
+
7
+ ##
8
+ # Calls #accept_block_quote on +visitor+
9
+
10
+ def accept visitor
11
+ visitor.accept_block_quote self
12
+ end
13
+
14
+ end
15
+
@@ -1,8 +1,23 @@
1
+ # frozen_string_literal: true
1
2
  ##
2
3
  # A Document containing lists, headings, paragraphs, etc.
3
4
 
4
5
  class RDoc::Markup::Document
5
6
 
7
+ include Enumerable
8
+
9
+ ##
10
+ # The file this document was created from. See also
11
+ # RDoc::ClassModule#add_comment
12
+
13
+ attr_reader :file
14
+
15
+ ##
16
+ # If a heading is below the given level it will be omitted from the
17
+ # table_of_contents
18
+
19
+ attr_accessor :omit_headings_below
20
+
6
21
  ##
7
22
  # The parts of the Document
8
23
 
@@ -13,7 +28,10 @@ class RDoc::Markup::Document
13
28
 
14
29
  def initialize *parts
15
30
  @parts = []
16
- @parts.push(*parts)
31
+ @parts.concat parts
32
+
33
+ @file = nil
34
+ @omit_headings_from_table_of_contents_below = nil
17
35
  end
18
36
 
19
37
  ##
@@ -23,7 +41,7 @@ class RDoc::Markup::Document
23
41
  case part
24
42
  when RDoc::Markup::Document then
25
43
  unless part.empty? then
26
- parts.push(*part.parts)
44
+ parts.concat part.parts
27
45
  parts << RDoc::Markup::BlankLine.new
28
46
  end
29
47
  when String then
@@ -36,7 +54,9 @@ class RDoc::Markup::Document
36
54
  end
37
55
 
38
56
  def == other # :nodoc:
39
- self.class == other.class and @parts == other.parts
57
+ self.class == other.class and
58
+ @file == other.file and
59
+ @parts == other.parts
40
60
  end
41
61
 
42
62
  ##
@@ -45,22 +65,80 @@ class RDoc::Markup::Document
45
65
  def accept visitor
46
66
  visitor.start_accepting
47
67
 
48
- @parts.each do |item|
49
- item.accept visitor
50
- end
68
+ visitor.accept_document self
51
69
 
52
70
  visitor.end_accepting
53
71
  end
54
72
 
73
+ ##
74
+ # Concatenates the given +parts+ onto the document
75
+
76
+ def concat parts
77
+ self.parts.concat parts
78
+ end
79
+
80
+ ##
81
+ # Enumerator for the parts of this document
82
+
83
+ def each &block
84
+ @parts.each(&block)
85
+ end
86
+
55
87
  ##
56
88
  # Does this document have no parts?
57
89
 
58
90
  def empty?
59
- @parts.empty?
91
+ @parts.empty? or (@parts.length == 1 and merged? and @parts.first.empty?)
92
+ end
93
+
94
+ ##
95
+ # The file this Document was created from.
96
+
97
+ def file= location
98
+ @file = case location
99
+ when RDoc::TopLevel then
100
+ location.relative_name
101
+ else
102
+ location
103
+ end
104
+ end
105
+
106
+ ##
107
+ # When this is a collection of documents (#file is not set and this document
108
+ # contains only other documents as its direct children) #merge replaces
109
+ # documents in this class with documents from +other+ when the file matches
110
+ # and adds documents from +other+ when the files do not.
111
+ #
112
+ # The information in +other+ is preferred over the receiver
113
+
114
+ def merge other
115
+ if empty? then
116
+ @parts = other.parts
117
+ return self
118
+ end
119
+
120
+ other.parts.each do |other_part|
121
+ self.parts.delete_if do |self_part|
122
+ self_part.file and self_part.file == other_part.file
123
+ end
124
+
125
+ self.parts << other_part
126
+ end
127
+
128
+ self
129
+ end
130
+
131
+ ##
132
+ # Does this Document contain other Documents?
133
+
134
+ def merged?
135
+ RDoc::Markup::Document === @parts.first
60
136
  end
61
137
 
62
138
  def pretty_print q # :nodoc:
63
- q.group 2, '[doc: ', ']' do
139
+ start = @file ? "[doc (#{@file}): " : '[doc: '
140
+
141
+ q.group 2, start, ']' do
64
142
  q.seplist @parts do |part|
65
143
  q.pp part
66
144
  end
@@ -71,7 +149,16 @@ class RDoc::Markup::Document
71
149
  # Appends +parts+ to the document
72
150
 
73
151
  def push *parts
74
- self.parts.push(*parts)
152
+ self.parts.concat parts
153
+ end
154
+
155
+ ##
156
+ # Returns an Array of headings in the document.
157
+ #
158
+ # Require 'rdoc/markup/formatter' before calling this method.
159
+
160
+ def table_of_contents
161
+ accept RDoc::Markup::ToTableOfContents.to_toc
75
162
  end
76
163
 
77
164
  end