rdoc-markdown 0.20.2 → 0.21.1

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: 867481b03e8cfa3279b67d5344e3d95dfed1c23b4a885cef33bf2cf0992d2df8
4
- data.tar.gz: f1bea8f39ecc1ccfdb9363c8c1071fa01099cf48596c1e4d90b01dee4cd000b1
3
+ metadata.gz: 5103b919452fc2a8143563d54ce1c2e7ab3e4aaf2afdfe44d6057fcce9a2e5c4
4
+ data.tar.gz: d8abe423253297371c5cb60c722bb24507c40d2a73ee9df37eca75a1b2dab60a
5
5
  SHA512:
6
- metadata.gz: 9eb94354e06c97eb71c9bf4defc1c4f4b7f62489d1ac5d9170cb2d091ab126f181b6f84457d9f2f78a324814ed417d78a9dba67f3d2a995cacfabc276cab3eba
7
- data.tar.gz: 2caa21c1f0968226a68dddfb115f9dd6c8750ed08db856fb94dce541100eb7b0c2fb36ef7da355f54f5b50e15129c9b65cd19ff5e0aa597e9a65c4a955eb2e33
6
+ metadata.gz: 3fa2a3b9e6cc98af9902d054f3ad4989e05639f9f55da4bd2d5e4f5a984d9e97833d1c4d06898439a00907ad783ec7329ad46c2c8ae614fcc46a001ceea444fd
7
+ data.tar.gz: dedabad24735933e97d59127de66271a2a628287822e626c6eb4c5bf9631c613c512a05a511918c4a84fed34bffa61dd29166716fe61ae4badf38fa3e9220deb
data/CHANGELOG.md CHANGED
@@ -1,6 +1,14 @@
1
1
  # Changelog
2
2
 
3
- ## Unreleased
3
+ ## 0.21.1
4
+
5
+ - Preserve hash-prefixed comments and literal Markdown headings in code examples when offsetting documentation headings.
6
+
7
+ ## 0.21.0
8
+ - Keep generated method and section headings readable after raw HTML descriptions.
9
+ - Validate search-index targets and same-document links against parsed Markdown headings and anchors, including alias targets.
10
+ - Leave alias targets unlinked when RDoc has removed the canonical method from the generated documentation.
11
+ - Preserve literal HTML, ERB templates, heredocs, and entity strings in code examples.
4
12
 
5
13
  ## 0.20.2
6
14
 
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
  ```
@@ -9,15 +9,13 @@ class RDoc::Generator::Markdown::Conversion
9
9
  #
10
10
  # @return [String] Markdown with normalized links and no trailing whitespace.
11
11
  def self.markdownify(input, heading_level_offset: 0)
12
- fragment = normalized_html_fragment(input)
12
+ fragment = normalized_html_fragment(input, heading_level_offset)
13
13
  anchor_aliases = tokenize_legacy_anchors(fragment.css("span.legacy-anchor[id]"))
14
14
  document = fragment.document
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
19
- "#{"#" * [Regexp.last_match(1).length + heading_level_offset, 6].min}#{Regexp.last_match(2)}"
20
- end
18
+ normalize_definition_lists(markdown).rstrip
21
19
  end
22
20
 
23
21
  class << self
@@ -26,9 +24,10 @@ class RDoc::Generator::Markdown::Conversion
26
24
  # Normalizes HTML constructs that reverse_markdown cannot preserve directly.
27
25
  #
28
26
  # @param input [String] RDoc HTML fragment.
27
+ # @param heading_level_offset [Integer] Heading levels to add to actual HTML headings.
29
28
  #
30
29
  # @return [Nokogiri::HTML4::DocumentFragment] Normalized fragment.
31
- def normalized_html_fragment(input)
30
+ def normalized_html_fragment(input, heading_level_offset)
32
31
  fragment = Nokogiri::HTML.fragment(input)
33
32
  context_anchors, content_anchors = fragment.css("span.legacy-anchor[id]").partition do |span|
34
33
  context_anchor?(span)
@@ -41,7 +40,7 @@ class RDoc::Generator::Markdown::Conversion
41
40
  normalize_pre_blocks(fragment)
42
41
  document = fragment.document
43
42
  fragment.css("h1, h2, h3, h4, h5, h6").each do |heading|
44
- normalize_heading_link(heading, document)
43
+ normalize_heading(heading, document, heading_level_offset)
45
44
  end
46
45
  fragment
47
46
  end
@@ -64,17 +63,19 @@ class RDoc::Generator::Markdown::Conversion
64
63
  fragment.css("pre").each do |pre|
65
64
  language = pre["class"].to_s[/\A(?!highlight\z)[A-Za-z][A-Za-z0-9_+-]*\z/]
66
65
  pre["class"] = "brush: #{language};" if language
67
- pre.inner_html = pre.text
66
+ pre.content = pre.text
68
67
  end
69
68
  end
70
69
 
71
- # Normalizes one heading's leading fragment link.
70
+ # Normalizes one heading's level and leading fragment link.
72
71
  #
73
72
  # @param heading [Nokogiri::XML::Element] Heading element.
74
73
  # @param document [Nokogiri::HTML4::Document] Owning document.
74
+ # @param heading_level_offset [Integer] Heading levels to add, capped at six.
75
75
  #
76
76
  # @return [void]
77
- def normalize_heading_link(heading, document)
77
+ def normalize_heading(heading, document, heading_level_offset)
78
+ heading.name = "h#{[Integer(heading.name.delete_prefix("h")) + heading_level_offset, 6].min}"
78
79
  link = heading.xpath("./a[starts-with(@href, '#') and string-length(@href) > 1]").find do |anchor|
79
80
  leading_heading_link?(anchor)
80
81
  end
@@ -152,14 +153,17 @@ class RDoc::Generator::Markdown::Conversion
152
153
  .sub(%r{\A((?:\.\./)*)(?:files|classes|modules)/(?=.+\.md(?:[?#]|\z))}, '\1')
153
154
  end
154
155
 
155
- # Converts RDoc definition-list code blocks into Markdown lists.
156
+ # Converts RDoc definition-list code blocks into Markdown lists and separates
157
+ # raw HTML lists from following Markdown without rewriting fenced examples.
156
158
  #
157
159
  # @param markdown [String] Markdown content.
158
160
  #
159
- # @return [String] Markdown with convertible blocks normalized.
160
- def normalize_definition_list_code_blocks(markdown)
161
- markdown.gsub(/```[^\n]*\n(.+?)\n```/m) do
161
+ # @return [String] Markdown with definition lists normalized.
162
+ def normalize_definition_lists(markdown)
163
+ markdown.gsub(%r{```[^\n]*\n(.+?)\n```|</dl>\n(?=\S)}m) do
162
164
  body = Regexp.last_match(1)
165
+ next "</dl>\n\n" unless body
166
+
163
167
  converted = convert_definition_list_block(body)
164
168
  converted || Regexp.last_match
165
169
  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
 
@@ -5,6 +5,6 @@ module Rdoc
5
5
  # @private
6
6
  module Markdown
7
7
  # @private
8
- VERSION = "0.20.2"
8
+ VERSION = "0.21.1"
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,6 +62,7 @@
61
62
 
62
63
  <%= "#" * group_heading_level %> <%= visibility.capitalize %> <%= type.capitalize %> Methods
63
64
  <% methods.each do |method| -%>
65
+
64
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 -%>
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.2
4
+ version: 0.21.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stanislav (Stas) Katkov