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/parser.rb
CHANGED
|
@@ -1,288 +1,296 @@
|
|
|
1
1
|
# -*- coding: us-ascii -*-
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
#
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
#
|
|
10
|
-
#
|
|
11
|
-
#
|
|
12
|
-
#
|
|
13
|
-
#
|
|
14
|
-
#
|
|
15
|
-
#
|
|
16
|
-
#
|
|
17
|
-
#
|
|
18
|
-
#
|
|
19
|
-
#
|
|
20
|
-
#
|
|
21
|
-
#
|
|
22
|
-
#
|
|
23
|
-
#
|
|
24
|
-
#
|
|
25
|
-
#
|
|
26
|
-
#
|
|
27
|
-
#
|
|
28
|
-
#
|
|
29
|
-
#
|
|
30
|
-
#
|
|
31
|
-
#
|
|
32
|
-
|
|
33
|
-
class RDoc::Parser
|
|
34
|
-
|
|
35
|
-
@parsers = []
|
|
36
|
-
|
|
37
|
-
class << self
|
|
4
|
+
module RDoc
|
|
5
|
+
##
|
|
6
|
+
# A parser is simple a class that subclasses RDoc::Parser and implements #scan
|
|
7
|
+
# to fill in an RDoc::TopLevel with parsed data.
|
|
8
|
+
#
|
|
9
|
+
# The initialize method takes an RDoc::TopLevel to fill with parsed content,
|
|
10
|
+
# the name of the file to be parsed, the content of the file, an RDoc::Options
|
|
11
|
+
# object and an RDoc::Stats object to inform the user of parsed items. The
|
|
12
|
+
# scan method is then called to parse the file and must return the
|
|
13
|
+
# RDoc::TopLevel object. By calling super these items will be set for you.
|
|
14
|
+
#
|
|
15
|
+
# In order to be used by RDoc the parser needs to register the file extensions
|
|
16
|
+
# it can parse. Use ::parse_files_matching to register extensions.
|
|
17
|
+
#
|
|
18
|
+
# require 'rdoc'
|
|
19
|
+
#
|
|
20
|
+
# class RDoc::Parser::Xyz < RDoc::Parser
|
|
21
|
+
# parse_files_matching /\.xyz$/
|
|
22
|
+
#
|
|
23
|
+
# def initialize top_level, file_name, content, options, stats
|
|
24
|
+
# super
|
|
25
|
+
#
|
|
26
|
+
# # extra initialization if needed
|
|
27
|
+
# end
|
|
28
|
+
#
|
|
29
|
+
# def scan
|
|
30
|
+
# # parse file and fill in @top_level
|
|
31
|
+
# end
|
|
32
|
+
# end
|
|
38
33
|
|
|
39
|
-
|
|
40
|
-
# An Array of arrays that maps file extension (or name) regular
|
|
41
|
-
# expressions to parser classes that will parse matching filenames.
|
|
42
|
-
#
|
|
43
|
-
# Use parse_files_matching to register a parser's file extensions.
|
|
34
|
+
class Parser
|
|
44
35
|
|
|
45
|
-
|
|
36
|
+
@parsers = []
|
|
46
37
|
|
|
47
|
-
|
|
38
|
+
class << self
|
|
48
39
|
|
|
49
|
-
|
|
50
|
-
|
|
40
|
+
##
|
|
41
|
+
# An Array of arrays that maps file extension (or name) regular
|
|
42
|
+
# expressions to parser classes that will parse matching filenames.
|
|
43
|
+
#
|
|
44
|
+
# Use parse_files_matching to register a parser's file extensions.
|
|
51
45
|
|
|
52
|
-
|
|
46
|
+
attr_reader :parsers
|
|
53
47
|
|
|
54
|
-
|
|
55
|
-
# Alias an extension to another extension. After this call, files ending
|
|
56
|
-
# "new_ext" will be parsed using the same parser as "old_ext"
|
|
48
|
+
end
|
|
57
49
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
new_ext = new_ext.sub(/^\.(.*)/, '\1')
|
|
50
|
+
##
|
|
51
|
+
# The name of the file being parsed
|
|
61
52
|
|
|
62
|
-
|
|
63
|
-
return false unless parser
|
|
53
|
+
attr_reader :file_name
|
|
64
54
|
|
|
65
|
-
|
|
55
|
+
##
|
|
56
|
+
# Alias an extension to another extension. After this call, files ending
|
|
57
|
+
# "new_ext" will be parsed using the same parser as "old_ext"
|
|
66
58
|
|
|
67
|
-
|
|
68
|
-
|
|
59
|
+
def self.alias_extension(old_ext, new_ext)
|
|
60
|
+
old_ext = old_ext.sub(/^\.(.*)/, '\1')
|
|
61
|
+
new_ext = new_ext.sub(/^\.(.*)/, '\1')
|
|
69
62
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
# content that an RDoc parser shouldn't try to consume.
|
|
63
|
+
parser = can_parse_by_name "xxx.#{old_ext}"
|
|
64
|
+
return false unless parser
|
|
73
65
|
|
|
74
|
-
|
|
75
|
-
return false if file =~ /\.(rdoc|txt)$/
|
|
66
|
+
Parser.parsers.unshift [/\.#{new_ext}$/, parser]
|
|
76
67
|
|
|
77
|
-
|
|
68
|
+
true
|
|
69
|
+
end
|
|
78
70
|
|
|
79
|
-
|
|
71
|
+
##
|
|
72
|
+
# Determines if the file is a "binary" file which basically means it has
|
|
73
|
+
# content that an RDoc parser shouldn't try to consume.
|
|
80
74
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
encoding = s[/^\s*\#\s*(?:-\*-\s*)?(?:en)?coding:\s*([^\s;]+?)(?:-\*-|[\s;])/, 1]
|
|
84
|
-
mode = "rb:#{encoding}" if encoding
|
|
85
|
-
s = File.open(file, mode) {|f| f.gets(nil, 1024)}
|
|
75
|
+
def self.binary?(file)
|
|
76
|
+
return false if file =~ /\.(rdoc|txt)$/
|
|
86
77
|
|
|
87
|
-
|
|
88
|
-
end
|
|
78
|
+
s = File.read(file, 1024) or return false
|
|
89
79
|
|
|
90
|
-
|
|
91
|
-
# Checks if +file+ is a zip file in disguise. Signatures from
|
|
92
|
-
# http://www.garykessler.net/library/file_sigs.html
|
|
80
|
+
return true if s[0, 2] == Marshal.dump('')[0, 2] or s.index("\x00")
|
|
93
81
|
|
|
94
|
-
|
|
95
|
-
|
|
82
|
+
mode = 'r:utf-8' # default source encoding has been changed to utf-8
|
|
83
|
+
s.sub!(/\A#!.*\n/, '') # assume shebang line isn't longer than 1024.
|
|
84
|
+
encoding = s[/^\s*\#\s*(?:-\*-\s*)?(?:en)?coding:\s*([^\s;]+?)(?:-\*-|[\s;])/, 1]
|
|
85
|
+
mode = "rb:#{encoding}" if encoding
|
|
86
|
+
s = File.open(file, mode) {|f| f.gets(nil, 1024)}
|
|
96
87
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
zip_signature == "PK\x07\x08"
|
|
100
|
-
rescue
|
|
101
|
-
false
|
|
102
|
-
end
|
|
88
|
+
not s.valid_encoding?
|
|
89
|
+
end
|
|
103
90
|
|
|
104
|
-
|
|
105
|
-
|
|
91
|
+
##
|
|
92
|
+
# Checks if +file+ is a zip file in disguise. Signatures from
|
|
93
|
+
# http://www.garykessler.net/library/file_sigs.html
|
|
106
94
|
|
|
107
|
-
|
|
108
|
-
|
|
95
|
+
def self.zip?(file)
|
|
96
|
+
zip_signature = File.read file, 4
|
|
109
97
|
|
|
110
|
-
|
|
111
|
-
|
|
98
|
+
zip_signature == "PK\x03\x04" or
|
|
99
|
+
zip_signature == "PK\x05\x06" or
|
|
100
|
+
zip_signature == "PK\x07\x08"
|
|
101
|
+
rescue
|
|
102
|
+
false
|
|
103
|
+
end
|
|
112
104
|
|
|
113
|
-
|
|
114
|
-
|
|
105
|
+
##
|
|
106
|
+
# Return a parser that can handle a particular extension
|
|
115
107
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
# not depend upon the file being readable.
|
|
108
|
+
def self.can_parse(file_name)
|
|
109
|
+
parser = can_parse_by_name file_name
|
|
119
110
|
|
|
120
|
-
|
|
121
|
-
|
|
111
|
+
# HACK Selenium hides a jar file using a .txt extension
|
|
112
|
+
return if parser == Parser::Simple and zip? file_name
|
|
122
113
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
return parser if ext_name.empty?
|
|
114
|
+
parser
|
|
115
|
+
end
|
|
126
116
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
117
|
+
##
|
|
118
|
+
# Returns a parser that can handle the extension for +file_name+. This does
|
|
119
|
+
# not depend upon the file being readable.
|
|
120
|
+
|
|
121
|
+
def self.can_parse_by_name(file_name)
|
|
122
|
+
_, parser = Parser.parsers.find { |regexp,| regexp =~ file_name }
|
|
123
|
+
|
|
124
|
+
# The default parser must not parse binary files
|
|
125
|
+
ext_name = File.extname file_name
|
|
126
|
+
return parser if ext_name.empty?
|
|
127
|
+
|
|
128
|
+
if parser == Parser::Simple and ext_name !~ /txt|rdoc/
|
|
129
|
+
case mode = check_modeline(file_name)
|
|
130
|
+
when nil, 'rdoc' # continue
|
|
131
|
+
else
|
|
132
|
+
Parser.parsers.find { |_, p| return p if mode.casecmp?(p.name[/\w+\z/]) }
|
|
133
|
+
return nil
|
|
134
|
+
end
|
|
133
135
|
end
|
|
134
|
-
end
|
|
135
136
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
137
|
+
parser
|
|
138
|
+
rescue Errno::EACCES
|
|
139
|
+
end
|
|
139
140
|
|
|
140
|
-
|
|
141
|
-
|
|
141
|
+
##
|
|
142
|
+
# Returns the file type from the modeline in +file_name+
|
|
142
143
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
144
|
+
def self.check_modeline(file_name)
|
|
145
|
+
line = File.open file_name do |io|
|
|
146
|
+
io.gets
|
|
147
|
+
end
|
|
147
148
|
|
|
148
|
-
|
|
149
|
+
/-\*-\s*(.*?\S)\s*-\*-/ =~ line
|
|
149
150
|
|
|
150
|
-
|
|
151
|
+
return nil unless type = $1
|
|
151
152
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
153
|
+
if /;/ =~ type
|
|
154
|
+
return nil unless /(?:\s|\A)mode:\s*([^\s;]+)/i =~ type
|
|
155
|
+
type = $1
|
|
156
|
+
end
|
|
156
157
|
|
|
157
|
-
|
|
158
|
+
return nil if /coding:/i =~ type
|
|
158
159
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
160
|
+
type.downcase
|
|
161
|
+
rescue ArgumentError
|
|
162
|
+
rescue ::Encoding::InvalidByteSequenceError # invalid byte sequence
|
|
162
163
|
|
|
163
|
-
|
|
164
|
+
end
|
|
164
165
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
166
|
+
##
|
|
167
|
+
# Finds and instantiates the correct parser for the given +file_name+ and
|
|
168
|
+
# +content+.
|
|
168
169
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
170
|
+
def self.for(top_level, content, options, stats)
|
|
171
|
+
file_name = top_level.absolute_name
|
|
172
|
+
return if binary? file_name
|
|
172
173
|
|
|
173
|
-
|
|
174
|
+
parser = use_markup content
|
|
174
175
|
|
|
175
|
-
|
|
176
|
-
|
|
176
|
+
unless parser
|
|
177
|
+
parse_name = file_name
|
|
177
178
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
179
|
+
# If no extension, look for shebang
|
|
180
|
+
if file_name !~ /\.\w+$/ && content =~ %r{\A#!(.+)}
|
|
181
|
+
shebang = $1
|
|
182
|
+
case shebang
|
|
183
|
+
when %r{env\s+ruby}, %r{/ruby}
|
|
184
|
+
parse_name = 'dummy.rb'
|
|
185
|
+
end
|
|
184
186
|
end
|
|
187
|
+
|
|
188
|
+
parser = can_parse parse_name
|
|
185
189
|
end
|
|
186
190
|
|
|
187
|
-
|
|
188
|
-
end
|
|
191
|
+
return unless parser
|
|
189
192
|
|
|
190
|
-
|
|
193
|
+
content = remove_modeline content
|
|
191
194
|
|
|
192
|
-
|
|
195
|
+
parser.new top_level, content, options, stats
|
|
196
|
+
rescue SystemCallError
|
|
197
|
+
nil
|
|
198
|
+
end
|
|
193
199
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
200
|
+
##
|
|
201
|
+
# Record which file types this parser can understand.
|
|
202
|
+
#
|
|
203
|
+
# It is ok to call this multiple times.
|
|
198
204
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
# It is ok to call this multiple times.
|
|
205
|
+
def self.parse_files_matching(regexp)
|
|
206
|
+
Parser.parsers.unshift [regexp, self]
|
|
207
|
+
end
|
|
203
208
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
end
|
|
209
|
+
##
|
|
210
|
+
# Removes an emacs-style modeline from the first line of the document
|
|
207
211
|
|
|
208
|
-
|
|
209
|
-
|
|
212
|
+
def self.remove_modeline(content)
|
|
213
|
+
content.sub(/\A.*-\*-\s*(.*?\S)\s*-\*-.*\r?\n/, '')
|
|
214
|
+
end
|
|
210
215
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
216
|
+
##
|
|
217
|
+
# If there is a <tt>markup: parser_name</tt> comment at the front of the
|
|
218
|
+
# file, use it to determine the parser. For example:
|
|
219
|
+
#
|
|
220
|
+
# # markup: rdoc
|
|
221
|
+
# # Class comment can go here
|
|
222
|
+
#
|
|
223
|
+
# class C
|
|
224
|
+
# end
|
|
225
|
+
#
|
|
226
|
+
# The comment should appear as the first line of the +content+.
|
|
227
|
+
#
|
|
228
|
+
# If the content contains a shebang or editor modeline the comment may
|
|
229
|
+
# appear on the second or third line.
|
|
230
|
+
#
|
|
231
|
+
# Any comment style may be used to hide the markup comment.
|
|
232
|
+
#
|
|
233
|
+
# The +tomdoc+ and +markdown+ markups name comment formats rather than
|
|
234
|
+
# parsers, so no parser is selected for them and RDoc::Parser.for picks one
|
|
235
|
+
# from the file name instead.
|
|
214
236
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
# file, use it to determine the parser. For example:
|
|
218
|
-
#
|
|
219
|
-
# # markup: rdoc
|
|
220
|
-
# # Class comment can go here
|
|
221
|
-
#
|
|
222
|
-
# class C
|
|
223
|
-
# end
|
|
224
|
-
#
|
|
225
|
-
# The comment should appear as the first line of the +content+.
|
|
226
|
-
#
|
|
227
|
-
# If the content contains a shebang or editor modeline the comment may
|
|
228
|
-
# appear on the second or third line.
|
|
229
|
-
#
|
|
230
|
-
# Any comment style may be used to hide the markup comment.
|
|
237
|
+
def self.use_markup(content)
|
|
238
|
+
markup = content.lines.first(3).grep(/markup:\s+(\w+)/) { $1 }.first
|
|
231
239
|
|
|
232
|
-
|
|
233
|
-
markup = content.lines.first(3).grep(/markup:\s+(\w+)/) { $1 }.first
|
|
240
|
+
return unless markup
|
|
234
241
|
|
|
235
|
-
|
|
242
|
+
# tomdoc and markdown name a comment format, not a parser. Skipping them
|
|
243
|
+
# keeps the search below from matching RDoc::Parser::Markdown for a file
|
|
244
|
+
# that is not markdown.
|
|
245
|
+
return if %w[tomdoc markdown].include? markup
|
|
236
246
|
|
|
237
|
-
|
|
238
|
-
return RDoc::Parser::Ruby if %w[tomdoc markdown].include? markup
|
|
247
|
+
markup = Regexp.escape markup
|
|
239
248
|
|
|
240
|
-
|
|
249
|
+
_, selected = Parser.parsers.find do |_, parser|
|
|
250
|
+
/^#{markup}$/i =~ parser.name.sub(/.*:/, '')
|
|
251
|
+
end
|
|
241
252
|
|
|
242
|
-
|
|
243
|
-
/^#{markup}$/i =~ parser.name.sub(/.*:/, '')
|
|
253
|
+
selected
|
|
244
254
|
end
|
|
245
255
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
@preprocess = RDoc::Markup::PreProcess.new @file_name, @options.rdoc_include
|
|
266
|
-
@preprocess.options = @options
|
|
267
|
-
end
|
|
256
|
+
##
|
|
257
|
+
# Creates a new Parser storing +top_level+, +file_name+, +content+,
|
|
258
|
+
# +options+ and +stats+ in instance variables. In +@preprocess+ an
|
|
259
|
+
# RDoc::Markup::PreProcess object is created which allows processing of
|
|
260
|
+
# directives.
|
|
261
|
+
|
|
262
|
+
def initialize(top_level, content, options, stats)
|
|
263
|
+
@top_level = top_level
|
|
264
|
+
@top_level.parser = self.class
|
|
265
|
+
@store = @top_level.store
|
|
266
|
+
|
|
267
|
+
@file_name = top_level.absolute_name
|
|
268
|
+
@content = content
|
|
269
|
+
@options = options
|
|
270
|
+
@stats = stats
|
|
271
|
+
|
|
272
|
+
@preprocess = Markup::PreProcess.new @file_name, @options.rdoc_include
|
|
273
|
+
@preprocess.options = @options
|
|
274
|
+
end
|
|
268
275
|
|
|
269
|
-
|
|
276
|
+
autoload :Text, "#{__dir__}/parser/text"
|
|
270
277
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
278
|
+
##
|
|
279
|
+
# Normalizes tabs in +body+
|
|
280
|
+
|
|
281
|
+
def handle_tab_width(body)
|
|
282
|
+
if /\t/ =~ body
|
|
283
|
+
tab_width = @options.tab_width
|
|
284
|
+
body.split(/\n/).map do |line|
|
|
285
|
+
1 while line.gsub!(/\t+/) do
|
|
286
|
+
b, e = $~.offset(0)
|
|
287
|
+
' ' * (tab_width * (e-b) - b % tab_width)
|
|
288
|
+
end
|
|
289
|
+
line
|
|
290
|
+
end.join "\n"
|
|
291
|
+
else
|
|
292
|
+
body
|
|
293
|
+
end
|
|
286
294
|
end
|
|
287
295
|
end
|
|
288
296
|
end
|
data/lib/rdoc/rbs_helper.rb
CHANGED
|
@@ -122,7 +122,7 @@ module RDoc
|
|
|
122
122
|
start_in_escaped = prefix.length
|
|
123
123
|
end_in_escaped = start_in_escaped + escaped_name.length
|
|
124
124
|
|
|
125
|
-
href = ERB::Util.html_escape(
|
|
125
|
+
href = ERB::Util.html_escape(Markup::Formatter.gen_relative_url(from_path, target_path))
|
|
126
126
|
result[start_in_escaped...end_in_escaped] =
|
|
127
127
|
"<a href=\"#{href}\" class=\"rbs-type\">#{escaped_name}</a>"
|
|
128
128
|
end
|
data/lib/rdoc/rd/inline.rb
CHANGED
|
@@ -1,71 +1,75 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
module RDoc
|
|
3
|
+
class RD
|
|
4
|
+
##
|
|
5
|
+
# Inline keeps track of markup and labels to create proper links.
|
|
4
6
|
|
|
5
|
-
class
|
|
7
|
+
class Inline
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
##
|
|
10
|
+
# The text of the reference
|
|
9
11
|
|
|
10
|
-
|
|
12
|
+
attr_reader :reference
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
##
|
|
15
|
+
# The markup of this reference in RDoc format
|
|
14
16
|
|
|
15
|
-
|
|
17
|
+
attr_reader :rdoc
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
##
|
|
20
|
+
# Creates a new Inline for +rdoc+ and +reference+.
|
|
21
|
+
#
|
|
22
|
+
# +rdoc+ may be another Inline or a String. If +reference+ is not given it
|
|
23
|
+
# will use the text from +rdoc+.
|
|
22
24
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
def self.new(rdoc, reference = rdoc)
|
|
26
|
+
if self === rdoc and reference.equal? rdoc
|
|
27
|
+
rdoc
|
|
28
|
+
else
|
|
29
|
+
super
|
|
30
|
+
end
|
|
31
|
+
end
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
##
|
|
34
|
+
# Initializes the Inline with +rdoc+ and +inline+
|
|
33
35
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
def initialize(rdoc, reference) # :not-new:
|
|
37
|
+
@reference = reference.equal?(rdoc) ? reference.dup : reference
|
|
36
38
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
# unpack
|
|
40
|
+
@reference = @reference.reference if self.class === @reference
|
|
41
|
+
@rdoc = rdoc
|
|
42
|
+
end
|
|
41
43
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
def ==(other) # :nodoc:
|
|
45
|
+
self.class === other and
|
|
46
|
+
@reference == other.reference and @rdoc == other.rdoc
|
|
47
|
+
end
|
|
46
48
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
def append(more)
|
|
51
|
-
case more
|
|
52
|
-
when String then
|
|
53
|
-
@reference += more
|
|
54
|
-
@rdoc += more
|
|
55
|
-
when RDoc::RD::Inline then
|
|
56
|
-
@reference += more.reference
|
|
57
|
-
@rdoc += more.rdoc
|
|
58
|
-
else
|
|
59
|
-
raise "unknown thingy #{more}"
|
|
60
|
-
end
|
|
49
|
+
##
|
|
50
|
+
# Appends +more+ to this inline. +more+ may be a String or another Inline.
|
|
61
51
|
|
|
62
|
-
|
|
63
|
-
|
|
52
|
+
def append(more)
|
|
53
|
+
case more
|
|
54
|
+
when String
|
|
55
|
+
@reference += more
|
|
56
|
+
@rdoc += more
|
|
57
|
+
when RD::Inline
|
|
58
|
+
@reference += more.reference
|
|
59
|
+
@rdoc += more.rdoc
|
|
60
|
+
else
|
|
61
|
+
raise "unknown thingy #{more}"
|
|
62
|
+
end
|
|
64
63
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
self
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def inspect # :nodoc:
|
|
68
|
+
"(inline: #{self})"
|
|
69
|
+
end
|
|
68
70
|
|
|
69
|
-
|
|
71
|
+
alias to_s rdoc # :nodoc:
|
|
70
72
|
|
|
73
|
+
end
|
|
74
|
+
end
|
|
71
75
|
end
|