rdoc 7.0.2 → 7.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 +9 -0
- data/README.md +70 -4
- data/doc/markup_reference/markdown.md +558 -0
- data/doc/markup_reference/rdoc.rdoc +1169 -0
- data/lib/rdoc/code_object/class_module.rb +44 -8
- data/lib/rdoc/code_object/context/section.rb +20 -1
- data/lib/rdoc/cross_reference.rb +30 -21
- data/lib/rdoc/generator/template/aliki/_sidebar_pages.rhtml +1 -1
- data/lib/rdoc/generator/template/aliki/class.rhtml +3 -1
- data/lib/rdoc/generator/template/aliki/css/rdoc.css +20 -0
- data/lib/rdoc/generator/template/aliki/js/c_highlighter.js +1 -1
- data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +1 -1
- data/lib/rdoc/generator/template/darkfish/class.rhtml +2 -0
- data/lib/rdoc/generator/template/darkfish/css/rdoc.css +19 -0
- data/lib/rdoc/markdown.kpeg +1 -5
- data/lib/rdoc/markdown.rb +1 -5
- data/lib/rdoc/markup/attribute_manager.rb +28 -1
- data/lib/rdoc/markup/blank_line.rb +25 -23
- data/lib/rdoc/markup/element.rb +21 -0
- data/lib/rdoc/markup/hard_break.rb +30 -27
- data/lib/rdoc/markup/heading.rb +166 -77
- data/lib/rdoc/markup/raw.rb +52 -55
- data/lib/rdoc/markup/table.rb +48 -40
- data/lib/rdoc/markup/to_html.rb +31 -11
- data/lib/rdoc/markup/to_html_crossref.rb +24 -5
- data/lib/rdoc/markup/to_label.rb +11 -1
- data/lib/rdoc/markup/verbatim.rb +1 -1
- data/lib/rdoc/markup.rb +3 -2
- data/lib/rdoc/parser/changelog.rb +8 -0
- data/lib/rdoc/text.rb +15 -0
- data/lib/rdoc/token_stream.rb +4 -8
- data/lib/rdoc/version.rb +1 -1
- data/rdoc.gemspec +2 -2
- metadata +6 -7
- data/ExampleMarkdown.md +0 -39
- data/ExampleRDoc.rdoc +0 -210
data/lib/rdoc/markup/heading.rb
CHANGED
|
@@ -1,84 +1,173 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
##
|
|
3
|
-
# A heading with a level (1-6) and text
|
|
4
2
|
|
|
5
|
-
RDoc
|
|
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
|
-
|
|
3
|
+
module RDoc
|
|
4
|
+
class Markup
|
|
5
|
+
# IMPORTANT! This weird workaround is required to ensure that RDoc can correctly deserializing Marshal data from
|
|
6
|
+
# older rubies. Older rubies have `Heading` as a struct, so if we change it to a class, deserialization fails
|
|
7
|
+
if RUBY_VERSION.start_with?("4.")
|
|
8
|
+
class Heading < Element
|
|
9
|
+
#: String
|
|
10
|
+
attr_reader :text
|
|
11
|
+
|
|
12
|
+
#: Integer
|
|
13
|
+
attr_accessor :level
|
|
14
|
+
|
|
15
|
+
#: (Integer, String) -> void
|
|
16
|
+
def initialize(level, text)
|
|
17
|
+
super()
|
|
18
|
+
|
|
19
|
+
@level = level
|
|
20
|
+
@text = text
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
#: (Object) -> bool
|
|
24
|
+
def ==(other)
|
|
25
|
+
other.is_a?(Heading) && other.level == @level && other.text == @text
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
else
|
|
29
|
+
Heading = Struct.new(:level, :text)
|
|
32
30
|
end
|
|
33
31
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
32
|
+
# A heading with a level (1-6) and text
|
|
33
|
+
#
|
|
34
|
+
# RDoc syntax:
|
|
35
|
+
# = Heading 1
|
|
36
|
+
# == Heading 2
|
|
37
|
+
# === Heading 3
|
|
38
|
+
#
|
|
39
|
+
# Markdown syntax:
|
|
40
|
+
# # Heading 1
|
|
41
|
+
# ## Heading 2
|
|
42
|
+
# ### Heading 3
|
|
43
|
+
#
|
|
44
|
+
class Heading
|
|
45
|
+
# A singleton RDoc::Markup::ToLabel formatter for headings.
|
|
46
|
+
#: () -> RDoc::Markup::ToLabel
|
|
47
|
+
def self.to_label
|
|
48
|
+
@to_label ||= Markup::ToLabel.new
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# A singleton plain HTML formatter for headings. Used for creating labels for the Table of Contents
|
|
52
|
+
#: () -> RDoc::Markup::ToHtml
|
|
53
|
+
def self.to_html
|
|
54
|
+
@to_html ||= begin
|
|
55
|
+
markup = Markup.new
|
|
56
|
+
markup.add_regexp_handling CrossReference::CROSSREF_REGEXP, :CROSSREF
|
|
57
|
+
|
|
58
|
+
to_html = Markup::ToHtml.new nil
|
|
59
|
+
|
|
60
|
+
def to_html.handle_regexp_CROSSREF(target)
|
|
61
|
+
target.text.sub(/^\\/, '')
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
to_html
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# @override
|
|
69
|
+
#: (untyped) -> void
|
|
70
|
+
def accept(visitor)
|
|
71
|
+
visitor.accept_heading(self)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# An HTML-safe anchor reference for this header using GitHub-style formatting:
|
|
75
|
+
# - Lowercase
|
|
76
|
+
# - Spaces converted to hyphens
|
|
77
|
+
# - Special characters removed (except hyphens)
|
|
78
|
+
#
|
|
79
|
+
# Examples:
|
|
80
|
+
# "Hello" -> "hello"
|
|
81
|
+
# "Hello World" -> "hello-world"
|
|
82
|
+
# "Foo Bar Baz" -> "foo-bar-baz"
|
|
83
|
+
#
|
|
84
|
+
#: () -> String
|
|
85
|
+
def aref
|
|
86
|
+
self.class.to_label.convert text.dup
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# An HTML-safe anchor reference using legacy RDoc formatting:
|
|
90
|
+
# - Prefixed with "label-"
|
|
91
|
+
# - Original case preserved
|
|
92
|
+
# - Spaces converted to + (URL encoding style)
|
|
93
|
+
# - Special characters percent-encoded
|
|
94
|
+
#
|
|
95
|
+
# Returns nil if it would be the same as the GitHub-style aref (no alias needed).
|
|
96
|
+
#
|
|
97
|
+
# Examples:
|
|
98
|
+
# "hello" -> "label-hello" (different due to label- prefix)
|
|
99
|
+
# "Hello" -> "label-Hello"
|
|
100
|
+
# "Hello World" -> "label-Hello+World"
|
|
101
|
+
# "Foo Bar Baz" -> "label-Foo+Bar+Baz"
|
|
102
|
+
#
|
|
103
|
+
#: () -> String?
|
|
104
|
+
def legacy_aref
|
|
105
|
+
"label-#{self.class.to_label.convert_legacy text.dup}"
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# Creates a fully-qualified label (GitHub-style) which includes the context's aref prefix.
|
|
109
|
+
# This helps keep IDs unique in HTML when headings appear within class/method documentation.
|
|
110
|
+
#
|
|
111
|
+
# Examples (without context):
|
|
112
|
+
# "Hello World" -> "hello-world"
|
|
113
|
+
#
|
|
114
|
+
# Examples (with context being class Foo):
|
|
115
|
+
# "Hello World" -> "class-foo-hello-world"
|
|
116
|
+
#
|
|
117
|
+
# Examples (with context being method #bar):
|
|
118
|
+
# "Hello World" -> "method-i-bar-hello-world"
|
|
119
|
+
#
|
|
120
|
+
#: (RDoc::Context?) -> String
|
|
121
|
+
def label(context = nil)
|
|
122
|
+
result = +""
|
|
123
|
+
result << "#{context.aref}-" if context&.respond_to?(:aref)
|
|
124
|
+
result << aref
|
|
125
|
+
result
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# Creates a fully-qualified legacy label for backward compatibility.
|
|
129
|
+
# This is used to generate a secondary ID attribute on the heading's inner anchor,
|
|
130
|
+
# allowing old-style links (e.g., #label-Hello+World) to continue working.
|
|
131
|
+
#
|
|
132
|
+
# Examples (without context):
|
|
133
|
+
# "hello" -> "label-hello"
|
|
134
|
+
# "Hello World" -> "label-Hello+World"
|
|
135
|
+
#
|
|
136
|
+
# Examples (with context being class Foo):
|
|
137
|
+
# "hello" -> "class-Foo-label-hello"
|
|
138
|
+
# "Hello World" -> "class-Foo-label-Hello+World"
|
|
139
|
+
#
|
|
140
|
+
#: (RDoc::Context?) -> String
|
|
141
|
+
def legacy_label(context = nil)
|
|
142
|
+
result = +""
|
|
143
|
+
if context&.respond_to?(:legacy_aref)
|
|
144
|
+
result << "#{context.legacy_aref}-"
|
|
145
|
+
elsif context&.respond_to?(:aref)
|
|
146
|
+
result << "#{context.aref}-"
|
|
147
|
+
end
|
|
148
|
+
result << legacy_aref
|
|
149
|
+
result
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
# HTML markup of the text of this label without the surrounding header element.
|
|
153
|
+
#: () -> String
|
|
154
|
+
def plain_html
|
|
155
|
+
no_image_text = text
|
|
156
|
+
|
|
157
|
+
if matched = no_image_text.match(/rdoc-image:[^:]+:(.*)/)
|
|
158
|
+
no_image_text = matched[1]
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
self.class.to_html.to_html(no_image_text)
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
# @override
|
|
165
|
+
#: (PP) -> void
|
|
166
|
+
def pretty_print(q)
|
|
167
|
+
q.group 2, "[head: #{level} ", ']' do
|
|
168
|
+
q.pp text
|
|
169
|
+
end
|
|
170
|
+
end
|
|
73
171
|
end
|
|
74
|
-
|
|
75
|
-
self.class.to_html.to_html(text)
|
|
76
172
|
end
|
|
77
|
-
|
|
78
|
-
def pretty_print(q) # :nodoc:
|
|
79
|
-
q.group 2, "[head: #{level} ", ']' do
|
|
80
|
-
q.pp text
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
|
|
84
173
|
end
|
data/lib/rdoc/markup/raw.rb
CHANGED
|
@@ -1,69 +1,66 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
##
|
|
3
|
-
# A section of text that is added to the output document as-is
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
##
|
|
21
|
-
# Appends +text+
|
|
3
|
+
module RDoc
|
|
4
|
+
class Markup
|
|
5
|
+
# A section of text that is added to the output document as-is
|
|
6
|
+
class Raw
|
|
7
|
+
# The component parts of the list
|
|
8
|
+
#: Array[String]
|
|
9
|
+
attr_reader :parts
|
|
10
|
+
|
|
11
|
+
# Creates a new Raw containing +parts+
|
|
12
|
+
#: (*String) -> void
|
|
13
|
+
def initialize(*parts)
|
|
14
|
+
@parts = parts
|
|
15
|
+
end
|
|
22
16
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
# Appends +text+
|
|
18
|
+
#: (String) -> void
|
|
19
|
+
def <<(text)
|
|
20
|
+
@parts << text
|
|
21
|
+
end
|
|
26
22
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
#: (top) -> bool
|
|
24
|
+
def ==(other) # :nodoc:
|
|
25
|
+
self.class == other.class && @parts == other.parts
|
|
26
|
+
end
|
|
30
27
|
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
# Calls #accept_raw+ on +visitor+
|
|
29
|
+
# @override
|
|
30
|
+
#: (untyped) -> void
|
|
31
|
+
def accept(visitor)
|
|
32
|
+
visitor.accept_raw(self)
|
|
33
|
+
end
|
|
33
34
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
# Appends +other+'s parts
|
|
36
|
+
#: (Raw) -> void
|
|
37
|
+
def merge(other)
|
|
38
|
+
@parts.concat(other.parts)
|
|
39
|
+
end
|
|
37
40
|
|
|
38
|
-
|
|
39
|
-
|
|
41
|
+
# @override
|
|
42
|
+
#: (PP) -> void
|
|
43
|
+
def pretty_print(q) # :nodoc:
|
|
44
|
+
self.class.name =~ /.*::(\w{1,4})/i
|
|
40
45
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
46
|
+
q.group(2, "[#{$1.downcase}: ", ']') do
|
|
47
|
+
q.seplist(@parts) do |part|
|
|
48
|
+
q.pp(part)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
44
52
|
|
|
45
|
-
|
|
46
|
-
|
|
53
|
+
# Appends +texts+ onto this Paragraph
|
|
54
|
+
#: (*String) -> void
|
|
55
|
+
def push(*texts)
|
|
56
|
+
self.parts.concat(texts)
|
|
57
|
+
end
|
|
47
58
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
59
|
+
# The raw text
|
|
60
|
+
#: () -> String
|
|
61
|
+
def text
|
|
62
|
+
@parts.join(" ")
|
|
51
63
|
end
|
|
52
64
|
end
|
|
53
65
|
end
|
|
54
|
-
|
|
55
|
-
##
|
|
56
|
-
# Appends +texts+ onto this Paragraph
|
|
57
|
-
|
|
58
|
-
def push *texts
|
|
59
|
-
self.parts.concat texts
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
##
|
|
63
|
-
# The raw text
|
|
64
|
-
|
|
65
|
-
def text
|
|
66
|
-
@parts.join ' '
|
|
67
|
-
end
|
|
68
|
-
|
|
69
66
|
end
|
data/lib/rdoc/markup/table.rb
CHANGED
|
@@ -1,52 +1,60 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
##
|
|
3
|
-
# A section of table
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
module RDoc
|
|
4
|
+
class Markup
|
|
5
|
+
# A section of table
|
|
6
|
+
class Table < Element
|
|
7
|
+
# Headers of each column
|
|
8
|
+
#: Array[String]
|
|
9
|
+
attr_accessor :header
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
# Alignments of each column
|
|
12
|
+
#: Array[Symbol?]
|
|
13
|
+
attr_accessor :align
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
# Body texts of each column
|
|
16
|
+
#: Array[String]
|
|
17
|
+
attr_accessor :body
|
|
14
18
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
# :stopdoc:
|
|
21
|
-
def ==(other)
|
|
22
|
-
self.class == other.class and
|
|
23
|
-
@header == other.header and
|
|
24
|
-
@align == other.align and
|
|
25
|
-
@body == other.body
|
|
26
|
-
end
|
|
19
|
+
#: (Array[String], Array[Symbol?], Array[String]) -> void
|
|
20
|
+
def initialize(header, align, body)
|
|
21
|
+
@header, @align, @body = header, align, body
|
|
22
|
+
end
|
|
27
23
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
#: (Object) -> bool
|
|
25
|
+
def ==(other)
|
|
26
|
+
self.class == other.class && @header == other.header &&
|
|
27
|
+
@align == other.align && @body == other.body
|
|
28
|
+
end
|
|
31
29
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
q.pp text
|
|
37
|
-
if align
|
|
38
|
-
q.text ":"
|
|
39
|
-
q.breakable
|
|
40
|
-
q.text align.to_s
|
|
41
|
-
end
|
|
42
|
-
end
|
|
30
|
+
# @override
|
|
31
|
+
#: (untyped) -> void
|
|
32
|
+
def accept(visitor)
|
|
33
|
+
visitor.accept_table(@header, @body, @align)
|
|
43
34
|
end
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
35
|
+
|
|
36
|
+
# @override
|
|
37
|
+
#: (untyped) -> String
|
|
38
|
+
def pretty_print(q)
|
|
39
|
+
q.group 2, '[Table: ', ']' do
|
|
40
|
+
q.group 2, '[Head: ', ']' do
|
|
41
|
+
q.seplist @header.zip(@align) do |text, align|
|
|
49
42
|
q.pp text
|
|
43
|
+
if align
|
|
44
|
+
q.text ":"
|
|
45
|
+
q.breakable
|
|
46
|
+
q.text align.to_s
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
q.breakable
|
|
51
|
+
q.group 2, '[Body: ', ']' do
|
|
52
|
+
q.seplist @body do |body|
|
|
53
|
+
q.group 2, '[', ']' do
|
|
54
|
+
q.seplist body do |text|
|
|
55
|
+
q.pp text
|
|
56
|
+
end
|
|
57
|
+
end
|
|
50
58
|
end
|
|
51
59
|
end
|
|
52
60
|
end
|
data/lib/rdoc/markup/to_html.rb
CHANGED
|
@@ -221,10 +221,15 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|
|
221
221
|
|
|
222
222
|
def accept_verbatim(verbatim)
|
|
223
223
|
text = verbatim.text.rstrip
|
|
224
|
+
format = verbatim.format
|
|
224
225
|
|
|
225
226
|
klass = nil
|
|
226
227
|
|
|
227
|
-
|
|
228
|
+
# Apply Ruby syntax highlighting if
|
|
229
|
+
# - explicitly marked as Ruby (via ruby? which accepts :ruby or :rb)
|
|
230
|
+
# - no format specified but the text is parseable as Ruby
|
|
231
|
+
# Otherwise, add language class when applicable and skip Ruby highlighting
|
|
232
|
+
content = if verbatim.ruby? || (format.nil? && parseable?(text))
|
|
228
233
|
begin
|
|
229
234
|
tokens = RDoc::Parser::RipperStateLex.parse text
|
|
230
235
|
klass = ' class="ruby"'
|
|
@@ -236,6 +241,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|
|
236
241
|
CGI.escapeHTML text
|
|
237
242
|
end
|
|
238
243
|
else
|
|
244
|
+
klass = " class=\"#{format}\"" if format
|
|
239
245
|
CGI.escapeHTML text
|
|
240
246
|
end
|
|
241
247
|
|
|
@@ -306,6 +312,13 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|
|
306
312
|
level = [6, heading.level].min
|
|
307
313
|
|
|
308
314
|
label = heading.label @code_object
|
|
315
|
+
legacy_label = heading.legacy_label @code_object
|
|
316
|
+
|
|
317
|
+
# Add legacy anchor before the heading for backward compatibility.
|
|
318
|
+
# This allows old links with label- prefix to still work.
|
|
319
|
+
if @options.output_decoration && !@options.pipe
|
|
320
|
+
@res << "\n<span id=\"#{legacy_label}\" class=\"legacy-anchor\"></span>"
|
|
321
|
+
end
|
|
309
322
|
|
|
310
323
|
@res << if @options.output_decoration
|
|
311
324
|
"\n<h#{level} id=\"#{label}\">"
|
|
@@ -362,14 +375,18 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|
|
362
375
|
end
|
|
363
376
|
|
|
364
377
|
##
|
|
365
|
-
#
|
|
366
|
-
#
|
|
378
|
+
# Generates an HTML link or image tag for the given +url+ and +text+.
|
|
379
|
+
#
|
|
380
|
+
# - Image URLs (http/https/link ending in .gif, .png, .jpg, .jpeg, .bmp)
|
|
381
|
+
# become <img> tags
|
|
382
|
+
# - File references (.rb, .rdoc, .md) are converted to .html paths
|
|
383
|
+
# - Anchor URLs (#foo) pass through unchanged for GitHub-style header linking
|
|
384
|
+
# - Footnote links get wrapped in <sup> tags
|
|
367
385
|
|
|
368
386
|
def gen_url(url, text)
|
|
369
387
|
scheme, url, id = parse_url url
|
|
370
388
|
|
|
371
|
-
if %w[http https link].include?(scheme)
|
|
372
|
-
url =~ /\.(gif|png|jpg|jpeg|bmp)$/ then
|
|
389
|
+
if %w[http https link].include?(scheme) && url =~ /\.(gif|png|jpg|jpeg|bmp)\z/
|
|
373
390
|
"<img src=\"#{url}\" />"
|
|
374
391
|
else
|
|
375
392
|
if scheme != 'link' and %r%\A((?!https?:)(?:[^/#]*/)*+)([^/#]+)\.(rb|rdoc|md)(?=\z|#)%i =~ url
|
|
@@ -381,9 +398,11 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|
|
381
398
|
|
|
382
399
|
link = "<a#{id} href=\"#{url}\">#{text}</a>"
|
|
383
400
|
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
401
|
+
if /"foot/.match?(id)
|
|
402
|
+
"<sup>#{link}</sup>"
|
|
403
|
+
else
|
|
404
|
+
link
|
|
405
|
+
end
|
|
387
406
|
end
|
|
388
407
|
end
|
|
389
408
|
|
|
@@ -400,9 +419,10 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|
|
400
419
|
# Maps attributes to HTML tags
|
|
401
420
|
|
|
402
421
|
def init_tags
|
|
403
|
-
add_tag :BOLD,
|
|
404
|
-
add_tag :TT,
|
|
405
|
-
add_tag :EM,
|
|
422
|
+
add_tag :BOLD, "<strong>", "</strong>"
|
|
423
|
+
add_tag :TT, "<code>", "</code>"
|
|
424
|
+
add_tag :EM, "<em>", "</em>"
|
|
425
|
+
add_tag :STRIKE, "<del>", "</del>"
|
|
406
426
|
end
|
|
407
427
|
|
|
408
428
|
##
|
|
@@ -169,14 +169,33 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
|
|
|
169
169
|
end
|
|
170
170
|
|
|
171
171
|
if label
|
|
172
|
+
# Convert label to GitHub-style anchor format
|
|
173
|
+
# First convert + to space (URL encoding), then apply GitHub-style rules
|
|
174
|
+
formatted_label = RDoc::Text.to_anchor(label.tr('+', ' '))
|
|
175
|
+
|
|
176
|
+
# Case 1: Path already has an anchor (e.g., method link)
|
|
177
|
+
# Input: C1#method@label -> path="C1.html#method-i-m"
|
|
178
|
+
# Output: C1.html#method-i-m-label
|
|
172
179
|
if path =~ /#/
|
|
173
|
-
path << "
|
|
174
|
-
|
|
175
|
-
|
|
180
|
+
path << "-#{formatted_label}"
|
|
181
|
+
|
|
182
|
+
# Case 2: Label matches a section title
|
|
183
|
+
# Input: C1@Section -> path="C1.html", section "Section" exists
|
|
184
|
+
# Output: C1.html#section (uses section.aref for GitHub-style)
|
|
185
|
+
elsif (section = ref&.sections&.find { |s| label.tr('+', ' ') == s.title })
|
|
186
|
+
path << "##{section.aref}"
|
|
187
|
+
|
|
188
|
+
# Case 3: Ref has an aref (class/module context)
|
|
189
|
+
# Input: C1@heading -> path="C1.html", ref=C1 class
|
|
190
|
+
# Output: C1.html#class-c1-heading
|
|
176
191
|
elsif ref.respond_to?(:aref)
|
|
177
|
-
path << "##{ref.aref}
|
|
192
|
+
path << "##{ref.aref}-#{formatted_label}"
|
|
193
|
+
|
|
194
|
+
# Case 4: No context, just the label (e.g., TopLevel/file)
|
|
195
|
+
# Input: README@section -> path="README_md.html"
|
|
196
|
+
# Output: README_md.html#section
|
|
178
197
|
else
|
|
179
|
-
path << "
|
|
198
|
+
path << "##{formatted_label}"
|
|
180
199
|
end
|
|
181
200
|
end
|
|
182
201
|
|
data/lib/rdoc/markup/to_label.rb
CHANGED
|
@@ -28,11 +28,21 @@ class RDoc::Markup::ToLabel < RDoc::Markup::Formatter
|
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
##
|
|
31
|
-
# Converts +text+ to an HTML-safe label
|
|
31
|
+
# Converts +text+ to an HTML-safe label using GitHub-style anchor formatting.
|
|
32
32
|
|
|
33
33
|
def convert(text)
|
|
34
34
|
label = convert_flow @am.flow text
|
|
35
35
|
|
|
36
|
+
RDoc::Text.to_anchor(label)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
##
|
|
40
|
+
# Converts +text+ to an HTML-safe label using legacy RDoc formatting.
|
|
41
|
+
# Used for generating backward-compatible anchor aliases.
|
|
42
|
+
|
|
43
|
+
def convert_legacy(text)
|
|
44
|
+
label = convert_flow @am.flow text
|
|
45
|
+
|
|
36
46
|
CGI.escape(label).gsub('%', '-').sub(/^-/, '')
|
|
37
47
|
end
|
|
38
48
|
|
data/lib/rdoc/markup/verbatim.rb
CHANGED
data/lib/rdoc/markup.rb
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
#
|
|
17
17
|
# - +rdoc+:
|
|
18
18
|
# the +RDoc+ markup format;
|
|
19
|
-
# see RDoc
|
|
19
|
+
# see {RDoc Markup Reference}[rdoc-ref:doc/markup_reference/rdoc.rdoc]
|
|
20
20
|
# - +markdown+:
|
|
21
21
|
# The +markdown+ markup format as described in
|
|
22
22
|
# the {Markdown Guide}[https://www.markdownguide.org];
|
|
@@ -102,7 +102,7 @@
|
|
|
102
102
|
#
|
|
103
103
|
# = \RDoc Markup Reference
|
|
104
104
|
#
|
|
105
|
-
# See RDoc
|
|
105
|
+
# See {RDoc Markup Reference}[rdoc-ref:doc/markup_reference/rdoc.rdoc]
|
|
106
106
|
#
|
|
107
107
|
#--
|
|
108
108
|
# Original Author:: Dave Thomas, dave@pragmaticprogrammer.com
|
|
@@ -210,6 +210,7 @@ https://github.com/ruby/rdoc/issues
|
|
|
210
210
|
autoload :BlankLine, "#{__dir__}/markup/blank_line"
|
|
211
211
|
autoload :BlockQuote, "#{__dir__}/markup/block_quote"
|
|
212
212
|
autoload :Document, "#{__dir__}/markup/document"
|
|
213
|
+
autoload :Element, "#{__dir__}/markup/element"
|
|
213
214
|
autoload :HardBreak, "#{__dir__}/markup/hard_break"
|
|
214
215
|
autoload :Heading, "#{__dir__}/markup/heading"
|
|
215
216
|
autoload :Include, "#{__dir__}/markup/include"
|