rdoc-markdown 0.21.0 → 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: 8b215eca69feb6c88372f2a84436dff0c42712e0f3deb7086c91e9ee1f0e8cd3
4
- data.tar.gz: 3ce6ccaeecfd189da39207c07e6f6733c5f183589eb90a3474ea3316b80c0445
3
+ metadata.gz: 5103b919452fc2a8143563d54ce1c2e7ab3e4aaf2afdfe44d6057fcce9a2e5c4
4
+ data.tar.gz: d8abe423253297371c5cb60c722bb24507c40d2a73ee9df37eca75a1b2dab60a
5
5
  SHA512:
6
- metadata.gz: 5cc5f170e0eae86a2f5ba510db36fb9f1bf5b1eca91d7b3a31fb95f1a0b2188ff8d1b48892fb98c65bfa2b7b46e9d80cbe5c852595e540f214204d0a9d3c936f
7
- data.tar.gz: 3df4e291559a57ca7cf727e1e59b60ae8c292cd6defadb7a0c8cef91e1bd56f504e8ab9072d75a9978658efd19b8a0613b7884352ce57cd7cd5d67143762f322
6
+ metadata.gz: 3fa2a3b9e6cc98af9902d054f3ad4989e05639f9f55da4bd2d5e4f5a984d9e97833d1c4d06898439a00907ad783ec7329ad46c2c8ae614fcc46a001ceea444fd
7
+ data.tar.gz: dedabad24735933e97d59127de66271a2a628287822e626c6eb4c5bf9631c613c512a05a511918c4a84fed34bffa61dd29166716fe61ae4badf38fa3e9220deb
data/CHANGELOG.md CHANGED
@@ -1,7 +1,10 @@
1
1
  # Changelog
2
2
 
3
- ## Unreleased
3
+ ## 0.21.1
4
4
 
5
+ - Preserve hash-prefixed comments and literal Markdown headings in code examples when offsetting documentation headings.
6
+
7
+ ## 0.21.0
5
8
  - Keep generated method and section headings readable after raw HTML descriptions.
6
9
  - Validate search-index targets and same-document links against parsed Markdown headings and anchors, including alias targets.
7
10
  - Leave alias targets unlinked when RDoc has removed the canonical method from the generated documentation.
@@ -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_lists(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
@@ -68,13 +67,15 @@ class RDoc::Generator::Markdown::Conversion
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
@@ -5,6 +5,6 @@ module Rdoc
5
5
  # @private
6
6
  module Markdown
7
7
  # @private
8
- VERSION = "0.21.0"
8
+ VERSION = "0.21.1"
9
9
  end
10
10
  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.21.0
4
+ version: 0.21.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stanislav (Stas) Katkov