rdoc 6.17.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 (169) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +193 -0
  3. data/LEGAL.rdoc +6 -0
  4. data/LICENSE.rdoc +4 -0
  5. data/README.md +132 -8
  6. data/RI.md +75 -75
  7. data/doc/markup_reference/markdown.md +659 -0
  8. data/doc/markup_reference/rdoc.rdoc +1169 -0
  9. data/exe/rdoc +2 -2
  10. data/lib/rdoc/code_object/alias.rb +70 -74
  11. data/lib/rdoc/code_object/any_method.rb +308 -293
  12. data/lib/rdoc/code_object/attr.rb +150 -142
  13. data/lib/rdoc/code_object/class_module.rb +802 -715
  14. data/lib/rdoc/code_object/constant.rb +181 -144
  15. data/lib/rdoc/code_object/context/section.rb +140 -130
  16. data/lib/rdoc/code_object/context.rb +925 -941
  17. data/lib/rdoc/code_object/extend.rb +7 -5
  18. data/lib/rdoc/code_object/include.rb +7 -5
  19. data/lib/rdoc/code_object/method_attr.rb +328 -315
  20. data/lib/rdoc/code_object/mixin.rb +97 -92
  21. data/lib/rdoc/code_object/normal_class.rb +77 -78
  22. data/lib/rdoc/code_object/normal_module.rb +61 -59
  23. data/lib/rdoc/code_object/require.rb +23 -39
  24. data/lib/rdoc/code_object/single_class.rb +21 -19
  25. data/lib/rdoc/code_object/top_level.rb +215 -202
  26. data/lib/rdoc/code_object.rb +305 -305
  27. data/lib/rdoc/comment.rb +274 -337
  28. data/lib/rdoc/cross_reference.rb +195 -206
  29. data/lib/rdoc/encoding.rb +105 -103
  30. data/lib/rdoc/erb_partial.rb +13 -11
  31. data/lib/rdoc/erbio.rb +29 -27
  32. data/lib/rdoc/generator/aliki.rb +196 -30
  33. data/lib/rdoc/generator/darkfish.rb +647 -629
  34. data/lib/rdoc/generator/json_index.rb +233 -229
  35. data/lib/rdoc/generator/markup.rb +165 -122
  36. data/lib/rdoc/generator/pot/message_extractor.rb +57 -51
  37. data/lib/rdoc/generator/pot/po.rb +52 -51
  38. data/lib/rdoc/generator/pot/po_entry.rb +138 -132
  39. data/lib/rdoc/generator/pot.rb +85 -81
  40. data/lib/rdoc/generator/ri.rb +23 -19
  41. data/lib/rdoc/generator/template/aliki/DESIGN.md +538 -0
  42. data/lib/rdoc/generator/template/aliki/_aside_toc.rhtml +1 -1
  43. data/lib/rdoc/generator/template/aliki/_footer.rhtml +2 -2
  44. data/lib/rdoc/generator/template/aliki/_head.rhtml +15 -10
  45. data/lib/rdoc/generator/template/aliki/_header.rhtml +29 -44
  46. data/lib/rdoc/generator/template/aliki/_sidebar_extends.rhtml +8 -6
  47. data/lib/rdoc/generator/template/aliki/_sidebar_includes.rhtml +8 -6
  48. data/lib/rdoc/generator/template/aliki/_sidebar_installed.rhtml +1 -1
  49. data/lib/rdoc/generator/template/aliki/_sidebar_pages.rhtml +3 -3
  50. data/lib/rdoc/generator/template/aliki/_sidebar_search.rhtml +3 -3
  51. data/lib/rdoc/generator/template/aliki/_sidebar_sections.rhtml +1 -1
  52. data/lib/rdoc/generator/template/aliki/_sidebar_toggle.rhtml +1 -1
  53. data/lib/rdoc/generator/template/aliki/class.rhtml +71 -61
  54. data/lib/rdoc/generator/template/aliki/css/rdoc.css +796 -323
  55. data/lib/rdoc/generator/template/aliki/index.rhtml +1 -1
  56. data/lib/rdoc/generator/template/aliki/js/aliki.js +119 -113
  57. data/lib/rdoc/generator/template/aliki/js/bash_highlighter.js +167 -0
  58. data/lib/rdoc/generator/template/aliki/js/c_highlighter.js +1 -1
  59. data/lib/rdoc/generator/template/aliki/js/{search.js → search_controller.js} +16 -7
  60. data/lib/rdoc/generator/template/aliki/js/search_navigation.js +105 -0
  61. data/lib/rdoc/generator/template/aliki/js/search_ranker.js +239 -0
  62. data/lib/rdoc/generator/template/aliki/page.rhtml +1 -1
  63. data/lib/rdoc/generator/template/aliki/servlet_not_found.rhtml +1 -1
  64. data/lib/rdoc/generator/template/aliki/servlet_root.rhtml +2 -2
  65. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +1 -1
  66. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +8 -6
  67. data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +8 -6
  68. data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +1 -1
  69. data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +2 -2
  70. data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +1 -1
  71. data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +5 -5
  72. data/lib/rdoc/generator/template/darkfish/class.rhtml +29 -32
  73. data/lib/rdoc/generator/template/darkfish/css/rdoc.css +19 -1
  74. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +3 -3
  75. data/lib/rdoc/generator.rb +48 -46
  76. data/lib/rdoc/i18n/locale.rb +99 -95
  77. data/lib/rdoc/i18n/text.rb +109 -105
  78. data/lib/rdoc/i18n.rb +7 -5
  79. data/lib/rdoc/markdown/byte_runtime.rb +80 -0
  80. data/lib/rdoc/markdown.kpeg +52 -33
  81. data/lib/rdoc/markdown.rb +365 -177
  82. data/lib/rdoc/markup/blank_line.rb +25 -23
  83. data/lib/rdoc/markup/block_quote.rb +12 -8
  84. data/lib/rdoc/markup/document.rb +127 -123
  85. data/lib/rdoc/markup/element.rb +21 -0
  86. data/lib/rdoc/markup/formatter.rb +220 -203
  87. data/lib/rdoc/markup/hard_break.rb +30 -27
  88. data/lib/rdoc/markup/heading.rb +163 -77
  89. data/lib/rdoc/markup/include.rb +33 -29
  90. data/lib/rdoc/markup/indented_paragraph.rb +37 -33
  91. data/lib/rdoc/markup/inline_parser.rb +316 -0
  92. data/lib/rdoc/markup/list.rb +80 -88
  93. data/lib/rdoc/markup/list_item.rb +73 -85
  94. data/lib/rdoc/markup/paragraph.rb +23 -19
  95. data/lib/rdoc/markup/parser.rb +501 -497
  96. data/lib/rdoc/markup/pre_process.rb +284 -305
  97. data/lib/rdoc/markup/raw.rb +52 -55
  98. data/lib/rdoc/markup/rule.rb +16 -12
  99. data/lib/rdoc/markup/table.rb +48 -40
  100. data/lib/rdoc/markup/to_ansi.rb +143 -92
  101. data/lib/rdoc/markup/to_bs.rb +86 -102
  102. data/lib/rdoc/markup/to_html.rb +608 -506
  103. data/lib/rdoc/markup/to_html_crossref.rb +219 -210
  104. data/lib/rdoc/markup/to_html_snippet.rb +210 -205
  105. data/lib/rdoc/markup/to_joined_paragraph.rb +40 -41
  106. data/lib/rdoc/markup/to_label.rb +64 -51
  107. data/lib/rdoc/markup/to_markdown.rb +212 -184
  108. data/lib/rdoc/markup/to_rdoc.rb +341 -277
  109. data/lib/rdoc/markup/to_table_of_contents.rb +66 -62
  110. data/lib/rdoc/markup/to_test.rb +62 -50
  111. data/lib/rdoc/markup/to_tt_only.rb +83 -92
  112. data/lib/rdoc/markup/verbatim.rb +62 -58
  113. data/lib/rdoc/markup.rb +196 -215
  114. data/lib/rdoc/options.rb +1063 -1076
  115. data/lib/rdoc/parser/c.rb +1039 -1036
  116. data/lib/rdoc/parser/changelog.rb +320 -287
  117. data/lib/rdoc/parser/markdown.rb +17 -13
  118. data/lib/rdoc/parser/rbs.rb +279 -0
  119. data/lib/rdoc/parser/rd.rb +17 -13
  120. data/lib/rdoc/parser/ruby.rb +1231 -2222
  121. data/lib/rdoc/parser/ruby_colorizer.rb +303 -0
  122. data/lib/rdoc/parser/simple.rb +31 -27
  123. data/lib/rdoc/parser/text.rb +12 -8
  124. data/lib/rdoc/parser.rb +230 -221
  125. data/lib/rdoc/rbs_helper.rb +186 -0
  126. data/lib/rdoc/rd/inline.rb +57 -53
  127. data/lib/rdoc/rd.rb +90 -88
  128. data/lib/rdoc/rdoc.rb +547 -366
  129. data/lib/rdoc/ri/driver.rb +1141 -1130
  130. data/lib/rdoc/ri/formatter.rb +7 -3
  131. data/lib/rdoc/ri/paths.rb +140 -136
  132. data/lib/rdoc/ri/servlet.rb +456 -0
  133. data/lib/rdoc/ri/store.rb +4 -2
  134. data/lib/rdoc/ri/task.rb +55 -51
  135. data/lib/rdoc/ri.rb +14 -11
  136. data/lib/rdoc/rubygems_hook.rb +194 -192
  137. data/lib/rdoc/server.rb +462 -0
  138. data/lib/rdoc/stats/normal.rb +46 -42
  139. data/lib/rdoc/stats/quiet.rb +39 -35
  140. data/lib/rdoc/stats/verbose.rb +35 -31
  141. data/lib/rdoc/stats.rb +363 -338
  142. data/lib/rdoc/store.rb +919 -725
  143. data/lib/rdoc/task.rb +260 -255
  144. data/lib/rdoc/text.rb +164 -240
  145. data/lib/rdoc/token_stream.rb +88 -106
  146. data/lib/rdoc/tom_doc.rb +203 -201
  147. data/lib/rdoc/version.rb +1 -1
  148. data/lib/rdoc.rb +35 -7
  149. data/lib/rubygems_plugin.rb +2 -11
  150. data/rdoc-logo.svg +43 -0
  151. data/rdoc.gemspec +9 -7
  152. metadata +46 -32
  153. data/CONTRIBUTING.rdoc +0 -219
  154. data/ExampleMarkdown.md +0 -39
  155. data/ExampleRDoc.rdoc +0 -210
  156. data/lib/rdoc/code_object/anon_class.rb +0 -10
  157. data/lib/rdoc/code_object/ghost_method.rb +0 -6
  158. data/lib/rdoc/code_object/meta_method.rb +0 -6
  159. data/lib/rdoc/markdown/literals.kpeg +0 -21
  160. data/lib/rdoc/markdown/literals.rb +0 -454
  161. data/lib/rdoc/markup/attr_changer.rb +0 -22
  162. data/lib/rdoc/markup/attr_span.rb +0 -35
  163. data/lib/rdoc/markup/attribute_manager.rb +0 -405
  164. data/lib/rdoc/markup/attributes.rb +0 -70
  165. data/lib/rdoc/markup/regexp_handling.rb +0 -40
  166. data/lib/rdoc/parser/prism_ruby.rb +0 -1100
  167. data/lib/rdoc/parser/ripper_state_lex.rb +0 -302
  168. data/lib/rdoc/parser/ruby_tools.rb +0 -163
  169. 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
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
110
115
 
111
- text = truncate input
112
- text << ' ...' unless text == input
116
+ super Markup::Verbatim.new text
113
117
 
114
- super RDoc::Markup::Verbatim.new text
118
+ add_paragraph
119
+ end
115
120
 
116
- add_paragraph
117
- end
121
+ ##
122
+ # Prepares the visitor for HTML snippet generation
118
123
 
119
- ##
120
- # Prepares the visitor for HTML snippet generation
124
+ def start_accepting
125
+ super
121
126
 
122
- def start_accepting
123
- super
127
+ @characters = 0
128
+ end
124
129
 
125
- @characters = 0
126
- end
130
+ ##
131
+ # Removes escaping from the cross-references in +target+ and escapes HTML
132
+ # characters, since snippets don't link cross-references.
127
133
 
128
- ##
129
- # Removes escaping from the cross-references in +target+
134
+ def handle_regexp_CROSSREF(text)
135
+ convert_string(text.delete_prefix('\\'))
136
+ end
130
137
 
131
- def handle_regexp_CROSSREF(target)
132
- target.text.sub(/\A\\/, '')
133
- end
138
+ ##
139
+ # Lists are paragraphs, but notes and labels have a separator
134
140
 
135
- ##
136
- # +target+ is a <code><br></code>
141
+ def list_item_start(list_item, list_type)
142
+ throw :done if @characters >= @character_limit
137
143
 
138
- def handle_regexp_HARD_BREAK(target)
139
- @characters -= 4
140
- '<br>'
141
- end
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 ', '
142
151
 
143
- ##
144
- # Lists are paragraphs, but notes and labels have a separator
152
+ labels << " &mdash; " unless labels.empty?
145
153
 
146
- def list_item_start(list_item, list_type)
147
- throw :done if @characters >= @character_limit
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
148
161
 
149
- case list_type
150
- when :BULLET, :LALPHA, :NUMBER, :UALPHA then
151
- "<p>"
152
- when :LABEL, :NOTE then
153
- labels = Array(list_item.label).map do |label|
154
- to_html label
155
- end.join ', '
162
+ ##
163
+ # Returns just the text of +link+, +url+ is only used to determine the link
164
+ # type.
165
+
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
156
182
 
157
- labels << " &mdash; " unless labels.empty?
183
+ ##
184
+ # In snippets, there are no lists
158
185
 
159
- start = "<p>#{labels}"
160
- @characters += 1 # try to include the label
161
- start
162
- else
163
- raise RDoc::Error, "Invalid list type: #{list_type.inspect}"
164
- end
165
- end
186
+ def html_list_name(list_type, open_tag)
187
+ ''
188
+ end
166
189
 
167
- ##
168
- # Returns just the text of +link+, +url+ is only used to determine the link
169
- # type.
170
-
171
- def gen_url(url, text)
172
- if url =~ /^rdoc-label:([^:]*)(?::(.*))?/ then
173
- type = "link"
174
- elsif url =~ /([A-Za-z]+):(.*)/ then
175
- type = $1
176
- else
177
- type = "http"
178
- end
190
+ ##
191
+ # Throws +:done+ when paragraph_limit paragraphs have been encountered
179
192
 
180
- if (type == "http" or type == "https" or type == "link") and
181
- url =~ /\.(gif|png|jpg|jpeg|bmp)$/ then
182
- ''
183
- else
184
- text.sub(%r%^#{type}:/*%, '')
185
- end
186
- end
193
+ def add_paragraph
194
+ @paragraphs += 1
187
195
 
188
- ##
189
- # In snippets, there are no lists
196
+ throw :done if @paragraphs >= @paragraph_limit
197
+ end
190
198
 
191
- def html_list_name(list_type, open_tag)
192
- ''
193
- end
199
+ ##
200
+ # Marks up +content+
194
201
 
195
- ##
196
- # Throws +:done+ when paragraph_limit paragraphs have been encountered
202
+ def convert(content)
203
+ catch :done do
204
+ return super
205
+ end
197
206
 
198
- def add_paragraph
199
- @paragraphs += 1
207
+ end_accepting
208
+ end
200
209
 
201
- throw :done if @paragraphs >= @paragraph_limit
202
- end
210
+ def handle_PLAIN_TEXT(text) # :nodoc:
211
+ return if inline_limit_reached?
203
212
 
204
- ##
205
- # Marks up +content+
213
+ truncated = truncate(text, @inline_character_limit)
214
+ @inline_character_limit -= text.size
215
+ emit_inline(convert_string(truncated))
216
+ end
206
217
 
207
- def convert(content)
208
- catch :done do
209
- return super
210
- end
218
+ def handle_REGEXP_HANDLING_TEXT(text) # :nodoc:
219
+ return if inline_limit_reached?
211
220
 
212
- end_accepting
213
- end
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
214
226
 
215
- ##
216
- # Converts flow items +flow+
217
-
218
- def convert_flow(flow)
219
- throw :done if @characters >= @character_limit
220
-
221
- res = []
222
- @mask = 0
223
-
224
- flow.each do |item|
225
- case item
226
- when RDoc::Markup::AttrChanger then
227
- off_tags res, item
228
- on_tags res, item
229
- when String then
230
- text = convert_string item
231
- res << truncate(text)
232
- when RDoc::Markup::RegexpHandling then
233
- text = convert_regexp_handling item
234
- res << truncate(text)
235
- else
236
- raise "Unknown flow element: #{item.inspect}"
227
+ def handle_BOLD(nodes)
228
+ super unless inline_limit_reached?
237
229
  end
238
230
 
239
- if @characters >= @character_limit then
240
- off_tags res, RDoc::Markup::AttrChanger.new(0, @mask)
241
- break
231
+ def handle_BOLD_WORD(word)
232
+ super unless inline_limit_reached?
242
233
  end
243
- end
244
234
 
245
- res << ' ...' if @characters >= @character_limit
235
+ def handle_EM(nodes)
236
+ super unless inline_limit_reached?
237
+ end
246
238
 
247
- res.join
248
- end
239
+ def handle_EM_WORD(word)
240
+ super unless inline_limit_reached?
241
+ end
249
242
 
250
- ##
251
- # Maintains a bitmask to allow HTML elements to be closed properly. See
252
- # RDoc::Markup::Formatter.
243
+ def handle_TT(code)
244
+ super unless inline_limit_reached?
245
+ end
253
246
 
254
- def on_tags(res, item)
255
- @mask ^= item.turn_on
247
+ def handle_STRIKE(nodes)
248
+ super unless inline_limit_reached?
249
+ end
256
250
 
257
- super
258
- end
251
+ def handle_HARD_BREAK
252
+ super unless inline_limit_reached?
253
+ end
259
254
 
260
- ##
261
- # Maintains a bitmask to allow HTML elements to be closed properly. See
262
- # RDoc::Markup::Formatter.
255
+ def handle_TIDYLINK(label_part, url)
256
+ traverse_inline_nodes(label_part) unless inline_limit_reached?
257
+ end
263
258
 
264
- def off_tags(res, item)
265
- @mask ^= item.turn_off
259
+ def inline_limit_reached?
260
+ @inline_character_limit <= 0
261
+ end
266
262
 
267
- super
268
- end
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
269
272
 
270
- ##
271
- # Truncates +text+ at the end of the first word after the character_limit.
273
+ def to_html(item)
274
+ throw :done if @characters >= @character_limit
275
+ handle_inline(item)
276
+ end
272
277
 
273
- def truncate(text)
274
- length = text.length
275
- characters = @characters
276
- @characters += length
278
+ ##
279
+ # Truncates +text+ at the end of the first word after the limit.
277
280
 
278
- return text if @characters < @character_limit
281
+ def truncate(text, limit)
282
+ return text if limit >= text.size
283
+ return '' if limit <= 0
279
284
 
280
- remaining = @character_limit - characters
285
+ text =~ /\A(.{#{limit},}?)(\s|$)/m # TODO word-break instead of \s?
281
286
 
282
- text =~ /\A(.{#{remaining},}?)(\s|$)/m # TODO word-break instead of \s?
287
+ $1
288
+ end
283
289
 
284
- $1
290
+ end
285
291
  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