rdoc 8.0.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.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +1 -3
- data/RI.md +75 -75
- data/exe/rdoc +2 -2
- data/lib/rdoc/code_object/alias.rb +71 -69
- data/lib/rdoc/code_object/any_method.rb +305 -303
- data/lib/rdoc/code_object/attr.rb +150 -148
- data/lib/rdoc/code_object/class_module.rb +798 -792
- data/lib/rdoc/code_object/constant.rb +175 -173
- data/lib/rdoc/code_object/context/section.rb +142 -138
- data/lib/rdoc/code_object/context.rb +926 -958
- data/lib/rdoc/code_object/extend.rb +7 -5
- data/lib/rdoc/code_object/include.rb +7 -5
- data/lib/rdoc/code_object/method_attr.rb +326 -319
- data/lib/rdoc/code_object/mixin.rb +97 -95
- data/lib/rdoc/code_object/normal_class.rb +77 -78
- data/lib/rdoc/code_object/normal_module.rb +61 -59
- data/lib/rdoc/code_object/require.rb +23 -39
- data/lib/rdoc/code_object/single_class.rb +21 -19
- data/lib/rdoc/code_object/top_level.rb +212 -219
- data/lib/rdoc/code_object.rb +305 -303
- data/lib/rdoc/comment.rb +275 -273
- data/lib/rdoc/cross_reference.rb +192 -190
- data/lib/rdoc/encoding.rb +105 -103
- data/lib/rdoc/erb_partial.rb +13 -11
- data/lib/rdoc/erbio.rb +29 -27
- data/lib/rdoc/generator/aliki.rb +161 -153
- data/lib/rdoc/generator/darkfish.rb +645 -635
- data/lib/rdoc/generator/json_index.rb +233 -229
- data/lib/rdoc/generator/markup.rb +164 -146
- data/lib/rdoc/generator/pot/message_extractor.rb +57 -51
- data/lib/rdoc/generator/pot/po.rb +52 -51
- data/lib/rdoc/generator/pot/po_entry.rb +138 -132
- data/lib/rdoc/generator/pot.rb +85 -81
- data/lib/rdoc/generator/ri.rb +23 -19
- data/lib/rdoc/generator/template/aliki/DESIGN.md +6 -4
- data/lib/rdoc/generator/template/aliki/_footer.rhtml +1 -1
- data/lib/rdoc/generator/template/aliki/_head.rhtml +10 -10
- data/lib/rdoc/generator/template/aliki/_header.rhtml +29 -44
- data/lib/rdoc/generator/template/aliki/_sidebar_search.rhtml +4 -4
- data/lib/rdoc/generator/template/aliki/css/rdoc.css +207 -178
- data/lib/rdoc/generator/template/aliki/js/aliki.js +60 -84
- data/lib/rdoc/generator/template/darkfish/_footer.rhtml +1 -1
- data/lib/rdoc/generator.rb +48 -46
- data/lib/rdoc/i18n/locale.rb +99 -95
- data/lib/rdoc/i18n/text.rb +109 -105
- data/lib/rdoc/i18n.rb +7 -5
- data/lib/rdoc/markdown/byte_runtime.rb +80 -0
- data/lib/rdoc/markdown.kpeg +15 -11
- data/lib/rdoc/markdown.rb +40 -47
- data/lib/rdoc/markup/block_quote.rb +12 -8
- data/lib/rdoc/markup/document.rb +127 -123
- data/lib/rdoc/markup/formatter.rb +219 -215
- data/lib/rdoc/markup/include.rb +33 -29
- data/lib/rdoc/markup/indented_paragraph.rb +37 -33
- data/lib/rdoc/markup/inline_parser.rb +281 -277
- data/lib/rdoc/markup/list.rb +80 -88
- data/lib/rdoc/markup/list_item.rb +73 -85
- data/lib/rdoc/markup/paragraph.rb +23 -19
- data/lib/rdoc/markup/parser.rb +501 -497
- data/lib/rdoc/markup/pre_process.rb +283 -279
- data/lib/rdoc/markup/raw.rb +2 -2
- data/lib/rdoc/markup/rule.rb +16 -12
- data/lib/rdoc/markup/to_ansi.rb +143 -139
- data/lib/rdoc/markup/to_bs.rb +72 -68
- data/lib/rdoc/markup/to_html.rb +594 -565
- data/lib/rdoc/markup/to_html_crossref.rb +234 -230
- data/lib/rdoc/markup/to_html_snippet.rb +232 -227
- data/lib/rdoc/markup/to_joined_paragraph.rb +36 -32
- data/lib/rdoc/markup/to_label.rb +63 -59
- data/lib/rdoc/markup/to_markdown.rb +212 -208
- data/lib/rdoc/markup/to_rdoc.rb +336 -332
- data/lib/rdoc/markup/to_table_of_contents.rb +66 -62
- data/lib/rdoc/markup/to_test.rb +60 -56
- data/lib/rdoc/markup/to_tt_only.rb +84 -80
- data/lib/rdoc/markup/verbatim.rb +62 -58
- data/lib/rdoc/markup.rb +198 -196
- data/lib/rdoc/options.rb +1063 -1061
- data/lib/rdoc/parser/c.rb +1039 -1037
- data/lib/rdoc/parser/changelog.rb +319 -315
- data/lib/rdoc/parser/markdown.rb +17 -13
- data/lib/rdoc/parser/rbs.rb +239 -235
- data/lib/rdoc/parser/rd.rb +17 -13
- data/lib/rdoc/parser/ruby.rb +1245 -1124
- data/lib/rdoc/parser/ruby_colorizer.rb +263 -213
- data/lib/rdoc/parser/simple.rb +31 -27
- data/lib/rdoc/parser/text.rb +12 -8
- data/lib/rdoc/parser.rb +228 -220
- data/lib/rdoc/rbs_helper.rb +1 -1
- data/lib/rdoc/rd/inline.rb +57 -53
- data/lib/rdoc/rd.rb +90 -88
- data/lib/rdoc/rdoc.rb +500 -491
- data/lib/rdoc/ri/driver.rb +1140 -1135
- data/lib/rdoc/ri/formatter.rb +7 -3
- data/lib/rdoc/ri/paths.rb +140 -136
- data/lib/rdoc/ri/servlet.rb +354 -350
- data/lib/rdoc/ri/store.rb +4 -2
- data/lib/rdoc/ri/task.rb +55 -51
- data/lib/rdoc/ri.rb +14 -12
- data/lib/rdoc/rubygems_hook.rb +183 -181
- data/lib/rdoc/server.rb +349 -347
- data/lib/rdoc/stats/normal.rb +46 -42
- data/lib/rdoc/stats/quiet.rb +39 -35
- data/lib/rdoc/stats/verbose.rb +35 -31
- data/lib/rdoc/stats.rb +365 -363
- data/lib/rdoc/store.rb +888 -902
- data/lib/rdoc/task.rb +260 -256
- data/lib/rdoc/text.rb +135 -133
- data/lib/rdoc/token_stream.rb +101 -93
- data/lib/rdoc/tom_doc.rb +203 -201
- data/lib/rdoc/version.rb +1 -1
- metadata +4 -5
- data/lib/rdoc/markdown/literals.kpeg +0 -21
- data/lib/rdoc/markdown/literals.rb +0 -454
|
@@ -1,287 +1,292 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
module RDoc
|
|
3
|
+
class Markup
|
|
4
|
+
##
|
|
5
|
+
# Outputs RDoc markup as paragraphs with inline markup only.
|
|
4
6
|
|
|
5
|
-
class
|
|
7
|
+
class ToHtmlSnippet < Markup::ToHtml
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
##
|
|
10
|
+
# After this many characters the input will be cut off.
|
|
9
11
|
|
|
10
|
-
|
|
12
|
+
attr_reader :character_limit
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
##
|
|
15
|
+
# The number of characters seen so far.
|
|
14
16
|
|
|
15
|
-
|
|
17
|
+
attr_reader :characters # :nodoc:
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
##
|
|
20
|
+
# The attribute bitmask
|
|
19
21
|
|
|
20
|
-
|
|
22
|
+
attr_reader :mask
|
|
21
23
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
##
|
|
25
|
+
# After this many paragraphs the input will be cut off.
|
|
24
26
|
|
|
25
|
-
|
|
27
|
+
attr_reader :paragraph_limit
|
|
26
28
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
##
|
|
30
|
+
# Count of paragraphs found
|
|
29
31
|
|
|
30
|
-
|
|
32
|
+
attr_reader :paragraphs
|
|
31
33
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
38
|
-
|
|
39
|
+
def initialize(characters = 100, paragraphs = 3)
|
|
40
|
+
super()
|
|
39
41
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
+
@character_limit = characters
|
|
43
|
+
@paragraph_limit = paragraphs
|
|
42
44
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
@characters = 0
|
|
46
|
+
@mask = 0
|
|
47
|
+
@paragraphs = 0
|
|
46
48
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
@markup.add_regexp_handling CrossReference::CROSSREF_REGEXP, :CROSSREF
|
|
50
|
+
end
|
|
49
51
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
+
##
|
|
53
|
+
# Adds +heading+ to the output as a paragraph
|
|
52
54
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
def accept_heading(heading)
|
|
56
|
+
@res << "<p>#{to_html heading.text}\n"
|
|
55
57
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
+
add_paragraph
|
|
59
|
+
end
|
|
58
60
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
+
##
|
|
62
|
+
# Raw sections are untrusted and ignored
|
|
61
63
|
|
|
62
|
-
|
|
64
|
+
alias accept_raw ignore
|
|
63
65
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
+
##
|
|
67
|
+
# Rules are ignored
|
|
66
68
|
|
|
67
|
-
|
|
69
|
+
alias accept_rule ignore
|
|
68
70
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
+
##
|
|
72
|
+
# Adds +paragraph+ to the output
|
|
71
73
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
+
def accept_paragraph(paragraph)
|
|
75
|
+
para = @in_list_entry.last || "<p>"
|
|
74
76
|
|
|
75
|
-
|
|
77
|
+
text = paragraph.text @hard_break
|
|
76
78
|
|
|
77
|
-
|
|
79
|
+
@res << "#{para}#{to_html text}\n"
|
|
78
80
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
+
add_paragraph
|
|
82
|
+
end
|
|
81
83
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
+
##
|
|
85
|
+
# Finishes consumption of +list_item+
|
|
84
86
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
+
def accept_list_item_end(list_item)
|
|
88
|
+
end
|
|
87
89
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
+
##
|
|
91
|
+
# Prepares the visitor for consuming +list_item+
|
|
90
92
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
93
|
+
def accept_list_item_start(list_item)
|
|
94
|
+
@res << list_item_start(list_item, @list.last)
|
|
95
|
+
end
|
|
94
96
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
+
##
|
|
98
|
+
# Prepares the visitor for consuming +list+
|
|
97
99
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
106
|
+
##
|
|
107
|
+
# Adds +verbatim+ to the output
|
|
106
108
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
-
|
|
116
|
+
super Markup::Verbatim.new text
|
|
115
117
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
+
add_paragraph
|
|
119
|
+
end
|
|
118
120
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
+
##
|
|
122
|
+
# Prepares the visitor for HTML snippet generation
|
|
121
123
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
+
def start_accepting
|
|
125
|
+
super
|
|
124
126
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
##
|
|
129
|
-
# Removes escaping from the cross-references in +target+
|
|
127
|
+
@characters = 0
|
|
128
|
+
end
|
|
130
129
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
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
|
-
|
|
134
|
+
def handle_regexp_CROSSREF(text)
|
|
135
|
+
convert_string(text.delete_prefix('\\'))
|
|
136
|
+
end
|
|
137
137
|
|
|
138
|
-
|
|
139
|
-
|
|
138
|
+
##
|
|
139
|
+
# Lists are paragraphs, but notes and labels have a separator
|
|
140
140
|
|
|
141
|
-
|
|
142
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 << " — " unless labels.empty?
|
|
158
153
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
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
|
-
|
|
173
|
-
|
|
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
|
-
|
|
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
|
-
|
|
184
|
-
|
|
185
|
-
|
|
273
|
+
def to_html(item)
|
|
274
|
+
throw :done if @characters >= @character_limit
|
|
275
|
+
handle_inline(item)
|
|
276
|
+
end
|
|
186
277
|
|
|
187
|
-
|
|
188
|
-
|
|
278
|
+
##
|
|
279
|
+
# Truncates +text+ at the end of the first word after the limit.
|
|
189
280
|
|
|
190
|
-
|
|
191
|
-
|
|
281
|
+
def truncate(text, limit)
|
|
282
|
+
return text if limit >= text.size
|
|
283
|
+
return '' if limit <= 0
|
|
192
284
|
|
|
193
|
-
|
|
194
|
-
end
|
|
285
|
+
text =~ /\A(.{#{limit},}?)(\s|$)/m # TODO word-break instead of \s?
|
|
195
286
|
|
|
196
|
-
|
|
197
|
-
|
|
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 << " #{TO_HTML_CHARACTERS[text.encoding][:ellipsis]}" 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
|
-
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,41 +1,45 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
# This
|
|
8
|
-
#
|
|
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.
|
|
9
11
|
|
|
10
|
-
class
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
class ToJoinedParagraph < Markup::Formatter
|
|
13
|
+
def start_accepting # :nodoc:
|
|
14
|
+
end
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
def end_accepting # :nodoc:
|
|
17
|
+
end
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
##
|
|
20
|
+
# Converts the parts of +paragraph+ to a single entry.
|
|
19
21
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
|
26
28
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
paragraph.parts.replace parts
|
|
30
|
+
end
|
|
29
31
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
|
40
42
|
|
|
43
|
+
end
|
|
44
|
+
end
|
|
41
45
|
end
|