rdoc 7.2.0 → 8.0.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 +3 -4
- data/LICENSE.rdoc +4 -0
- data/README.md +43 -2
- data/doc/markup_reference/markdown.md +104 -3
- data/lib/rdoc/code_object/alias.rb +2 -8
- data/lib/rdoc/code_object/any_method.rb +11 -6
- data/lib/rdoc/code_object/attr.rb +11 -6
- data/lib/rdoc/code_object/class_module.rb +62 -32
- data/lib/rdoc/code_object/constant.rb +29 -3
- data/lib/rdoc/code_object/context/section.rb +4 -35
- data/lib/rdoc/code_object/context.rb +39 -34
- data/lib/rdoc/code_object/method_attr.rb +9 -15
- data/lib/rdoc/code_object/mixin.rb +2 -2
- data/lib/rdoc/code_object/top_level.rb +9 -3
- data/lib/rdoc/code_object.rb +2 -4
- data/lib/rdoc/comment.rb +0 -65
- data/lib/rdoc/cross_reference.rb +7 -27
- data/lib/rdoc/encoding.rb +3 -3
- data/lib/rdoc/generator/aliki.rb +17 -0
- data/lib/rdoc/generator/darkfish.rb +12 -6
- data/lib/rdoc/generator/json_index.rb +2 -2
- data/lib/rdoc/generator/markup.rb +56 -31
- data/lib/rdoc/generator/template/aliki/DESIGN.md +536 -0
- data/lib/rdoc/generator/template/aliki/_aside_toc.rhtml +1 -1
- data/lib/rdoc/generator/template/aliki/_head.rhtml +1 -1
- data/lib/rdoc/generator/template/aliki/_sidebar_extends.rhtml +8 -6
- data/lib/rdoc/generator/template/aliki/_sidebar_includes.rhtml +8 -6
- data/lib/rdoc/generator/template/aliki/_sidebar_installed.rhtml +1 -1
- data/lib/rdoc/generator/template/aliki/_sidebar_pages.rhtml +2 -2
- data/lib/rdoc/generator/template/aliki/_sidebar_sections.rhtml +1 -1
- data/lib/rdoc/generator/template/aliki/_sidebar_toggle.rhtml +1 -1
- data/lib/rdoc/generator/template/aliki/class.rhtml +56 -46
- data/lib/rdoc/generator/template/aliki/css/rdoc.css +337 -111
- data/lib/rdoc/generator/template/aliki/index.rhtml +1 -1
- data/lib/rdoc/generator/template/aliki/js/aliki.js +20 -18
- data/lib/rdoc/generator/template/aliki/page.rhtml +1 -1
- data/lib/rdoc/generator/template/aliki/servlet_not_found.rhtml +1 -1
- data/lib/rdoc/generator/template/aliki/servlet_root.rhtml +2 -2
- data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +8 -6
- data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +8 -6
- data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +1 -1
- data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +1 -1
- data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +1 -1
- data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +5 -5
- data/lib/rdoc/generator/template/darkfish/class.rhtml +18 -21
- data/lib/rdoc/generator/template/darkfish/css/rdoc.css +0 -1
- data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +3 -3
- data/lib/rdoc/i18n/text.rb +3 -3
- data/lib/rdoc/markdown.kpeg +15 -10
- data/lib/rdoc/markdown.rb +289 -104
- data/lib/rdoc/markup/document.rb +2 -2
- data/lib/rdoc/markup/formatter.rb +24 -34
- data/lib/rdoc/markup/heading.rb +1 -4
- data/lib/rdoc/markup/indented_paragraph.rb +1 -1
- data/lib/rdoc/markup/list.rb +2 -2
- data/lib/rdoc/markup/list_item.rb +2 -2
- data/lib/rdoc/markup/pre_process.rb +0 -25
- data/lib/rdoc/markup/to_ansi.rb +1 -1
- data/lib/rdoc/markup/to_bs.rb +1 -1
- data/lib/rdoc/markup/to_html.rb +131 -53
- data/lib/rdoc/markup/to_html_crossref.rb +97 -71
- data/lib/rdoc/markup/to_html_snippet.rb +5 -5
- data/lib/rdoc/markup/to_joined_paragraph.rb +0 -5
- data/lib/rdoc/markup/to_label.rb +2 -2
- data/lib/rdoc/markup/to_markdown.rb +1 -1
- data/lib/rdoc/markup/to_rdoc.rb +2 -2
- data/lib/rdoc/markup/to_table_of_contents.rb +1 -1
- data/lib/rdoc/markup/to_tt_only.rb +0 -7
- data/lib/rdoc/markup/verbatim.rb +1 -1
- data/lib/rdoc/options.rb +36 -51
- data/lib/rdoc/parser/c.rb +7 -6
- data/lib/rdoc/parser/rbs.rb +275 -0
- data/lib/rdoc/parser/ruby.rb +954 -2066
- data/lib/rdoc/parser/ruby_colorizer.rb +253 -0
- data/lib/rdoc/parser.rb +3 -2
- data/lib/rdoc/rbs_helper.rb +186 -0
- data/lib/rdoc/rdoc.rb +196 -24
- data/lib/rdoc/ri/driver.rb +8 -2
- data/lib/rdoc/ri/paths.rb +1 -1
- data/lib/rdoc/{servlet.rb → ri/servlet.rb} +5 -5
- data/lib/rdoc/ri.rb +4 -3
- data/lib/rdoc/rubygems_hook.rb +11 -11
- data/lib/rdoc/server.rb +460 -0
- data/lib/rdoc/stats.rb +147 -124
- data/lib/rdoc/store.rb +212 -4
- data/lib/rdoc/task.rb +16 -15
- data/lib/rdoc/text.rb +1 -118
- data/lib/rdoc/token_stream.rb +11 -33
- data/lib/rdoc/version.rb +1 -1
- data/lib/rdoc.rb +35 -7
- data/lib/rubygems_plugin.rb +2 -11
- data/rdoc-logo.svg +43 -0
- data/rdoc.gemspec +6 -4
- metadata +35 -18
- data/lib/rdoc/code_object/anon_class.rb +0 -10
- data/lib/rdoc/code_object/ghost_method.rb +0 -6
- data/lib/rdoc/code_object/meta_method.rb +0 -6
- data/lib/rdoc/parser/prism_ruby.rb +0 -1112
- data/lib/rdoc/parser/ripper_state_lex.rb +0 -302
- data/lib/rdoc/parser/ruby_tools.rb +0 -163
data/lib/rdoc/markup/document.rb
CHANGED
|
@@ -26,7 +26,7 @@ class RDoc::Markup::Document
|
|
|
26
26
|
##
|
|
27
27
|
# Creates a new Document with +parts+
|
|
28
28
|
|
|
29
|
-
def initialize
|
|
29
|
+
def initialize(*parts)
|
|
30
30
|
@parts = []
|
|
31
31
|
@parts.concat parts
|
|
32
32
|
|
|
@@ -148,7 +148,7 @@ class RDoc::Markup::Document
|
|
|
148
148
|
##
|
|
149
149
|
# Appends +parts+ to the document
|
|
150
150
|
|
|
151
|
-
def push
|
|
151
|
+
def push(*parts)
|
|
152
152
|
self.parts.concat parts
|
|
153
153
|
end
|
|
154
154
|
|
|
@@ -14,13 +14,6 @@ require 'rdoc/markup/inline_parser'
|
|
|
14
14
|
|
|
15
15
|
class RDoc::Markup::Formatter
|
|
16
16
|
|
|
17
|
-
##
|
|
18
|
-
# Tag for inline markup containing a +bit+ for the bitmask and the +on+ and
|
|
19
|
-
# +off+ triggers.
|
|
20
|
-
|
|
21
|
-
InlineTag = Struct.new(:bit, :on, :off)
|
|
22
|
-
|
|
23
|
-
|
|
24
17
|
##
|
|
25
18
|
# Converts a target url to one that is relative to a given path
|
|
26
19
|
|
|
@@ -48,10 +41,8 @@ class RDoc::Markup::Formatter
|
|
|
48
41
|
##
|
|
49
42
|
# Creates a new Formatter
|
|
50
43
|
|
|
51
|
-
def initialize
|
|
52
|
-
@
|
|
53
|
-
|
|
54
|
-
@markup = markup || RDoc::Markup.new
|
|
44
|
+
def initialize
|
|
45
|
+
@markup = RDoc::Markup.new
|
|
55
46
|
|
|
56
47
|
@from_path = '.'
|
|
57
48
|
end
|
|
@@ -94,31 +85,30 @@ class RDoc::Markup::Formatter
|
|
|
94
85
|
# Applies regexp handling to +text+ and returns an array of [text, converted?] pairs.
|
|
95
86
|
|
|
96
87
|
def apply_regexp_handling(text)
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
matched_name = matched_text = nil
|
|
102
|
-
@markup.regexp_handlings.each do |pattern, name|
|
|
103
|
-
m = text.match(pattern, start)
|
|
104
|
-
next unless m
|
|
88
|
+
matched = []
|
|
89
|
+
@markup.regexp_handlings.each_with_index do |(pattern, name), priority|
|
|
90
|
+
text.scan(pattern) do
|
|
91
|
+
m = Regexp.last_match
|
|
105
92
|
idx = m[1] ? 1 : 0
|
|
106
|
-
|
|
107
|
-
pos = m.begin(idx)
|
|
108
|
-
matched_text = m[idx]
|
|
109
|
-
matched_name = name
|
|
110
|
-
end
|
|
93
|
+
matched << [m.begin(idx), m.end(idx), m[idx], name, priority]
|
|
111
94
|
end
|
|
112
|
-
output << [text[start...pos], false] if pos > start
|
|
113
|
-
if matched_name
|
|
114
|
-
handled = public_send(:"handle_regexp_#{matched_name}", matched_text)
|
|
115
|
-
output << [handled, true]
|
|
116
|
-
start = pos + matched_text.size
|
|
117
|
-
else
|
|
118
|
-
start = pos
|
|
119
|
-
end
|
|
120
|
-
break if pos == text.size
|
|
121
95
|
end
|
|
96
|
+
# If the start positions are the same, prefer the earlier-registered one
|
|
97
|
+
# (lower numeric priority from each_with_index).
|
|
98
|
+
matched.sort_by! {|beg_pos, _, _, _, priority| [beg_pos, priority] }
|
|
99
|
+
|
|
100
|
+
pos = 0
|
|
101
|
+
output = []
|
|
102
|
+
matched.each do |beg_pos, end_pos, s, name|
|
|
103
|
+
next if beg_pos < pos
|
|
104
|
+
|
|
105
|
+
output << [text[pos...beg_pos], false] if beg_pos != pos
|
|
106
|
+
handled = public_send(:"handle_regexp_#{name}", s)
|
|
107
|
+
output << [handled, true]
|
|
108
|
+
pos = end_pos
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
output << [text[pos..], false] if pos < text.size
|
|
122
112
|
output
|
|
123
113
|
end
|
|
124
114
|
|
|
@@ -252,7 +242,7 @@ class RDoc::Markup::Formatter
|
|
|
252
242
|
#
|
|
253
243
|
# alias accept_raw ignore
|
|
254
244
|
|
|
255
|
-
def ignore
|
|
245
|
+
def ignore(*node)
|
|
256
246
|
end
|
|
257
247
|
|
|
258
248
|
##
|
data/lib/rdoc/markup/heading.rb
CHANGED
|
@@ -52,10 +52,7 @@ module RDoc
|
|
|
52
52
|
#: () -> RDoc::Markup::ToHtml
|
|
53
53
|
def self.to_html
|
|
54
54
|
@to_html ||= begin
|
|
55
|
-
|
|
56
|
-
markup.add_regexp_handling CrossReference::CROSSREF_REGEXP, :CROSSREF
|
|
57
|
-
|
|
58
|
-
to_html = Markup::ToHtml.new nil
|
|
55
|
+
to_html = Markup::ToHtml.new
|
|
59
56
|
|
|
60
57
|
def to_html.handle_regexp_CROSSREF(text)
|
|
61
58
|
text.sub(/^\\/, '')
|
data/lib/rdoc/markup/list.rb
CHANGED
|
@@ -37,7 +37,7 @@ class RDoc::Markup::List
|
|
|
37
37
|
# Creates a new list of +type+ with +items+. Valid list types are:
|
|
38
38
|
# +:BULLET+, +:LABEL+, +:LALPHA+, +:NOTE+, +:NUMBER+, +:UALPHA+
|
|
39
39
|
|
|
40
|
-
def initialize
|
|
40
|
+
def initialize(type = nil, *items)
|
|
41
41
|
@type = type
|
|
42
42
|
@items = []
|
|
43
43
|
@items.concat items
|
|
@@ -94,7 +94,7 @@ class RDoc::Markup::List
|
|
|
94
94
|
##
|
|
95
95
|
# Appends +items+ to the list
|
|
96
96
|
|
|
97
|
-
def push
|
|
97
|
+
def push(*items)
|
|
98
98
|
@items.concat items
|
|
99
99
|
end
|
|
100
100
|
|
|
@@ -24,7 +24,7 @@ class RDoc::Markup::ListItem
|
|
|
24
24
|
##
|
|
25
25
|
# Creates a new ListItem with an optional +label+ containing +parts+
|
|
26
26
|
|
|
27
|
-
def initialize
|
|
27
|
+
def initialize(label = nil, *parts)
|
|
28
28
|
@label = label
|
|
29
29
|
@parts = []
|
|
30
30
|
@parts.concat parts
|
|
@@ -92,7 +92,7 @@ class RDoc::Markup::ListItem
|
|
|
92
92
|
##
|
|
93
93
|
# Adds +parts+ to the ListItem
|
|
94
94
|
|
|
95
|
-
def push
|
|
95
|
+
def push(*parts)
|
|
96
96
|
@parts.concat parts
|
|
97
97
|
end
|
|
98
98
|
|
|
@@ -209,18 +209,6 @@ class RDoc::Markup::PreProcess
|
|
|
209
209
|
when 'include' then
|
|
210
210
|
filename = param.split(' ', 2).first
|
|
211
211
|
include_file filename, prefix, encoding
|
|
212
|
-
when 'main' then
|
|
213
|
-
@options.main_page = param if @options.respond_to? :main_page
|
|
214
|
-
warn <<~MSG
|
|
215
|
-
The :main: directive is deprecated and will be removed in RDoc 7.
|
|
216
|
-
|
|
217
|
-
You can use these options to specify the initial page displayed instead:
|
|
218
|
-
- `--main=#{param}` via the command line
|
|
219
|
-
- `rdoc.main = "#{param}"` if you use `RDoc::Task`
|
|
220
|
-
- `main_page: #{param}` in your `.rdoc_options` file
|
|
221
|
-
MSG
|
|
222
|
-
|
|
223
|
-
blankline
|
|
224
212
|
when 'nodoc' then
|
|
225
213
|
return blankline unless code_object
|
|
226
214
|
code_object.document_self = nil # notify nodoc
|
|
@@ -245,19 +233,6 @@ class RDoc::Markup::PreProcess
|
|
|
245
233
|
|
|
246
234
|
code_object.stop_doc
|
|
247
235
|
|
|
248
|
-
blankline
|
|
249
|
-
when 'title' then
|
|
250
|
-
@options.default_title = param if @options.respond_to? :default_title=
|
|
251
|
-
|
|
252
|
-
warn <<~MSG
|
|
253
|
-
The :title: directive is deprecated and will be removed in RDoc 7.
|
|
254
|
-
|
|
255
|
-
You can use these options to specify the title displayed instead:
|
|
256
|
-
- `--title=#{param}` via the command line
|
|
257
|
-
- `rdoc.title = "#{param}"` if you use `RDoc::Task`
|
|
258
|
-
- `title: #{param}` in your `.rdoc_options` file
|
|
259
|
-
MSG
|
|
260
|
-
|
|
261
236
|
blankline
|
|
262
237
|
when 'yield', 'yields' then
|
|
263
238
|
return blankline unless code_object
|
data/lib/rdoc/markup/to_ansi.rb
CHANGED
data/lib/rdoc/markup/to_bs.rb
CHANGED
data/lib/rdoc/markup/to_html.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
require 'cgi/escape'
|
|
3
3
|
require 'cgi/util' unless defined?(CGI::EscapeExt)
|
|
4
|
+
require 'prism'
|
|
4
5
|
|
|
5
6
|
##
|
|
6
7
|
# Outputs RDoc markup as HTML.
|
|
@@ -40,17 +41,100 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|
|
40
41
|
|
|
41
42
|
# :section:
|
|
42
43
|
|
|
44
|
+
# Maps an encoding to a Hash of characters properly transcoded for that
|
|
45
|
+
# encoding.
|
|
46
|
+
#
|
|
47
|
+
# See also encode_fallback.
|
|
48
|
+
|
|
49
|
+
TO_HTML_CHARACTERS = Hash.new do |h, encoding|
|
|
50
|
+
h[encoding] = {
|
|
51
|
+
close_dquote: encode_fallback('”', encoding, '"'),
|
|
52
|
+
close_squote: encode_fallback('’', encoding, '\''),
|
|
53
|
+
copyright: encode_fallback('©', encoding, '(c)'),
|
|
54
|
+
ellipsis: encode_fallback('…', encoding, '...'),
|
|
55
|
+
dot_ellipsis: encode_fallback('.…', encoding, '....'),
|
|
56
|
+
em_dash: encode_fallback('—', encoding, '---'),
|
|
57
|
+
en_dash: encode_fallback('–', encoding, '--'),
|
|
58
|
+
open_dquote: encode_fallback('“', encoding, '"'),
|
|
59
|
+
open_squote: encode_fallback('‘', encoding, '\''),
|
|
60
|
+
trademark: encode_fallback('®', encoding, '(r)'),
|
|
61
|
+
}
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
HTML_CHARACTER_ALIASES = {
|
|
65
|
+
'(c)' => :copyright,
|
|
66
|
+
'(C)' => :copyright,
|
|
67
|
+
'(r)' => :trademark,
|
|
68
|
+
'(R)' => :trademark,
|
|
69
|
+
'---' => :em_dash,
|
|
70
|
+
'--' => :en_dash,
|
|
71
|
+
'....' => :dot_ellipsis,
|
|
72
|
+
'...' => :ellipsis,
|
|
73
|
+
'``' => :open_dquote,
|
|
74
|
+
"''" => :close_dquote,
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
# Transcodes +character+ to +encoding+ with a +fallback+ character.
|
|
78
|
+
|
|
79
|
+
def self.encode_fallback(character, encoding, fallback)
|
|
80
|
+
character.encode(
|
|
81
|
+
encoding,
|
|
82
|
+
fallback: { character => fallback },
|
|
83
|
+
undef: :replace,
|
|
84
|
+
replace: fallback
|
|
85
|
+
)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# Converts ascii quote pairs to multibyte quote characters
|
|
89
|
+
class QuoteConverter
|
|
90
|
+
|
|
91
|
+
def initialize
|
|
92
|
+
@in_dquote = false
|
|
93
|
+
@in_squote = false
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def convert(quote, after_word:)
|
|
97
|
+
case quote
|
|
98
|
+
when '"'
|
|
99
|
+
type = @in_dquote ? :close_dquote : :open_dquote
|
|
100
|
+
@in_dquote = !@in_dquote
|
|
101
|
+
when "'"
|
|
102
|
+
if @in_squote
|
|
103
|
+
type = :close_squote
|
|
104
|
+
@in_squote = false
|
|
105
|
+
elsif after_word
|
|
106
|
+
# Mary's dog, my parents' house: do not start paired quotes
|
|
107
|
+
type = :close_squote
|
|
108
|
+
else
|
|
109
|
+
type = :open_squote
|
|
110
|
+
@in_squote = true
|
|
111
|
+
end
|
|
112
|
+
when '`'
|
|
113
|
+
# Opening quote of <tt>`quoted sentence'</tt>.
|
|
114
|
+
# This will conflict with code blocks <tt>`puts('hello')`</tt> in the future.
|
|
115
|
+
if !@in_squote && !after_word
|
|
116
|
+
type = :open_squote
|
|
117
|
+
@in_squote = true
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
TO_HTML_CHARACTERS[quote.encoding][type] if type
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
43
124
|
##
|
|
44
125
|
# Creates a new formatter that will output HTML
|
|
45
126
|
|
|
46
|
-
def initialize(
|
|
47
|
-
super
|
|
127
|
+
def initialize(pipe: false, output_decoration: true)
|
|
128
|
+
super()
|
|
48
129
|
|
|
130
|
+
@pipe = pipe
|
|
131
|
+
@output_decoration = output_decoration
|
|
49
132
|
@code_object = nil
|
|
50
133
|
@from_path = ''
|
|
51
134
|
@in_list_entry = nil
|
|
52
135
|
@list = nil
|
|
53
136
|
@th = nil
|
|
137
|
+
@quote_converter = nil
|
|
54
138
|
@in_tidylink_label = false
|
|
55
139
|
@hard_break = "<br>\n"
|
|
56
140
|
|
|
@@ -75,6 +159,11 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|
|
75
159
|
# suppress crossref: \#method \::method \ClassName \method_with_underscores
|
|
76
160
|
@markup.add_regexp_handling(/\\(?:[#:A-Z]|[a-z]+_[a-z0-9])/, :SUPPRESSED_CROSSREF)
|
|
77
161
|
|
|
162
|
+
@markup.add_regexp_handling(Regexp.union(HTML_CHARACTER_ALIASES.keys), :HTML_CHARACTERS)
|
|
163
|
+
|
|
164
|
+
@markup.add_regexp_handling(/\b['"`]/, :QUOTE_AFTER_WORD)
|
|
165
|
+
@markup.add_regexp_handling(/\B['"`]/, :QUOTE_NOT_AFTER_WORD)
|
|
166
|
+
|
|
78
167
|
init_link_notation_regexp_handlings
|
|
79
168
|
end
|
|
80
169
|
|
|
@@ -227,12 +316,28 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|
|
227
316
|
|
|
228
317
|
def handle_inline(text) # :nodoc:
|
|
229
318
|
@inline_output = +''
|
|
319
|
+
@quote_converter = QuoteConverter.new
|
|
230
320
|
super
|
|
231
321
|
out = @inline_output
|
|
232
322
|
@inline_output = nil
|
|
323
|
+
@quote_converter = nil
|
|
233
324
|
out
|
|
234
325
|
end
|
|
235
326
|
|
|
327
|
+
# Converts <tt>(c), (r), --, --- , ..., ...., ``, ''</tt> to HTML characters.
|
|
328
|
+
def handle_regexp_HTML_CHARACTERS(text)
|
|
329
|
+
name = HTML_CHARACTER_ALIASES[text]
|
|
330
|
+
TO_HTML_CHARACTERS[text.encoding][name] if name
|
|
331
|
+
end
|
|
332
|
+
|
|
333
|
+
def handle_regexp_QUOTE_NOT_AFTER_WORD(text)
|
|
334
|
+
@quote_converter.convert(text, after_word: false) || convert_string(text)
|
|
335
|
+
end
|
|
336
|
+
|
|
337
|
+
def handle_regexp_QUOTE_AFTER_WORD(text)
|
|
338
|
+
@quote_converter.convert(text, after_word: true) || convert_string(text)
|
|
339
|
+
end
|
|
340
|
+
|
|
236
341
|
# Converts suppressed cross-reference +text+ to HTML by removing the leading backslash.
|
|
237
342
|
|
|
238
343
|
def handle_regexp_SUPPRESSED_CROSSREF(text)
|
|
@@ -311,13 +416,22 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|
|
311
416
|
def accept_paragraph(paragraph)
|
|
312
417
|
@res << "\n<p>"
|
|
313
418
|
text = paragraph.text @hard_break
|
|
314
|
-
text = text.gsub(/(#{SPACE_SEPARATED_LETTER_CLASS})?\K
|
|
419
|
+
text = text.gsub(/(#{SPACE_SEPARATED_LETTER_CLASS})?\K(?:\r?\n)+(?=(?(1)(#{SPACE_SEPARATED_LETTER_CLASS})?))/o) {
|
|
315
420
|
defined?($2) && ' '
|
|
316
421
|
}
|
|
317
422
|
@res << to_html(text)
|
|
318
423
|
@res << "</p>\n"
|
|
319
424
|
end
|
|
320
425
|
|
|
426
|
+
# Generate syntax highlighted html for ruby-like text.
|
|
427
|
+
|
|
428
|
+
def parsable_text_to_html(text)
|
|
429
|
+
tokens = RDoc::Parser::RubyColorizer.colorize(text)
|
|
430
|
+
result = RDoc::TokenStream.to_html tokens
|
|
431
|
+
result = result + "\n" unless result.end_with?("\n")
|
|
432
|
+
result
|
|
433
|
+
end
|
|
434
|
+
|
|
321
435
|
##
|
|
322
436
|
# Adds +verbatim+ to the output
|
|
323
437
|
|
|
@@ -325,29 +439,19 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|
|
325
439
|
text = verbatim.text.rstrip
|
|
326
440
|
format = verbatim.format
|
|
327
441
|
|
|
328
|
-
klass = nil
|
|
329
|
-
|
|
330
442
|
# Apply Ruby syntax highlighting if
|
|
331
443
|
# - explicitly marked as Ruby (via ruby? which accepts :ruby or :rb)
|
|
332
444
|
# - no format specified but the text is parseable as Ruby
|
|
333
445
|
# Otherwise, add language class when applicable and skip Ruby highlighting
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
CGI.escapeHTML text
|
|
344
|
-
end
|
|
345
|
-
else
|
|
346
|
-
klass = " class=\"#{format}\"" if format
|
|
347
|
-
CGI.escapeHTML text
|
|
348
|
-
end
|
|
349
|
-
|
|
350
|
-
if @options.pipe then
|
|
446
|
+
if verbatim.ruby? || (format.nil? && parseable?(text))
|
|
447
|
+
content = parsable_text_to_html(text)
|
|
448
|
+
klass = ' class="ruby"'
|
|
449
|
+
else
|
|
450
|
+
content = CGI.escapeHTML text
|
|
451
|
+
klass = " class=\"#{format}\"" if format
|
|
452
|
+
end
|
|
453
|
+
|
|
454
|
+
if @pipe
|
|
351
455
|
@res << "\n<pre><code>#{CGI.escapeHTML text}\n</code></pre>\n"
|
|
352
456
|
else
|
|
353
457
|
@res << "\n<pre#{klass}>#{content}</pre>\n"
|
|
@@ -418,17 +522,17 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|
|
418
522
|
|
|
419
523
|
# Add legacy anchor before the heading for backward compatibility.
|
|
420
524
|
# This allows old links with label- prefix to still work.
|
|
421
|
-
if @
|
|
525
|
+
if @output_decoration && !@pipe
|
|
422
526
|
@res << "\n<span id=\"#{legacy_label}\" class=\"legacy-anchor\"></span>"
|
|
423
527
|
end
|
|
424
528
|
|
|
425
|
-
@res << if @
|
|
529
|
+
@res << if @output_decoration
|
|
426
530
|
"\n<h#{level} id=\"#{label}\">"
|
|
427
531
|
else
|
|
428
532
|
"\n<h#{level}>"
|
|
429
533
|
end
|
|
430
534
|
|
|
431
|
-
if @
|
|
535
|
+
if @pipe
|
|
432
536
|
@res << to_html(heading.text)
|
|
433
537
|
else
|
|
434
538
|
@res << "<a href=\"##{label}\">#{to_html(heading.text)}</a>"
|
|
@@ -566,39 +670,13 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|
|
566
670
|
# Returns true if text is valid ruby syntax
|
|
567
671
|
|
|
568
672
|
def parseable?(text)
|
|
569
|
-
|
|
570
|
-
catch(:valid) do
|
|
571
|
-
eval("BEGIN { throw :valid, true }\n#{text}")
|
|
572
|
-
end
|
|
573
|
-
rescue SyntaxError
|
|
574
|
-
false
|
|
575
|
-
ensure
|
|
576
|
-
$VERBOSE = verbose
|
|
673
|
+
Prism.parse_success?(text)
|
|
577
674
|
end
|
|
578
675
|
|
|
579
676
|
##
|
|
580
677
|
# Converts +item+ to HTML using RDoc::Text#to_html
|
|
581
678
|
|
|
582
679
|
def to_html(item)
|
|
583
|
-
|
|
584
|
-
# but we need to convert it here for now because to_html_characters converts pair of backticks to ’‘ and pair of double backticks to ”“.
|
|
585
|
-
# Known bugs: `...` in `<code>def f(...); end</code>` and `(c) in `<a href="(c)">` will be wrongly converted.
|
|
586
|
-
to_html_characters(handle_inline(item))
|
|
587
|
-
end
|
|
588
|
-
end
|
|
589
|
-
|
|
590
|
-
##
|
|
591
|
-
# Formatter dedicated to rendering tidy link labels without mutating the
|
|
592
|
-
# calling formatter's state.
|
|
593
|
-
|
|
594
|
-
class RDoc::Markup::LinkLabelToHtml < RDoc::Markup::ToHtml
|
|
595
|
-
def self.render(label, options, from_path)
|
|
596
|
-
new(options, from_path).to_html(label)
|
|
597
|
-
end
|
|
598
|
-
|
|
599
|
-
def initialize(options, from_path = nil)
|
|
600
|
-
super(options)
|
|
601
|
-
|
|
602
|
-
self.from_path = from_path if from_path
|
|
680
|
+
handle_inline(item)
|
|
603
681
|
end
|
|
604
682
|
end
|