yard-markdown 0.8.0 → 0.9.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/CHANGELOG.md +4 -0
- data/README.md +18 -4
- data/lib/yard/markdown/link_normalization_helper.rb +6 -13
- data/lib/yard/markdown/metadata_section_helper.rb +1 -1
- data/lib/yard/markdown/yardoc_extension.rb +30 -0
- data/lib/yard/markdown.rb +8 -0
- data/lib/yard-markdown.rb +3 -5
- data/templates/default/fulldoc/markdown/setup.rb +12 -2
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 756196562ff8a2cafba54128de039d2f10fffd93816a9fc0abdad8130805e124
|
|
4
|
+
data.tar.gz: 3a6f3bdfd92a9a95e632dac284f33151e89c26a1be283deac463f600971774a6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 04ea8878df7097ebf384ae8c45110c01036af65ce2004710c3f0c40fc20eb4cc8ccabec5f0dd4877c5abbf8c3305f7b42caa66581c4f884848b389d9106218d8
|
|
7
|
+
data.tar.gz: ef8e21cb4d98c319f37eab85291ecd69e808c3c074909adee7376d0fb7ab79e3d62436d86b082c69ef6777fa1eb7706ce9088cd39d648e8fe53fa00daa1ee7f7
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -19,6 +19,20 @@ gem install yard-markdown
|
|
|
19
19
|
|
|
20
20
|
Run `yardoc --format=markdown` to generate markdown documentation.
|
|
21
21
|
|
|
22
|
+
Markdown files in the project tree are detected automatically, copied unchanged into the output, and listed in `index.csv`:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
yardoc --format=markdown
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Markdown files whose basename starts with `_` are ignored automatically.
|
|
29
|
+
|
|
30
|
+
Use YARD's `--exclude` option to omit a separate documentation tree:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
yardoc --format=markdown --exclude '\Adocs/'
|
|
34
|
+
```
|
|
35
|
+
|
|
22
36
|
## FAQ
|
|
23
37
|
|
|
24
38
|
### Note on RDoc support
|
|
@@ -66,14 +80,14 @@ Validate generated markdown in sample docs:
|
|
|
66
80
|
bundle exec rake markdown:validate_examples
|
|
67
81
|
```
|
|
68
82
|
|
|
69
|
-
There is also a real-world validation harness for repositories with substantial YARD documentation (`
|
|
83
|
+
There is also a real-world validation harness for repositories with substantial YARD documentation (`faraday`, `sidekiq`):
|
|
70
84
|
|
|
71
85
|
```bash
|
|
72
86
|
bundle exec rake markdown:validate_real_world
|
|
73
87
|
```
|
|
74
88
|
|
|
75
|
-
This task validates generated
|
|
89
|
+
This task validates every generated Markdown file against CommonMark and GFM. Generated files must have valid local links and anchors; unresolved links and anchors in byte-identical Markdown copied from upstream are reported instead of failing validation.
|
|
76
90
|
|
|
77
|
-
GitHub Actions CI
|
|
91
|
+
GitHub Actions CI runs this task on every push/PR, so both real-world fixture gems are verified continuously.
|
|
78
92
|
|
|
79
|
-
For reproducible checks, the task clones pinned tags (`
|
|
93
|
+
For reproducible checks, the task clones pinned tags (`faraday` `v2.14.3`, `sidekiq` `v7.3.10`) into `tmp/real-world/repos` and honors each repository's `.yardopts` before generating output in `tmp/real-world/faraday` and `tmp/real-world/sidekiq`.
|
|
@@ -13,7 +13,6 @@ module YARD
|
|
|
13
13
|
output = content.instance_of?(Array) ? content.join("\n") : content
|
|
14
14
|
output = output.lines.map(&:rstrip).join("\n")
|
|
15
15
|
output = normalize_local_links(output, current_path)
|
|
16
|
-
output = normalize_malformed_local_links(output)
|
|
17
16
|
output = output.gsub(/\n{3,}/, "\n\n").strip
|
|
18
17
|
"#{output}\n"
|
|
19
18
|
end
|
|
@@ -83,12 +82,16 @@ module YARD
|
|
|
83
82
|
return relative_output_path(current_dir, object_path)
|
|
84
83
|
end
|
|
85
84
|
|
|
85
|
+
alias_path = Pathname.new(normalized.sub(/\.html\z/i, "")).cleanpath.to_s
|
|
86
|
+
copied_path = options.copied_file_aliases[alias_path]
|
|
87
|
+
return relative_output_path(current_dir, copied_path) if copied_path
|
|
88
|
+
|
|
86
89
|
if normalized.match?(/\.html\z/i)
|
|
87
90
|
normalized = normalized.sub(/\.html\z/i, ".md")
|
|
88
91
|
elsif File.extname(normalized).empty?
|
|
89
92
|
return nil if unresolved_identifier_target?(normalized)
|
|
90
93
|
|
|
91
|
-
normalized = "#{normalized}.md"
|
|
94
|
+
normalized = "#{normalized}.md"
|
|
92
95
|
end
|
|
93
96
|
|
|
94
97
|
relative_output_path(current_dir, normalized)
|
|
@@ -111,9 +114,7 @@ module YARD
|
|
|
111
114
|
# @return [Boolean] True when the target should be treated as unresolved.
|
|
112
115
|
def unresolved_identifier_target?(path)
|
|
113
116
|
cleaned = path.sub(%r{\A(?:(?:\.\./)+|\./)}, "")
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
cleaned.match?(/\A[a-z_]\w*\z/)
|
|
117
|
+
File.extname(cleaned).empty? && !cleaned.include?("/")
|
|
117
118
|
end
|
|
118
119
|
|
|
119
120
|
# Computes a relative path from the current output directory.
|
|
@@ -129,14 +130,6 @@ module YARD
|
|
|
129
130
|
rescue
|
|
130
131
|
target
|
|
131
132
|
end
|
|
132
|
-
|
|
133
|
-
# Replaces malformed local Markdown links with inline code.
|
|
134
|
-
#
|
|
135
|
-
# @param markdown [String] Markdown content to normalize.
|
|
136
|
-
# @return [String] Markdown with malformed local links replaced.
|
|
137
|
-
def normalize_malformed_local_links(markdown)
|
|
138
|
-
markdown.gsub(%r{\[([^\]]+)\]\((?!https?://|mailto:|#)(?:[^)\n]*['"][^)\n]*)\)}, '`\1`')
|
|
139
|
-
end
|
|
140
133
|
end
|
|
141
134
|
end
|
|
142
135
|
end
|
|
@@ -36,7 +36,7 @@ module YARD
|
|
|
36
36
|
# @return [String] Markdown link or plain table-cell text.
|
|
37
37
|
def metadata_reference(target)
|
|
38
38
|
label = metadata_table_cell(target.path)
|
|
39
|
-
return label unless target.is_a?(CodeObjects::
|
|
39
|
+
return label unless target.is_a?(CodeObjects::NamespaceObject) && run_verifier([target]).any?
|
|
40
40
|
|
|
41
41
|
"[#{label}](#{target.path})"
|
|
42
42
|
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module YARD
|
|
4
|
+
module Markdown
|
|
5
|
+
# Discovers Markdown pages before YARD generates documentation.
|
|
6
|
+
module YardocExtension
|
|
7
|
+
private
|
|
8
|
+
|
|
9
|
+
# Adds Markdown pages to the files rendered by the Markdown template.
|
|
10
|
+
#
|
|
11
|
+
# @param checksums [Hash, nil] Previously generated file checksums.
|
|
12
|
+
# @return [void]
|
|
13
|
+
def run_generate(checksums)
|
|
14
|
+
if options.format == :markdown
|
|
15
|
+
existing = options.files.map { |file| File.expand_path(file.filename) }
|
|
16
|
+
exclusions = excluded.map { |path| Regexp.new(path, Regexp::IGNORECASE) }
|
|
17
|
+
output = File.expand_path(options.serializer.basepath)
|
|
18
|
+
markdown_files = Dir.glob("**/*").grep(FILE_PATTERN)
|
|
19
|
+
.reject { |file| File.basename(file).start_with?("_") }
|
|
20
|
+
.reject { |file| exclusions.any? { |pattern| pattern.match?(file) } }
|
|
21
|
+
.reject { |file| File.expand_path(file).start_with?("#{output}/") }
|
|
22
|
+
.reject { |file| existing.include?(File.expand_path(file)) }
|
|
23
|
+
add_extra_files(markdown_files)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
super
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
data/lib/yard-markdown.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "yard"
|
|
4
|
+
require_relative "yard/markdown"
|
|
4
5
|
require_relative "yard/markdown/aref_helper"
|
|
5
6
|
require_relative "yard/markdown/collection_rendering_helper"
|
|
6
7
|
require_relative "yard/markdown/documentation_helper"
|
|
@@ -11,10 +12,7 @@ require_relative "yard/markdown/method_presentation_helper"
|
|
|
11
12
|
require_relative "yard/markdown/object_listing_helper"
|
|
12
13
|
require_relative "yard/markdown/section_assembly_helper"
|
|
13
14
|
require_relative "yard/markdown/tag_formatting_helper"
|
|
14
|
-
|
|
15
|
-
module YARD
|
|
16
|
-
module Markdown
|
|
17
|
-
end
|
|
18
|
-
end
|
|
15
|
+
require_relative "yard/markdown/yardoc_extension"
|
|
19
16
|
|
|
20
17
|
YARD::Templates::Engine.register_template_path File.dirname(__FILE__) + "/../templates"
|
|
18
|
+
YARD::CLI::Yardoc.prepend(YARD::Markdown::YardocExtension)
|
|
@@ -11,12 +11,19 @@ include YARD::Markdown::ObjectListingHelper,
|
|
|
11
11
|
# @return [void]
|
|
12
12
|
def init
|
|
13
13
|
options.objects = objects = run_verifier(options.objects).reject { |item| item.name == :root }
|
|
14
|
+
files = Array(options.files).select { |file| file.filename.match?(YARD::Markdown::FILE_PATTERN) }
|
|
15
|
+
options.copied_file_aliases = files.to_h do |file|
|
|
16
|
+
path = Pathname.new(file.filename).cleanpath.to_s
|
|
17
|
+
[path.sub(YARD::Markdown::FILE_PATTERN, ""), path]
|
|
18
|
+
end
|
|
14
19
|
|
|
15
20
|
options.delete(:objects)
|
|
16
21
|
options.delete(:files)
|
|
17
22
|
|
|
18
23
|
options.serializer.extension = "md"
|
|
19
24
|
|
|
25
|
+
files.each { |file| options.serializer.serialize(file.filename, File.binread(file.filename)) }
|
|
26
|
+
|
|
20
27
|
objects.each do |object|
|
|
21
28
|
Templates::Engine.with_serializer(object, options.serializer) { serialize(object) }
|
|
22
29
|
rescue => e
|
|
@@ -25,7 +32,7 @@ def init
|
|
|
25
32
|
log.backtrace(e)
|
|
26
33
|
end
|
|
27
34
|
|
|
28
|
-
serialize_index(objects)
|
|
35
|
+
serialize_index(objects, files)
|
|
29
36
|
end
|
|
30
37
|
|
|
31
38
|
# Renders the markdown template for a single namespace object.
|
|
@@ -39,13 +46,16 @@ end
|
|
|
39
46
|
# Writes the CSV search index for all rendered objects.
|
|
40
47
|
#
|
|
41
48
|
# @param objects [Array<YARD::CodeObjects::NamespaceObject>] Verified objects included in the generated documentation.
|
|
49
|
+
# @param files [Array<YARD::CodeObjects::ExtraFileObject>] Markdown files included in the generated documentation.
|
|
42
50
|
# @return [void]
|
|
43
|
-
def serialize_index(objects)
|
|
51
|
+
def serialize_index(objects, files)
|
|
44
52
|
filepath = "#{options.serializer.basepath}/index.csv"
|
|
45
53
|
|
|
46
54
|
CSV.open(filepath, "wb") do |csv|
|
|
47
55
|
csv << %w[name type path]
|
|
48
56
|
|
|
57
|
+
files.each { |file| csv << [file.title, "File", file.filename] }
|
|
58
|
+
|
|
49
59
|
objects.each do |object|
|
|
50
60
|
next if object.name == :root
|
|
51
61
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: yard-markdown
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.9.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Stanislav (Stas) Katkov
|
|
@@ -62,6 +62,7 @@ files:
|
|
|
62
62
|
- LICENSE.txt
|
|
63
63
|
- README.md
|
|
64
64
|
- lib/yard-markdown.rb
|
|
65
|
+
- lib/yard/markdown.rb
|
|
65
66
|
- lib/yard/markdown/aref_helper.rb
|
|
66
67
|
- lib/yard/markdown/collection_rendering_helper.rb
|
|
67
68
|
- lib/yard/markdown/documentation_helper.rb
|
|
@@ -72,6 +73,7 @@ files:
|
|
|
72
73
|
- lib/yard/markdown/object_listing_helper.rb
|
|
73
74
|
- lib/yard/markdown/section_assembly_helper.rb
|
|
74
75
|
- lib/yard/markdown/tag_formatting_helper.rb
|
|
76
|
+
- lib/yard/markdown/yardoc_extension.rb
|
|
75
77
|
- templates/default/fulldoc/markdown/setup.rb
|
|
76
78
|
- templates/default/module/markdown/setup.rb
|
|
77
79
|
homepage: https://poshtui.com
|