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 +4 -4
- data/CHANGELOG.md +9 -1
- data/README.md +6 -0
- data/lib/rdoc/generator/markdown/conversion.rb +17 -13
- data/lib/rdoc/generator/markdown/descriptions.rb +3 -1
- data/lib/rdoc/markdown/version.rb +1 -1
- data/lib/templates/classfile.md.erb +2 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5103b919452fc2a8143563d54ce1c2e7ab3e4aaf2afdfe44d6057fcce9a2e5c4
|
|
4
|
+
data.tar.gz: d8abe423253297371c5cb60c722bb24507c40d2a73ee9df37eca75a1b2dab60a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3fa2a3b9e6cc98af9902d054f3ad4989e05639f9f55da4bd2d5e4f5a984d9e97833d1c4d06898439a00907ad783ec7329ad46c2c8ae614fcc46a001ceea444fd
|
|
7
|
+
data.tar.gz: dedabad24735933e97d59127de66271a2a628287822e626c6eb4c5bf9631c613c512a05a511918c4a84fed34bffa61dd29166716fe61ae4badf38fa3e9220deb
|
data/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
##
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
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
|
|
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
|
|
160
|
-
def
|
|
161
|
-
markdown.gsub(
|
|
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
|
|
|
@@ -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 -%>
|