rdoc-markdown 0.20.1 → 0.21.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5ae68a40db5d99f60034820bab835a6a6d17c9db00dd3d38d3d47bd7da73743b
4
- data.tar.gz: 65a59f988b16411b5914dc5d7de8496efac2a12a67b835ac50b9fa478c1492fd
3
+ metadata.gz: 8b215eca69feb6c88372f2a84436dff0c42712e0f3deb7086c91e9ee1f0e8cd3
4
+ data.tar.gz: 3ce6ccaeecfd189da39207c07e6f6733c5f183589eb90a3474ea3316b80c0445
5
5
  SHA512:
6
- metadata.gz: c8c080f1704dff5d1a4ca256676fbf5f1a69d51a9ec0223e952cceb37837f840274a2bb39e44c70801379ef72d7a70d3811e96810de1d5a568341f6ec2a74875
7
- data.tar.gz: 10a07e634578b0ac0290d91e4b1f52f6af36e0cb30349fa8d519970020b55246e719dec427f64c8ad59f6505def782e8709e98b6ff4be01f5494637af5cb265c
6
+ metadata.gz: 5cc5f170e0eae86a2f5ba510db36fb9f1bf5b1eca91d7b3a31fb95f1a0b2188ff8d1b48892fb98c65bfa2b7b46e9d80cbe5c852595e540f214204d0a9d3c936f
7
+ data.tar.gz: 3df4e291559a57ca7cf727e1e59b60ae8c292cd6defadb7a0c8cef91e1bd56f504e8ab9072d75a9978658efd19b8a0613b7884352ce57cd7cd5d67143762f322
data/CHANGELOG.md CHANGED
@@ -2,6 +2,15 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ - Keep generated method and section headings readable after raw HTML descriptions.
6
+ - Validate search-index targets and same-document links against parsed Markdown headings and anchors, including alias targets.
7
+ - Leave alias targets unlinked when RDoc has removed the canonical method from the generated documentation.
8
+ - Preserve literal HTML, ERB templates, heredocs, and entity strings in code examples.
9
+
10
+ ## 0.20.2
11
+
12
+ - Preserve documented bracket lookup and assignment arguments in method headings without changing their anchors.
13
+
5
14
  ## 0.20.1
6
15
 
7
16
  - Don't offset headings for commets
data/README.md CHANGED
@@ -60,6 +60,12 @@ To validate generated markdown against GitHub Flavored Markdown and check local
60
60
  rake markdown:validate
61
61
  ```
62
62
 
63
+ Validation also checks same-document fragment links and every `index.csv` target.
64
+ Indexed fragments and method/attribute links must point to parsed Markdown heading
65
+ sections: an anchor appearing only in a code example or a raw HTML block is not
66
+ enough. This catches method headings swallowed by an unterminated Markdown HTML
67
+ block, including aliases that link back to those methods.
68
+
63
69
  To lint markdown ERB templates:
64
70
 
65
71
  ```
@@ -15,7 +15,7 @@ class RDoc::Generator::Markdown::Conversion
15
15
  fragment.css("a").each { |link| normalize_link(link, document) }
16
16
  markdown = ReverseMarkdown.convert(fragment, github_flavored: true).dup
17
17
  markdown.gsub!(Regexp.union(anchor_aliases.keys), anchor_aliases)
18
- normalize_definition_list_code_blocks(markdown).rstrip.gsub(/^(#+)(\s)/) do
18
+ normalize_definition_lists(markdown).rstrip.gsub(/^(#+)(\s)/) do
19
19
  "#{"#" * [Regexp.last_match(1).length + heading_level_offset, 6].min}#{Regexp.last_match(2)}"
20
20
  end
21
21
  end
@@ -64,7 +64,7 @@ class RDoc::Generator::Markdown::Conversion
64
64
  fragment.css("pre").each do |pre|
65
65
  language = pre["class"].to_s[/\A(?!highlight\z)[A-Za-z][A-Za-z0-9_+-]*\z/]
66
66
  pre["class"] = "brush: #{language};" if language
67
- pre.inner_html = pre.text
67
+ pre.content = pre.text
68
68
  end
69
69
  end
70
70
 
@@ -152,14 +152,17 @@ class RDoc::Generator::Markdown::Conversion
152
152
  .sub(%r{\A((?:\.\./)*)(?:files|classes|modules)/(?=.+\.md(?:[?#]|\z))}, '\1')
153
153
  end
154
154
 
155
- # Converts RDoc definition-list code blocks into Markdown lists.
155
+ # Converts RDoc definition-list code blocks into Markdown lists and separates
156
+ # raw HTML lists from following Markdown without rewriting fenced examples.
156
157
  #
157
158
  # @param markdown [String] Markdown content.
158
159
  #
159
- # @return [String] Markdown with convertible blocks normalized.
160
- def normalize_definition_list_code_blocks(markdown)
161
- markdown.gsub(/```[^\n]*\n(.+?)\n```/m) do
160
+ # @return [String] Markdown with definition lists normalized.
161
+ def normalize_definition_lists(markdown)
162
+ markdown.gsub(%r{```[^\n]*\n(.+?)\n```|</dl>\n(?=\S)}m) do
162
163
  body = Regexp.last_match(1)
164
+ next "</dl>\n\n" unless body
165
+
163
166
  converted = convert_definition_list_block(body)
164
167
  converted || Regexp.last_match
165
168
  end
@@ -149,11 +149,13 @@ module RDoc::Generator::Markdown::Descriptions
149
149
  # @param method [RDoc::AnyMethod] Target method.
150
150
  # @param current_class [RDoc::Context] Class or module currently being rendered.
151
151
  #
152
- # @return [String, nil] Anchor or relative Markdown link target, or nil when the target page is omitted.
152
+ # @return [String, nil] Anchor or relative Markdown link target, or nil when the target method or page is omitted.
153
153
  def method_link(method, current_class:)
154
154
  return unless method.display?
155
155
 
156
156
  target_parent = method.parent
157
+ return unless target_parent.method_list.include?(method)
158
+
157
159
  target_path = generation_state.class_output_paths[target_parent.full_name]
158
160
  return unless target_path
159
161
 
@@ -11,34 +11,54 @@ module RDoc::Generator::Markdown::Signatures
11
11
  #
12
12
  # @param method [RDoc::AnyMethod] Method object to render.
13
13
  #
14
- # @return [String] Normalized method signature.
14
+ # @return [String] Complete signature including the method name or documented receiver.
15
15
  def method_signature(method)
16
16
  RDoc::Generator::Markdown::Signatures.render_method_signature(method, store)
17
17
  end
18
18
 
19
19
  private :method_signature
20
20
 
21
- # Builds a method signature from RDoc and store metadata.
21
+ # Builds a complete method heading signature from RDoc and store metadata.
22
22
  #
23
23
  # @param method [RDoc::AnyMethod] Method object to render.
24
24
  # @param store [RDoc::Store] Documentation store with sidecar signatures.
25
25
  #
26
- # @return [String] Normalized method signature.
26
+ # @return [String] Complete signature including the method name or documented receiver.
27
27
  def self.render_method_signature(method, store)
28
- signatures = method.type_signature_lines || store.rbs_signature_for(method) || [method.param_seq]
28
+ signatures = method.type_signature_lines || store.rbs_signature_for(method)
29
+ if !signatures && (call_seq = bracket_call_sequence(method))
30
+ return call_seq.lines.map { |line| normalize_signature(line) }.join(" | ")
31
+ end
32
+ signatures ||= [method.param_seq]
29
33
 
30
34
  signatures = signatures.filter_map do |signature|
31
35
  next unless signature&.match?(/\S/)
32
36
 
33
- signature = signature.gsub("->", " -> ")
34
- signature = signature.gsub(/\s+/, " ").strip
37
+ signature = normalize_signature(signature)
35
38
  signature = " #{signature}" if signature.start_with?("->")
36
39
  merge_method_signature_arguments(signature, method.params)
37
40
  end
38
41
 
39
- return "()" if signatures.empty?
42
+ signature = signatures.empty? ? "()" : signatures.join(" | ")
43
+ "#{method.name}#{signature}"
44
+ end
40
45
 
41
- signatures.join(" | ")
46
+ # Returns the original call syntax for bracket operators, when documented.
47
+ #
48
+ # @param method [RDoc::AnyMethod] Method object to render.
49
+ #
50
+ # @return [String, nil] Documented bracket calls, or nil for other signatures.
51
+ def self.bracket_call_sequence(method)
52
+ method.call_seq if ["[]", "[]="].include?(method.name)
53
+ end
54
+
55
+ # Normalizes spacing in a signature without changing its call syntax.
56
+ #
57
+ # @param signature [String] Signature or complete call sequence.
58
+ #
59
+ # @return [String] Signature with consistent arrow and whitespace formatting.
60
+ def self.normalize_signature(signature)
61
+ signature.gsub("->", " -> ").gsub(/\s+/, " ").strip
42
62
  end
43
63
 
44
64
  # Merges RDoc parameter names into a type-only signature.
@@ -5,6 +5,6 @@ module Rdoc
5
5
  # @private
6
6
  module Markdown
7
7
  # @private
8
- VERSION = "0.20.1"
8
+ VERSION = "0.21.0"
9
9
  end
10
10
  end
@@ -29,6 +29,7 @@
29
29
  <%- group_heading_level = section_heading_level + 1 -%>
30
30
  <%- member_heading_level = group_heading_level + 1 -%>
31
31
  <%- unless section_title.empty? -%>
32
+
32
33
  <%= "#" * section_heading_level %> <%= section_title %>
33
34
  <%- end -%>
34
35
  <%- section_description = section_description(section, heading_level_offset: section_heading_level) -%>
@@ -61,7 +62,8 @@
61
62
 
62
63
  <%= "#" * group_heading_level %> <%= visibility.capitalize %> <%= type.capitalize %> Methods
63
64
  <% methods.each do |method| -%>
64
- <%= "#" * member_heading_level %> `<%= method.name %><%= method_signature(method) %>`<%= anchor(method.aref) %>
65
+
66
+ <%= "#" * member_heading_level %> `<%= method_signature(method) %>`<%= anchor(method.aref) %>
65
67
  <%= method_description(method, current_class: klass, heading_level_offset: member_heading_level) %>
66
68
  <% end -%>
67
69
  <% end -%>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdoc-markdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.20.1
4
+ version: 0.21.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stanislav (Stas) Katkov