rdoc 7.2.0 → 8.1.0

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 (150) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +4 -7
  3. data/LICENSE.rdoc +4 -0
  4. data/README.md +43 -2
  5. data/RI.md +75 -75
  6. data/doc/markup_reference/markdown.md +104 -3
  7. data/exe/rdoc +2 -2
  8. data/lib/rdoc/code_object/alias.rb +70 -74
  9. data/lib/rdoc/code_object/any_method.rb +305 -298
  10. data/lib/rdoc/code_object/attr.rb +150 -143
  11. data/lib/rdoc/code_object/class_module.rb +801 -765
  12. data/lib/rdoc/code_object/constant.rb +178 -150
  13. data/lib/rdoc/code_object/context/section.rb +133 -160
  14. data/lib/rdoc/code_object/context.rb +925 -952
  15. data/lib/rdoc/code_object/extend.rb +7 -5
  16. data/lib/rdoc/code_object/include.rb +7 -5
  17. data/lib/rdoc/code_object/method_attr.rb +325 -324
  18. data/lib/rdoc/code_object/mixin.rb +97 -95
  19. data/lib/rdoc/code_object/normal_class.rb +77 -78
  20. data/lib/rdoc/code_object/normal_module.rb +61 -59
  21. data/lib/rdoc/code_object/require.rb +23 -39
  22. data/lib/rdoc/code_object/single_class.rb +21 -19
  23. data/lib/rdoc/code_object/top_level.rb +212 -213
  24. data/lib/rdoc/code_object.rb +305 -305
  25. data/lib/rdoc/comment.rb +274 -337
  26. data/lib/rdoc/cross_reference.rb +194 -212
  27. data/lib/rdoc/encoding.rb +105 -103
  28. data/lib/rdoc/erb_partial.rb +13 -11
  29. data/lib/rdoc/erbio.rb +29 -27
  30. data/lib/rdoc/generator/aliki.rb +165 -140
  31. data/lib/rdoc/generator/darkfish.rb +647 -631
  32. data/lib/rdoc/generator/json_index.rb +233 -229
  33. data/lib/rdoc/generator/markup.rb +165 -122
  34. data/lib/rdoc/generator/pot/message_extractor.rb +57 -51
  35. data/lib/rdoc/generator/pot/po.rb +52 -51
  36. data/lib/rdoc/generator/pot/po_entry.rb +138 -132
  37. data/lib/rdoc/generator/pot.rb +85 -81
  38. data/lib/rdoc/generator/ri.rb +23 -19
  39. data/lib/rdoc/generator/template/aliki/DESIGN.md +538 -0
  40. data/lib/rdoc/generator/template/aliki/_aside_toc.rhtml +1 -1
  41. data/lib/rdoc/generator/template/aliki/_footer.rhtml +1 -1
  42. data/lib/rdoc/generator/template/aliki/_head.rhtml +11 -11
  43. data/lib/rdoc/generator/template/aliki/_header.rhtml +29 -44
  44. data/lib/rdoc/generator/template/aliki/_sidebar_extends.rhtml +8 -6
  45. data/lib/rdoc/generator/template/aliki/_sidebar_includes.rhtml +8 -6
  46. data/lib/rdoc/generator/template/aliki/_sidebar_installed.rhtml +1 -1
  47. data/lib/rdoc/generator/template/aliki/_sidebar_pages.rhtml +2 -2
  48. data/lib/rdoc/generator/template/aliki/_sidebar_search.rhtml +4 -4
  49. data/lib/rdoc/generator/template/aliki/_sidebar_sections.rhtml +1 -1
  50. data/lib/rdoc/generator/template/aliki/_sidebar_toggle.rhtml +1 -1
  51. data/lib/rdoc/generator/template/aliki/class.rhtml +56 -46
  52. data/lib/rdoc/generator/template/aliki/css/rdoc.css +538 -283
  53. data/lib/rdoc/generator/template/aliki/index.rhtml +1 -1
  54. data/lib/rdoc/generator/template/aliki/js/aliki.js +80 -102
  55. data/lib/rdoc/generator/template/aliki/page.rhtml +1 -1
  56. data/lib/rdoc/generator/template/aliki/servlet_not_found.rhtml +1 -1
  57. data/lib/rdoc/generator/template/aliki/servlet_root.rhtml +2 -2
  58. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +1 -1
  59. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +8 -6
  60. data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +8 -6
  61. data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +1 -1
  62. data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +1 -1
  63. data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +1 -1
  64. data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +5 -5
  65. data/lib/rdoc/generator/template/darkfish/class.rhtml +18 -21
  66. data/lib/rdoc/generator/template/darkfish/css/rdoc.css +0 -1
  67. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +3 -3
  68. data/lib/rdoc/generator.rb +48 -46
  69. data/lib/rdoc/i18n/locale.rb +99 -95
  70. data/lib/rdoc/i18n/text.rb +109 -105
  71. data/lib/rdoc/i18n.rb +7 -5
  72. data/lib/rdoc/markdown/byte_runtime.rb +80 -0
  73. data/lib/rdoc/markdown.kpeg +30 -21
  74. data/lib/rdoc/markdown.rb +329 -151
  75. data/lib/rdoc/markup/block_quote.rb +12 -8
  76. data/lib/rdoc/markup/document.rb +127 -123
  77. data/lib/rdoc/markup/formatter.rb +215 -221
  78. data/lib/rdoc/markup/heading.rb +1 -4
  79. data/lib/rdoc/markup/include.rb +33 -29
  80. data/lib/rdoc/markup/indented_paragraph.rb +37 -33
  81. data/lib/rdoc/markup/inline_parser.rb +281 -277
  82. data/lib/rdoc/markup/list.rb +80 -88
  83. data/lib/rdoc/markup/list_item.rb +73 -85
  84. data/lib/rdoc/markup/paragraph.rb +23 -19
  85. data/lib/rdoc/markup/parser.rb +501 -497
  86. data/lib/rdoc/markup/pre_process.rb +284 -305
  87. data/lib/rdoc/markup/raw.rb +2 -2
  88. data/lib/rdoc/markup/rule.rb +16 -12
  89. data/lib/rdoc/markup/to_ansi.rb +143 -139
  90. data/lib/rdoc/markup/to_bs.rb +72 -68
  91. data/lib/rdoc/markup/to_html.rb +600 -493
  92. data/lib/rdoc/markup/to_html_crossref.rb +221 -191
  93. data/lib/rdoc/markup/to_html_snippet.rb +232 -227
  94. data/lib/rdoc/markup/to_joined_paragraph.rb +40 -41
  95. data/lib/rdoc/markup/to_label.rb +63 -59
  96. data/lib/rdoc/markup/to_markdown.rb +212 -208
  97. data/lib/rdoc/markup/to_rdoc.rb +336 -332
  98. data/lib/rdoc/markup/to_table_of_contents.rb +66 -62
  99. data/lib/rdoc/markup/to_test.rb +60 -56
  100. data/lib/rdoc/markup/to_tt_only.rb +83 -86
  101. data/lib/rdoc/markup/verbatim.rb +62 -58
  102. data/lib/rdoc/markup.rb +198 -196
  103. data/lib/rdoc/options.rb +1063 -1076
  104. data/lib/rdoc/parser/c.rb +1039 -1036
  105. data/lib/rdoc/parser/changelog.rb +319 -315
  106. data/lib/rdoc/parser/markdown.rb +17 -13
  107. data/lib/rdoc/parser/rbs.rb +279 -0
  108. data/lib/rdoc/parser/rd.rb +17 -13
  109. data/lib/rdoc/parser/ruby.rb +1231 -2222
  110. data/lib/rdoc/parser/ruby_colorizer.rb +303 -0
  111. data/lib/rdoc/parser/simple.rb +31 -27
  112. data/lib/rdoc/parser/text.rb +12 -8
  113. data/lib/rdoc/parser.rb +230 -221
  114. data/lib/rdoc/rbs_helper.rb +186 -0
  115. data/lib/rdoc/rd/inline.rb +57 -53
  116. data/lib/rdoc/rd.rb +90 -88
  117. data/lib/rdoc/rdoc.rb +547 -366
  118. data/lib/rdoc/ri/driver.rb +1141 -1130
  119. data/lib/rdoc/ri/formatter.rb +7 -3
  120. data/lib/rdoc/ri/paths.rb +140 -136
  121. data/lib/rdoc/ri/servlet.rb +456 -0
  122. data/lib/rdoc/ri/store.rb +4 -2
  123. data/lib/rdoc/ri/task.rb +55 -51
  124. data/lib/rdoc/ri.rb +14 -11
  125. data/lib/rdoc/rubygems_hook.rb +194 -192
  126. data/lib/rdoc/server.rb +462 -0
  127. data/lib/rdoc/stats/normal.rb +46 -42
  128. data/lib/rdoc/stats/quiet.rb +39 -35
  129. data/lib/rdoc/stats/verbose.rb +35 -31
  130. data/lib/rdoc/stats.rb +363 -338
  131. data/lib/rdoc/store.rb +919 -725
  132. data/lib/rdoc/task.rb +260 -255
  133. data/lib/rdoc/text.rb +130 -245
  134. data/lib/rdoc/token_stream.rb +101 -115
  135. data/lib/rdoc/tom_doc.rb +203 -201
  136. data/lib/rdoc/version.rb +1 -1
  137. data/lib/rdoc.rb +35 -7
  138. data/lib/rubygems_plugin.rb +2 -11
  139. data/rdoc-logo.svg +43 -0
  140. data/rdoc.gemspec +6 -4
  141. metadata +36 -20
  142. data/lib/rdoc/code_object/anon_class.rb +0 -10
  143. data/lib/rdoc/code_object/ghost_method.rb +0 -6
  144. data/lib/rdoc/code_object/meta_method.rb +0 -6
  145. data/lib/rdoc/markdown/literals.kpeg +0 -21
  146. data/lib/rdoc/markdown/literals.rb +0 -454
  147. data/lib/rdoc/parser/prism_ruby.rb +0 -1112
  148. data/lib/rdoc/parser/ripper_state_lex.rb +0 -302
  149. data/lib/rdoc/parser/ruby_tools.rb +0 -163
  150. data/lib/rdoc/servlet.rb +0 -452
@@ -1,287 +1,292 @@
1
1
  # frozen_string_literal: true
2
- ##
3
- # Outputs RDoc markup as paragraphs with inline markup only.
2
+ module RDoc
3
+ class Markup
4
+ ##
5
+ # Outputs RDoc markup as paragraphs with inline markup only.
4
6
 
5
- class RDoc::Markup::ToHtmlSnippet < RDoc::Markup::ToHtml
7
+ class ToHtmlSnippet < Markup::ToHtml
6
8
 
7
- ##
8
- # After this many characters the input will be cut off.
9
+ ##
10
+ # After this many characters the input will be cut off.
9
11
 
10
- attr_reader :character_limit
12
+ attr_reader :character_limit
11
13
 
12
- ##
13
- # The number of characters seen so far.
14
+ ##
15
+ # The number of characters seen so far.
14
16
 
15
- attr_reader :characters # :nodoc:
17
+ attr_reader :characters # :nodoc:
16
18
 
17
- ##
18
- # The attribute bitmask
19
+ ##
20
+ # The attribute bitmask
19
21
 
20
- attr_reader :mask
22
+ attr_reader :mask
21
23
 
22
- ##
23
- # After this many paragraphs the input will be cut off.
24
+ ##
25
+ # After this many paragraphs the input will be cut off.
24
26
 
25
- attr_reader :paragraph_limit
27
+ attr_reader :paragraph_limit
26
28
 
27
- ##
28
- # Count of paragraphs found
29
+ ##
30
+ # Count of paragraphs found
29
31
 
30
- attr_reader :paragraphs
32
+ attr_reader :paragraphs
31
33
 
32
- ##
33
- # Creates a new ToHtmlSnippet formatter that will cut off the input on the
34
- # next word boundary after the given number of +characters+ or +paragraphs+
35
- # of text have been encountered.
34
+ ##
35
+ # Creates a new ToHtmlSnippet formatter that will cut off the input on the
36
+ # next word boundary after the given number of +characters+ or +paragraphs+
37
+ # of text have been encountered.
36
38
 
37
- def initialize(options, characters = 100, paragraphs = 3, markup = nil)
38
- super options, markup
39
+ def initialize(characters = 100, paragraphs = 3)
40
+ super()
39
41
 
40
- @character_limit = characters
41
- @paragraph_limit = paragraphs
42
+ @character_limit = characters
43
+ @paragraph_limit = paragraphs
42
44
 
43
- @characters = 0
44
- @mask = 0
45
- @paragraphs = 0
45
+ @characters = 0
46
+ @mask = 0
47
+ @paragraphs = 0
46
48
 
47
- @markup.add_regexp_handling RDoc::CrossReference::CROSSREF_REGEXP, :CROSSREF
48
- end
49
+ @markup.add_regexp_handling CrossReference::CROSSREF_REGEXP, :CROSSREF
50
+ end
49
51
 
50
- ##
51
- # Adds +heading+ to the output as a paragraph
52
+ ##
53
+ # Adds +heading+ to the output as a paragraph
52
54
 
53
- def accept_heading(heading)
54
- @res << "<p>#{to_html heading.text}\n"
55
+ def accept_heading(heading)
56
+ @res << "<p>#{to_html heading.text}\n"
55
57
 
56
- add_paragraph
57
- end
58
+ add_paragraph
59
+ end
58
60
 
59
- ##
60
- # Raw sections are untrusted and ignored
61
+ ##
62
+ # Raw sections are untrusted and ignored
61
63
 
62
- alias accept_raw ignore
64
+ alias accept_raw ignore
63
65
 
64
- ##
65
- # Rules are ignored
66
+ ##
67
+ # Rules are ignored
66
68
 
67
- alias accept_rule ignore
69
+ alias accept_rule ignore
68
70
 
69
- ##
70
- # Adds +paragraph+ to the output
71
+ ##
72
+ # Adds +paragraph+ to the output
71
73
 
72
- def accept_paragraph(paragraph)
73
- para = @in_list_entry.last || "<p>"
74
+ def accept_paragraph(paragraph)
75
+ para = @in_list_entry.last || "<p>"
74
76
 
75
- text = paragraph.text @hard_break
77
+ text = paragraph.text @hard_break
76
78
 
77
- @res << "#{para}#{to_html text}\n"
79
+ @res << "#{para}#{to_html text}\n"
78
80
 
79
- add_paragraph
80
- end
81
+ add_paragraph
82
+ end
81
83
 
82
- ##
83
- # Finishes consumption of +list_item+
84
+ ##
85
+ # Finishes consumption of +list_item+
84
86
 
85
- def accept_list_item_end(list_item)
86
- end
87
+ def accept_list_item_end(list_item)
88
+ end
87
89
 
88
- ##
89
- # Prepares the visitor for consuming +list_item+
90
+ ##
91
+ # Prepares the visitor for consuming +list_item+
90
92
 
91
- def accept_list_item_start(list_item)
92
- @res << list_item_start(list_item, @list.last)
93
- end
93
+ def accept_list_item_start(list_item)
94
+ @res << list_item_start(list_item, @list.last)
95
+ end
94
96
 
95
- ##
96
- # Prepares the visitor for consuming +list+
97
+ ##
98
+ # Prepares the visitor for consuming +list+
97
99
 
98
- def accept_list_start(list)
99
- @list << list.type
100
- @res << html_list_name(list.type, true)
101
- @in_list_entry.push ''
102
- end
100
+ def accept_list_start(list)
101
+ @list << list.type
102
+ @res << html_list_name(list.type, true)
103
+ @in_list_entry.push ''
104
+ end
103
105
 
104
- ##
105
- # Adds +verbatim+ to the output
106
+ ##
107
+ # Adds +verbatim+ to the output
106
108
 
107
- def accept_verbatim(verbatim)
108
- throw :done if @characters >= @character_limit
109
- input = verbatim.text.rstrip
110
- text = truncate(input, @character_limit - @characters)
111
- @characters += input.length
112
- text << ' ...' unless text == input
109
+ def accept_verbatim(verbatim)
110
+ throw :done if @characters >= @character_limit
111
+ input = verbatim.text.rstrip
112
+ text = truncate(input, @character_limit - @characters)
113
+ @characters += input.length
114
+ text << " #{TO_HTML_CHARACTERS[text.encoding][:ellipsis]}" unless text == input
113
115
 
114
- super RDoc::Markup::Verbatim.new text
116
+ super Markup::Verbatim.new text
115
117
 
116
- add_paragraph
117
- end
118
+ add_paragraph
119
+ end
118
120
 
119
- ##
120
- # Prepares the visitor for HTML snippet generation
121
+ ##
122
+ # Prepares the visitor for HTML snippet generation
121
123
 
122
- def start_accepting
123
- super
124
+ def start_accepting
125
+ super
124
126
 
125
- @characters = 0
126
- end
127
-
128
- ##
129
- # Removes escaping from the cross-references in +target+
127
+ @characters = 0
128
+ end
130
129
 
131
- def handle_regexp_CROSSREF(text)
132
- text.sub(/\A\\/, '')
133
- end
130
+ ##
131
+ # Removes escaping from the cross-references in +target+ and escapes HTML
132
+ # characters, since snippets don't link cross-references.
134
133
 
135
- ##
136
- # Lists are paragraphs, but notes and labels have a separator
134
+ def handle_regexp_CROSSREF(text)
135
+ convert_string(text.delete_prefix('\\'))
136
+ end
137
137
 
138
- def list_item_start(list_item, list_type)
139
- throw :done if @characters >= @character_limit
138
+ ##
139
+ # Lists are paragraphs, but notes and labels have a separator
140
140
 
141
- case list_type
142
- when :BULLET, :LALPHA, :NUMBER, :UALPHA then
143
- "<p>"
144
- when :LABEL, :NOTE then
145
- labels = Array(list_item.label).map do |label|
146
- to_html label
147
- end.join ', '
141
+ def list_item_start(list_item, list_type)
142
+ throw :done if @characters >= @character_limit
148
143
 
149
- labels << " &mdash; " unless labels.empty?
144
+ case list_type
145
+ when :BULLET, :LALPHA, :NUMBER, :UALPHA
146
+ "<p>"
147
+ when :LABEL, :NOTE
148
+ labels = Array(list_item.label).map do |label|
149
+ to_html label
150
+ end.join ', '
150
151
 
151
- start = "<p>#{labels}"
152
- @characters += 1 # try to include the label
153
- start
154
- else
155
- raise RDoc::Error, "Invalid list type: #{list_type.inspect}"
156
- end
157
- end
152
+ labels << " &mdash; " unless labels.empty?
158
153
 
159
- ##
160
- # Returns just the text of +link+, +url+ is only used to determine the link
161
- # type.
162
-
163
- def gen_url(url, text)
164
- if url =~ /^rdoc-label:([^:]*)(?::(.*))?/ then
165
- type = "link"
166
- elsif url =~ /([A-Za-z]+):(.*)/ then
167
- type = $1
168
- else
169
- type = "http"
170
- end
154
+ start = "<p>#{labels}"
155
+ @characters += 1 # try to include the label
156
+ start
157
+ else
158
+ raise Error, "Invalid list type: #{list_type.inspect}"
159
+ end
160
+ end
171
161
 
172
- if (type == "http" or type == "https" or type == "link") and
173
- url =~ /\.(gif|png|jpg|jpeg|bmp)$/ then
174
- ''
175
- else
176
- text.sub(%r%^#{type}:/*%, '')
177
- end
178
- end
162
+ ##
163
+ # Returns just the text of +link+, +url+ is only used to determine the link
164
+ # type.
179
165
 
180
- ##
181
- # In snippets, there are no lists
166
+ def gen_url(url, text)
167
+ if url =~ /^rdoc-label:([^:]*)(?::(.*))?/
168
+ type = "link"
169
+ elsif url =~ /([A-Za-z]+):(.*)/
170
+ type = $1
171
+ else
172
+ type = "http"
173
+ end
174
+
175
+ if (type == "http" or type == "https" or type == "link") and
176
+ url =~ /\.(gif|png|jpg|jpeg|bmp)$/
177
+ ''
178
+ else
179
+ text.sub(%r%^#{type}:/*%, '')
180
+ end
181
+ end
182
+
183
+ ##
184
+ # In snippets, there are no lists
185
+
186
+ def html_list_name(list_type, open_tag)
187
+ ''
188
+ end
189
+
190
+ ##
191
+ # Throws +:done+ when paragraph_limit paragraphs have been encountered
192
+
193
+ def add_paragraph
194
+ @paragraphs += 1
195
+
196
+ throw :done if @paragraphs >= @paragraph_limit
197
+ end
198
+
199
+ ##
200
+ # Marks up +content+
201
+
202
+ def convert(content)
203
+ catch :done do
204
+ return super
205
+ end
206
+
207
+ end_accepting
208
+ end
209
+
210
+ def handle_PLAIN_TEXT(text) # :nodoc:
211
+ return if inline_limit_reached?
212
+
213
+ truncated = truncate(text, @inline_character_limit)
214
+ @inline_character_limit -= text.size
215
+ emit_inline(convert_string(truncated))
216
+ end
217
+
218
+ def handle_REGEXP_HANDLING_TEXT(text) # :nodoc:
219
+ return if inline_limit_reached?
220
+
221
+ # We can't truncate text including html tags.
222
+ # Just emit as is, and count all characters including html tag part.
223
+ emit_inline(text)
224
+ @inline_character_limit -= text.size
225
+ end
226
+
227
+ def handle_BOLD(nodes)
228
+ super unless inline_limit_reached?
229
+ end
230
+
231
+ def handle_BOLD_WORD(word)
232
+ super unless inline_limit_reached?
233
+ end
234
+
235
+ def handle_EM(nodes)
236
+ super unless inline_limit_reached?
237
+ end
238
+
239
+ def handle_EM_WORD(word)
240
+ super unless inline_limit_reached?
241
+ end
242
+
243
+ def handle_TT(code)
244
+ super unless inline_limit_reached?
245
+ end
246
+
247
+ def handle_STRIKE(nodes)
248
+ super unless inline_limit_reached?
249
+ end
250
+
251
+ def handle_HARD_BREAK
252
+ super unless inline_limit_reached?
253
+ end
254
+
255
+ def handle_TIDYLINK(label_part, url)
256
+ traverse_inline_nodes(label_part) unless inline_limit_reached?
257
+ end
258
+
259
+ def inline_limit_reached?
260
+ @inline_character_limit <= 0
261
+ end
262
+
263
+ def handle_inline(text)
264
+ limit = @character_limit - @characters
265
+ return ['', 0] if limit <= 0
266
+ @inline_character_limit = limit
267
+ res = super
268
+ res << " #{TO_HTML_CHARACTERS[text.encoding][:ellipsis]}" if @inline_character_limit <= 0
269
+ @characters += limit - @inline_character_limit
270
+ res
271
+ end
182
272
 
183
- def html_list_name(list_type, open_tag)
184
- ''
185
- end
273
+ def to_html(item)
274
+ throw :done if @characters >= @character_limit
275
+ handle_inline(item)
276
+ end
186
277
 
187
- ##
188
- # Throws +:done+ when paragraph_limit paragraphs have been encountered
278
+ ##
279
+ # Truncates +text+ at the end of the first word after the limit.
189
280
 
190
- def add_paragraph
191
- @paragraphs += 1
281
+ def truncate(text, limit)
282
+ return text if limit >= text.size
283
+ return '' if limit <= 0
192
284
 
193
- throw :done if @paragraphs >= @paragraph_limit
194
- end
285
+ text =~ /\A(.{#{limit},}?)(\s|$)/m # TODO word-break instead of \s?
195
286
 
196
- ##
197
- # Marks up +content+
287
+ $1
288
+ end
198
289
 
199
- def convert(content)
200
- catch :done do
201
- return super
202
290
  end
203
-
204
- end_accepting
205
- end
206
-
207
- def handle_PLAIN_TEXT(text) # :nodoc:
208
- return if inline_limit_reached?
209
-
210
- truncated = truncate(text, @inline_character_limit)
211
- @inline_character_limit -= text.size
212
- emit_inline(convert_string(truncated))
213
- end
214
-
215
- def handle_REGEXP_HANDLING_TEXT(text) # :nodoc:
216
- return if inline_limit_reached?
217
-
218
- # We can't truncate text including html tags.
219
- # Just emit as is, and count all characters including html tag part.
220
- emit_inline(text)
221
- @inline_character_limit -= text.size
222
- end
223
-
224
- def handle_BOLD(nodes)
225
- super unless inline_limit_reached?
226
291
  end
227
-
228
- def handle_BOLD_WORD(word)
229
- super unless inline_limit_reached?
230
- end
231
-
232
- def handle_EM(nodes)
233
- super unless inline_limit_reached?
234
- end
235
-
236
- def handle_EM_WORD(word)
237
- super unless inline_limit_reached?
238
- end
239
-
240
- def handle_TT(code)
241
- super unless inline_limit_reached?
242
- end
243
-
244
- def handle_STRIKE(nodes)
245
- super unless inline_limit_reached?
246
- end
247
-
248
- def handle_HARD_BREAK
249
- super unless inline_limit_reached?
250
- end
251
-
252
- def handle_TIDYLINK(label_part, url)
253
- traverse_inline_nodes(label_part) unless inline_limit_reached?
254
- end
255
-
256
- def inline_limit_reached?
257
- @inline_character_limit <= 0
258
- end
259
-
260
- def handle_inline(text)
261
- limit = @character_limit - @characters
262
- return ['', 0] if limit <= 0
263
- @inline_character_limit = limit
264
- res = super
265
- res << ' ...' if @inline_character_limit <= 0
266
- @characters += limit - @inline_character_limit
267
- res
268
- end
269
-
270
- def to_html(item)
271
- throw :done if @characters >= @character_limit
272
- to_html_characters(handle_inline(item))
273
- end
274
-
275
- ##
276
- # Truncates +text+ at the end of the first word after the limit.
277
-
278
- def truncate(text, limit)
279
- return text if limit >= text.size
280
- return '' if limit <= 0
281
-
282
- text =~ /\A(.{#{limit},}?)(\s|$)/m # TODO word-break instead of \s?
283
-
284
- $1
285
- end
286
-
287
292
  end
@@ -1,46 +1,45 @@
1
1
  # frozen_string_literal: true
2
- ##
3
- # Joins the parts of an RDoc::Markup::Paragraph into a single String.
4
- #
5
- # This allows for easier maintenance and testing of Markdown support.
6
- #
7
- # This formatter only works on Paragraph instances. Attempting to process
8
- # other markup syntax items will not work.
2
+ module RDoc
3
+ class Markup
4
+ ##
5
+ # Joins the parts of an RDoc::Markup::Paragraph into a single String.
6
+ #
7
+ # This allows for easier maintenance and testing of Markdown support.
8
+ #
9
+ # This formatter only works on Paragraph instances. Attempting to process
10
+ # other markup syntax items will not work.
11
+
12
+ class ToJoinedParagraph < Markup::Formatter
13
+ def start_accepting # :nodoc:
14
+ end
15
+
16
+ def end_accepting # :nodoc:
17
+ end
18
+
19
+ ##
20
+ # Converts the parts of +paragraph+ to a single entry.
21
+
22
+ def accept_paragraph(paragraph)
23
+ parts = paragraph.parts.chunk do |part|
24
+ String === part
25
+ end.flat_map do |string, chunk|
26
+ string ? chunk.join.rstrip : chunk
27
+ end
28
+
29
+ paragraph.parts.replace parts
30
+ end
31
+
32
+ alias accept_block_quote ignore
33
+ alias accept_heading ignore
34
+ alias accept_list_end ignore
35
+ alias accept_list_item_end ignore
36
+ alias accept_list_item_start ignore
37
+ alias accept_list_start ignore
38
+ alias accept_raw ignore
39
+ alias accept_rule ignore
40
+ alias accept_verbatim ignore
41
+ alias accept_table ignore
9
42
 
10
- class RDoc::Markup::ToJoinedParagraph < RDoc::Markup::Formatter
11
-
12
- def initialize # :nodoc:
13
- super nil
14
- end
15
-
16
- def start_accepting # :nodoc:
17
- end
18
-
19
- def end_accepting # :nodoc:
20
- end
21
-
22
- ##
23
- # Converts the parts of +paragraph+ to a single entry.
24
-
25
- def accept_paragraph(paragraph)
26
- parts = paragraph.parts.chunk do |part|
27
- String === part
28
- end.flat_map do |string, chunk|
29
- string ? chunk.join.rstrip : chunk
30
43
  end
31
-
32
- paragraph.parts.replace parts
33
44
  end
34
-
35
- alias accept_block_quote ignore
36
- alias accept_heading ignore
37
- alias accept_list_end ignore
38
- alias accept_list_item_end ignore
39
- alias accept_list_item_start ignore
40
- alias accept_list_start ignore
41
- alias accept_raw ignore
42
- alias accept_rule ignore
43
- alias accept_verbatim ignore
44
- alias accept_table ignore
45
-
46
45
  end