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
data/lib/rdoc/markup/to_rdoc.rb
CHANGED
|
@@ -1,421 +1,425 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
module RDoc
|
|
3
|
+
class Markup
|
|
4
|
+
##
|
|
5
|
+
# Outputs RDoc markup as RDoc markup! (mostly)
|
|
4
6
|
|
|
5
|
-
class
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
7
|
+
class ToRdoc < Markup::Formatter
|
|
8
|
+
DEFAULT_HEADINGS = {
|
|
9
|
+
1 => ['= ', ''],
|
|
10
|
+
2 => ['== ', ''],
|
|
11
|
+
3 => ['=== ', ''],
|
|
12
|
+
4 => ['==== ', ''],
|
|
13
|
+
5 => ['===== ', ''],
|
|
14
|
+
6 => ['====== ', '']
|
|
15
|
+
}
|
|
16
|
+
DEFAULT_HEADINGS.default = []
|
|
17
|
+
DEFAULT_HEADINGS.freeze
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
##
|
|
20
|
+
# Current indent amount for output in characters
|
|
19
21
|
|
|
20
|
-
|
|
22
|
+
attr_accessor :indent
|
|
21
23
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
##
|
|
25
|
+
# Output width in characters
|
|
24
26
|
|
|
25
|
-
|
|
27
|
+
attr_accessor :width
|
|
26
28
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
##
|
|
30
|
+
# Stack of current list indexes for alphabetic and numeric lists
|
|
29
31
|
|
|
30
|
-
|
|
32
|
+
attr_reader :list_index
|
|
31
33
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
+
##
|
|
35
|
+
# Stack of list types
|
|
34
36
|
|
|
35
|
-
|
|
37
|
+
attr_reader :list_type
|
|
36
38
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
##
|
|
40
|
+
# Stack of list widths for indentation
|
|
39
41
|
|
|
40
|
-
|
|
42
|
+
attr_reader :list_width
|
|
41
43
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
+
##
|
|
45
|
+
# Prefix for the next list item. See #use_prefix
|
|
44
46
|
|
|
45
|
-
|
|
47
|
+
attr_reader :prefix
|
|
46
48
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
##
|
|
50
|
+
# Output accumulator
|
|
49
51
|
|
|
50
|
-
|
|
52
|
+
attr_reader :res
|
|
51
53
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
+
##
|
|
55
|
+
# Creates a new formatter that will output (mostly) \RDoc markup
|
|
54
56
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
+
def initialize
|
|
58
|
+
super
|
|
57
59
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
+
@markup.add_regexp_handling(/\\\S/, :SUPPRESSED_CROSSREF)
|
|
61
|
+
@width = 78
|
|
60
62
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
##
|
|
66
|
-
# Adds +blank_line+ to the output
|
|
67
|
-
|
|
68
|
-
def accept_blank_line(blank_line)
|
|
69
|
-
@res << "\n"
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
##
|
|
73
|
-
# Adds +paragraph+ to the output
|
|
74
|
-
|
|
75
|
-
def accept_block_quote(block_quote)
|
|
76
|
-
@indent += 2
|
|
63
|
+
@headings = DEFAULT_HEADINGS.dup
|
|
64
|
+
@hard_break = "\n"
|
|
65
|
+
end
|
|
77
66
|
|
|
78
|
-
|
|
79
|
-
|
|
67
|
+
##
|
|
68
|
+
# Adds +blank_line+ to the output
|
|
80
69
|
|
|
81
|
-
|
|
82
|
-
|
|
70
|
+
def accept_blank_line(blank_line)
|
|
71
|
+
@res << "\n"
|
|
72
|
+
end
|
|
83
73
|
|
|
84
|
-
|
|
85
|
-
|
|
74
|
+
##
|
|
75
|
+
# Adds +paragraph+ to the output
|
|
86
76
|
|
|
87
|
-
|
|
88
|
-
|
|
77
|
+
def accept_block_quote(block_quote)
|
|
78
|
+
@indent += 2
|
|
89
79
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
@res << @headings[heading.level][0]
|
|
93
|
-
@res << attributes(heading.text)
|
|
94
|
-
@res << @headings[heading.level][1]
|
|
95
|
-
@res << "\n"
|
|
96
|
-
end
|
|
80
|
+
block_quote.parts.each do |part|
|
|
81
|
+
@prefix = '> '
|
|
97
82
|
|
|
98
|
-
|
|
99
|
-
|
|
83
|
+
part.accept self
|
|
84
|
+
end
|
|
100
85
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
@list_type.pop
|
|
104
|
-
@list_width.pop
|
|
105
|
-
end
|
|
86
|
+
@indent -= 2
|
|
87
|
+
end
|
|
106
88
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
def accept_list_item_end(list_item)
|
|
111
|
-
width = case @list_type.last
|
|
112
|
-
when :BULLET then
|
|
113
|
-
2
|
|
114
|
-
when :NOTE, :LABEL then
|
|
115
|
-
if @prefix then
|
|
116
|
-
@res << @prefix.strip
|
|
117
|
-
@prefix = nil
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
@res << "\n"
|
|
121
|
-
2
|
|
122
|
-
else
|
|
123
|
-
bullet = @list_index.last.to_s
|
|
124
|
-
@list_index[-1] = @list_index.last.succ
|
|
125
|
-
bullet.length + 2
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
@indent -= width
|
|
129
|
-
end
|
|
89
|
+
##
|
|
90
|
+
# Adds +heading+ to the output
|
|
130
91
|
|
|
131
|
-
|
|
132
|
-
|
|
92
|
+
def accept_heading(heading)
|
|
93
|
+
use_prefix or @res << ' ' * @indent
|
|
94
|
+
@res << @headings[heading.level][0]
|
|
95
|
+
@res << attributes(heading.text)
|
|
96
|
+
@res << @headings[heading.level][1]
|
|
97
|
+
@res << "\n"
|
|
98
|
+
end
|
|
133
99
|
|
|
134
|
-
|
|
135
|
-
|
|
100
|
+
##
|
|
101
|
+
# Finishes consumption of +list+
|
|
136
102
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
103
|
+
def accept_list_end(list)
|
|
104
|
+
@list_index.pop
|
|
105
|
+
@list_type.pop
|
|
106
|
+
@list_width.pop
|
|
141
107
|
end
|
|
142
108
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
109
|
+
##
|
|
110
|
+
# Finishes consumption of +list_item+
|
|
111
|
+
|
|
112
|
+
def accept_list_item_end(list_item)
|
|
113
|
+
width = case @list_type.last
|
|
114
|
+
when :BULLET
|
|
115
|
+
2
|
|
116
|
+
when :NOTE, :LABEL
|
|
117
|
+
if @prefix
|
|
118
|
+
@res << @prefix.strip
|
|
119
|
+
@prefix = nil
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
@res << "\n"
|
|
123
|
+
2
|
|
124
|
+
else
|
|
125
|
+
bullet = @list_index.last.to_s
|
|
126
|
+
@list_index[-1] = @list_index.last.succ
|
|
127
|
+
bullet.length + 2
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
@indent -= width
|
|
148
131
|
end
|
|
149
132
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
@list_index << 'A'
|
|
183
|
-
@list_width << list.items.length.to_s.length
|
|
184
|
-
else
|
|
185
|
-
raise RDoc::Error, "invalid list type #{list.type}"
|
|
186
|
-
end
|
|
133
|
+
##
|
|
134
|
+
# Prepares the visitor for consuming +list_item+
|
|
135
|
+
|
|
136
|
+
def accept_list_item_start(list_item)
|
|
137
|
+
type = @list_type.last
|
|
138
|
+
|
|
139
|
+
case type
|
|
140
|
+
when :NOTE, :LABEL
|
|
141
|
+
stripped_labels = Array(list_item.label).map do |label|
|
|
142
|
+
attributes(label).strip
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
bullets = case type
|
|
146
|
+
when :NOTE
|
|
147
|
+
stripped_labels.map { |b| "#{b}::" }
|
|
148
|
+
when :LABEL
|
|
149
|
+
stripped_labels.map { |b| "[#{b}]" }
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
bullets = bullets.join("\n")
|
|
153
|
+
bullets << "\n" unless stripped_labels.empty?
|
|
154
|
+
|
|
155
|
+
@prefix = ' ' * @indent
|
|
156
|
+
@indent += 2
|
|
157
|
+
@prefix << bullets + (' ' * @indent)
|
|
158
|
+
else
|
|
159
|
+
bullet = type == :BULLET ? '*' : @list_index.last.to_s + '.'
|
|
160
|
+
@prefix = (' ' * @indent) + bullet.ljust(bullet.length + 1)
|
|
161
|
+
width = bullet.length + 1
|
|
162
|
+
@indent += width
|
|
163
|
+
end
|
|
164
|
+
end
|
|
187
165
|
|
|
188
|
-
|
|
189
|
-
|
|
166
|
+
##
|
|
167
|
+
# Prepares the visitor for consuming +list+
|
|
168
|
+
|
|
169
|
+
def accept_list_start(list)
|
|
170
|
+
case list.type
|
|
171
|
+
when :BULLET
|
|
172
|
+
@list_index << nil
|
|
173
|
+
@list_width << 1
|
|
174
|
+
when :LABEL, :NOTE
|
|
175
|
+
@list_index << nil
|
|
176
|
+
@list_width << 2
|
|
177
|
+
when :LALPHA
|
|
178
|
+
@list_index << 'a'
|
|
179
|
+
@list_width << list.items.length.to_s.length
|
|
180
|
+
when :NUMBER
|
|
181
|
+
@list_index << 1
|
|
182
|
+
@list_width << list.items.length.to_s.length
|
|
183
|
+
when :UALPHA
|
|
184
|
+
@list_index << 'A'
|
|
185
|
+
@list_width << list.items.length.to_s.length
|
|
186
|
+
else
|
|
187
|
+
raise Error, "invalid list type #{list.type}"
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
@list_type << list.type
|
|
191
|
+
end
|
|
190
192
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
+
##
|
|
194
|
+
# Adds +paragraph+ to the output
|
|
193
195
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
196
|
+
def accept_paragraph(paragraph)
|
|
197
|
+
text = paragraph.text @hard_break
|
|
198
|
+
wrap attributes text
|
|
199
|
+
end
|
|
198
200
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
+
##
|
|
202
|
+
# Adds +paragraph+ to the output
|
|
201
203
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
204
|
+
def accept_indented_paragraph(paragraph)
|
|
205
|
+
@indent += paragraph.indent
|
|
206
|
+
text = paragraph.text @hard_break
|
|
207
|
+
wrap attributes text
|
|
208
|
+
@indent -= paragraph.indent
|
|
209
|
+
end
|
|
208
210
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
+
##
|
|
212
|
+
# Adds +raw+ to the output
|
|
211
213
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
214
|
+
def accept_raw(raw)
|
|
215
|
+
@res << raw.parts.join("\n")
|
|
216
|
+
end
|
|
215
217
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
+
##
|
|
219
|
+
# Adds +rule+ to the output
|
|
218
220
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
221
|
+
def accept_rule(rule)
|
|
222
|
+
use_prefix or @res << ' ' * @indent
|
|
223
|
+
@res << '-' * (@width - @indent)
|
|
224
|
+
@res << "\n"
|
|
225
|
+
end
|
|
224
226
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
+
##
|
|
228
|
+
# Outputs +verbatim+ indented 2 columns
|
|
227
229
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
+
def accept_verbatim(verbatim)
|
|
231
|
+
indent = ' ' * (@indent + 2)
|
|
230
232
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
233
|
+
verbatim.parts.each do |part|
|
|
234
|
+
@res << indent unless part == "\n"
|
|
235
|
+
@res << part
|
|
236
|
+
end
|
|
235
237
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
+
@res << "\n"
|
|
239
|
+
end
|
|
238
240
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
+
##
|
|
242
|
+
# Adds +table+ to the output
|
|
243
|
+
|
|
244
|
+
def accept_table(header, body, aligns)
|
|
245
|
+
header = header.map { |h| attributes h }
|
|
246
|
+
body = body.map { |row| row.map { |t| attributes t } }
|
|
247
|
+
widths = header.zip(*body).map do |cols|
|
|
248
|
+
cols.compact.map { |col| calculate_text_width(col) }.max
|
|
249
|
+
end
|
|
250
|
+
aligns = aligns.map do |a|
|
|
251
|
+
case a
|
|
252
|
+
when nil, :center
|
|
253
|
+
:center
|
|
254
|
+
when :left
|
|
255
|
+
:ljust
|
|
256
|
+
when :right
|
|
257
|
+
:rjust
|
|
258
|
+
end
|
|
259
|
+
end
|
|
260
|
+
@res << header.zip(widths, aligns).map do |h, w, a|
|
|
261
|
+
extra_width = h.size - calculate_text_width(h)
|
|
262
|
+
h.__send__(a, w + extra_width)
|
|
263
|
+
end.join("|").rstrip << "\n"
|
|
264
|
+
@res << widths.map {|w| "-" * w }.join("|") << "\n"
|
|
265
|
+
body.each do |row|
|
|
266
|
+
@res << widths.zip(aligns).each_with_index.map do |(w, a), i|
|
|
267
|
+
t = row[i] || ""
|
|
268
|
+
extra_width = t.size - calculate_text_width(t)
|
|
269
|
+
t.__send__(a, w + extra_width)
|
|
270
|
+
end.join("|").rstrip << "\n"
|
|
271
|
+
end
|
|
272
|
+
end
|
|
241
273
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
body = body.map { |row| row.map { |t| attributes t } }
|
|
245
|
-
widths = header.zip(*body).map do |cols|
|
|
246
|
-
cols.compact.map { |col| calculate_text_width(col) }.max
|
|
247
|
-
end
|
|
248
|
-
aligns = aligns.map do |a|
|
|
249
|
-
case a
|
|
250
|
-
when nil, :center
|
|
251
|
-
:center
|
|
252
|
-
when :left
|
|
253
|
-
:ljust
|
|
254
|
-
when :right
|
|
255
|
-
:rjust
|
|
274
|
+
def calculate_text_width(text)
|
|
275
|
+
text.size
|
|
256
276
|
end
|
|
257
|
-
end
|
|
258
|
-
@res << header.zip(widths, aligns).map do |h, w, a|
|
|
259
|
-
extra_width = h.size - calculate_text_width(h)
|
|
260
|
-
h.__send__(a, w + extra_width)
|
|
261
|
-
end.join("|").rstrip << "\n"
|
|
262
|
-
@res << widths.map {|w| "-" * w }.join("|") << "\n"
|
|
263
|
-
body.each do |row|
|
|
264
|
-
@res << widths.zip(aligns).each_with_index.map do |(w, a), i|
|
|
265
|
-
t = row[i] || ""
|
|
266
|
-
extra_width = t.size - calculate_text_width(t)
|
|
267
|
-
t.__send__(a, w + extra_width)
|
|
268
|
-
end.join("|").rstrip << "\n"
|
|
269
|
-
end
|
|
270
|
-
end
|
|
271
277
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
278
|
+
def handle_PLAIN_TEXT(text)
|
|
279
|
+
add_text(text)
|
|
280
|
+
end
|
|
275
281
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
282
|
+
def handle_REGEXP_HANDLING_TEXT(text)
|
|
283
|
+
add_text(text)
|
|
284
|
+
end
|
|
279
285
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
286
|
+
def handle_BOLD(target)
|
|
287
|
+
on(:BOLD)
|
|
288
|
+
super
|
|
289
|
+
off(:BOLD)
|
|
290
|
+
end
|
|
283
291
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
292
|
+
def handle_EM(target)
|
|
293
|
+
on(:EM)
|
|
294
|
+
super
|
|
295
|
+
off(:EM)
|
|
296
|
+
end
|
|
289
297
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
298
|
+
def handle_BOLD_WORD(word)
|
|
299
|
+
on(:BOLD)
|
|
300
|
+
super
|
|
301
|
+
off(:BOLD)
|
|
302
|
+
end
|
|
295
303
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
304
|
+
def handle_EM_WORD(word)
|
|
305
|
+
on(:EM)
|
|
306
|
+
super
|
|
307
|
+
off(:EM)
|
|
308
|
+
end
|
|
301
309
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
310
|
+
def handle_TT(code)
|
|
311
|
+
on(:TT)
|
|
312
|
+
super
|
|
313
|
+
off(:TT)
|
|
314
|
+
end
|
|
307
315
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
316
|
+
def handle_STRIKE(target)
|
|
317
|
+
on(:STRIKE)
|
|
318
|
+
super
|
|
319
|
+
off(:STRIKE)
|
|
320
|
+
end
|
|
313
321
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
off(:STRIKE)
|
|
318
|
-
end
|
|
322
|
+
def handle_HARD_BREAK
|
|
323
|
+
add_text("\n")
|
|
324
|
+
end
|
|
319
325
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
326
|
+
def handle_TIDYLINK(label_part, url)
|
|
327
|
+
super
|
|
328
|
+
add_text("( #{url} )")
|
|
329
|
+
end
|
|
323
330
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
331
|
+
def handle_inline(text, initial_attributes = [])
|
|
332
|
+
@attributes = Hash.new(0)
|
|
333
|
+
initial_attributes.each { |attr| on(attr) }
|
|
334
|
+
out = @inline_output = +''
|
|
335
|
+
super(text)
|
|
336
|
+
@inline_output = nil
|
|
337
|
+
out
|
|
338
|
+
end
|
|
328
339
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
out = @inline_output = +''
|
|
333
|
-
super(text)
|
|
334
|
-
@inline_output = nil
|
|
335
|
-
out
|
|
336
|
-
end
|
|
340
|
+
def on(attr)
|
|
341
|
+
@attributes[attr] += 1
|
|
342
|
+
end
|
|
337
343
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
344
|
+
def off(attr)
|
|
345
|
+
@attributes[attr] -= 1
|
|
346
|
+
@attributes.delete(attr) if @attributes[attr] == 0
|
|
347
|
+
end
|
|
341
348
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
end
|
|
349
|
+
def add_text(text)
|
|
350
|
+
emit_inline(text)
|
|
351
|
+
end
|
|
346
352
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
353
|
+
def emit_inline(text)
|
|
354
|
+
@inline_output << text
|
|
355
|
+
end
|
|
350
356
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
end
|
|
357
|
+
##
|
|
358
|
+
# Applies attribute-specific markup to +text+ using RDoc::Markup::InlineParser
|
|
354
359
|
|
|
355
|
-
|
|
356
|
-
|
|
360
|
+
def attributes(text)
|
|
361
|
+
handle_inline(text)
|
|
362
|
+
end
|
|
357
363
|
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
end
|
|
364
|
+
##
|
|
365
|
+
# Returns the generated output
|
|
361
366
|
|
|
362
|
-
|
|
363
|
-
|
|
367
|
+
def end_accepting
|
|
368
|
+
@res.join
|
|
369
|
+
end
|
|
364
370
|
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
end
|
|
371
|
+
##
|
|
372
|
+
# Removes preceding \\ from the suppressed crossref +target+
|
|
368
373
|
|
|
369
|
-
|
|
370
|
-
|
|
374
|
+
def handle_regexp_SUPPRESSED_CROSSREF(text)
|
|
375
|
+
text.sub('\\', '')
|
|
376
|
+
end
|
|
371
377
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
end
|
|
378
|
+
##
|
|
379
|
+
# Prepares the visitor for text generation
|
|
375
380
|
|
|
376
|
-
|
|
377
|
-
|
|
381
|
+
def start_accepting
|
|
382
|
+
@res = [""]
|
|
383
|
+
@indent = 0
|
|
384
|
+
@prefix = nil
|
|
378
385
|
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
386
|
+
@list_index = []
|
|
387
|
+
@list_type = []
|
|
388
|
+
@list_width = []
|
|
389
|
+
end
|
|
383
390
|
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
end
|
|
391
|
+
##
|
|
392
|
+
# Adds the stored #prefix to the output and clears it. Lists generate a
|
|
393
|
+
# prefix for later consumption.
|
|
388
394
|
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
395
|
+
def use_prefix
|
|
396
|
+
prefix, @prefix = @prefix, nil
|
|
397
|
+
@res << prefix if prefix
|
|
392
398
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
@res << prefix if prefix
|
|
399
|
+
prefix
|
|
400
|
+
end
|
|
396
401
|
|
|
397
|
-
|
|
398
|
-
|
|
402
|
+
##
|
|
403
|
+
# Wraps +text+ to #width
|
|
399
404
|
|
|
400
|
-
|
|
401
|
-
|
|
405
|
+
def wrap(text)
|
|
406
|
+
return unless text && !text.empty?
|
|
402
407
|
|
|
403
|
-
|
|
404
|
-
return unless text && !text.empty?
|
|
408
|
+
text_len = @width - @indent
|
|
405
409
|
|
|
406
|
-
|
|
410
|
+
text_len = 20 if text_len < 20
|
|
407
411
|
|
|
408
|
-
|
|
412
|
+
next_prefix = ' ' * @indent
|
|
409
413
|
|
|
410
|
-
|
|
414
|
+
prefix = @prefix || next_prefix
|
|
415
|
+
@prefix = nil
|
|
411
416
|
|
|
412
|
-
|
|
413
|
-
|
|
417
|
+
text.scan(/\G(?:([^ \n]{#{text_len}})(?=[^ \n])|(.{1,#{text_len}})(?:[ \n]|\z))/) do
|
|
418
|
+
@res << prefix << ($1 || $2) << "\n"
|
|
419
|
+
prefix = next_prefix
|
|
420
|
+
end
|
|
421
|
+
end
|
|
414
422
|
|
|
415
|
-
text.scan(/\G(?:([^ \n]{#{text_len}})(?=[^ \n])|(.{1,#{text_len}})(?:[ \n]|\z))/) do
|
|
416
|
-
@res << prefix << ($1 || $2) << "\n"
|
|
417
|
-
prefix = next_prefix
|
|
418
423
|
end
|
|
419
424
|
end
|
|
420
|
-
|
|
421
425
|
end
|