yard-markdown 0.7.0 → 0.7.2

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: 41e14595e84affb837da2c36afb9a40f0e7ea866472fa32e5aefabc7c32c2ec8
4
- data.tar.gz: 605f1ad9c9496ebaf48afc7245ab25db98b5e22aed88c7c718bb3968f78b3b5e
3
+ metadata.gz: 6aa034296e039353941780b9556959dabbddad7874f52231b0dc69faed55b662
4
+ data.tar.gz: 379509fb60bb677e34f4ef90e3d6776462a6f9d0768fcf09c078866c78967476
5
5
  SHA512:
6
- metadata.gz: '0887584b2fe63298271fad1483237eb303d215068a6da79aee7cb59c463a6c2838a6a72171676e7876f7a7d8c9003c0e23eb0fcb9dbfd88e329f028c5907bdef'
7
- data.tar.gz: 9d50e908447b65b564315c996af01a43e35d360f2bafd600d34197ed20fc0cf8fde1b506850eb2fd476ee65d33c44ff10de8658abcd51037011060d4e69ec59f
6
+ metadata.gz: 7a93025d200cc5711781fefced38b4e2a4e91ca6fb7228b744c28c1c8dfae8b18819b12bfcec1c7b9b6051c4f179342d55b8bd3bdf07ec083ea9e36ca60f59c7
7
+ data.tar.gz: f25532bd94b48553decf5b8c1a48c9bc92dcf639aadfc09b02a6c8ec77f8a9c568515d21991b891499d76643f4ab42c0e4df19d6e0588df887480734b756a7d9
data/CHANGELOG.md CHANGED
@@ -5,6 +5,19 @@ This format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
5
5
 
6
6
  ## Unreleased
7
7
 
8
+ ## 0.7.2
9
+
10
+ ### Changed
11
+ - Limit the packaged gem to documentation, runtime code, and templates.
12
+
13
+ ### Removed
14
+ - Remove the generated RBS signature from the packaged gem.
15
+
16
+ ## 0.7.1
17
+
18
+ ### Fixed
19
+ - Preserve fenced code blocks in YARD docstrings so generated Markdown examples render correctly.
20
+
8
21
  ## 0.7.0
9
22
  ## Added
10
23
  - Adding yard-lint and all method documentation
@@ -14,4 +27,3 @@ This format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
14
27
  ## Changed
15
28
  - Refactoring and simplification of teamplate, mostly driven by mutantion testing
16
29
  - Improve documentation for entire project
17
-
data/README.md CHANGED
@@ -12,15 +12,6 @@ It's a pitty that rdoc and yard can't output a proper markdown file. I would lik
12
12
  - Mimick yard html layout where it makes sense to maintain familiarity
13
13
 
14
14
  ## Usage
15
- Yard doesn't load plugin by default, so you need to load plugin through `~/.yard/config`:
16
-
17
- ```yaml
18
- !!!yaml
19
- load_plugins: true
20
- autoload_plugins:
21
- - markdown
22
- ```
23
-
24
15
  Install a plugin
25
16
  ```
26
17
  gem install yard-markdown
@@ -28,20 +19,32 @@ gem install yard-markdown
28
19
 
29
20
  Run `yardoc --format=markdown` to generate markdown documentation.
30
21
 
31
- ## Note on RDoc support
22
+ ## FAQ
23
+
24
+ ### Note on RDoc support
32
25
  It seems important to note, that yard claims to have support for RDoc. That support is certainly present, but output for rdoc is dramatically different. A lot of useful information seems lost in the process.
33
26
 
34
27
  If you know how to improve that, please get in touch or submit a patch.
35
28
 
36
29
  So in meantime, there is work going on a competing gem for RDoc and it's called [rdoc-markdown gem](https://github.com/skatkov/rdoc-markdown/).
37
30
 
38
- ## Note on index.csv file
31
+ ### Note on index.csv file
39
32
  This gem emits index of all markdown files in a index.csv file.
40
33
 
41
34
  There are decent tools that offer search through structured plain-text files. But my expectation is that nobody will use CSV as an actual search index, but rather import it into something that performs this function better.
42
35
 
43
36
  In my personal use-case, I use SQLite. All other databases seem to have a good support for CSV imports.
44
37
 
38
+ ### Yard doesn't load plugin properly?
39
+ so you need to load plugin through `~/.yard/config`:
40
+
41
+ ```yaml
42
+ !!!yaml
43
+ load_plugins: true
44
+ autoload_plugins:
45
+ - markdown
46
+ ```
47
+
45
48
  ## Testing
46
49
  Unit tests verify renderer behavior, index links, and anchor consistency for both YARD-style and RDoc-style sources.
47
50
 
@@ -63,12 +66,6 @@ Validate generated markdown in sample docs:
63
66
  bundle exec rake markdown:validate_examples
64
67
  ```
65
68
 
66
- Regenerate the checked-in RBS types derived from YARD docs:
67
-
68
- ```bash
69
- bundle exec rake types:generate
70
- ```
71
-
72
69
  There is also a real-world validation harness for repositories with substantial YARD documentation (`rspec-core`, `sidekiq`):
73
70
 
74
71
  ```bash
@@ -79,6 +76,4 @@ This task validates generated markdown against CommonMark + GFM rendering, and r
79
76
 
80
77
  GitHub Actions CI now runs this task on every push/PR, so `sidekiq` and other real-world fixture gems are verified continuously.
81
78
 
82
- CI also regenerates `sig/yard/markdown.rbs` with `sord` and fails if the checked-in RBS file is out of date.
83
-
84
79
  For reproducible checks, the task clones pinned tags (`rspec-core` `v3.13.2`, `sidekiq` `v7.3.10`) into `tmp/real-world/repos` before generating output.
@@ -1,10 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Namespace for YARD extensions used by this gem.
3
4
  module YARD
5
+ # Shared helpers for rendering YARD objects as Markdown.
4
6
  module Markdown
5
7
  # Computes anchor ids that match the generated Markdown headings.
6
8
  module ArefHelper
7
- include AnchorComponentHelper
9
+ # Encodes a value so it can be embedded safely in an HTML anchor id.
10
+ #
11
+ # @param value [Object] Raw anchor fragment to encode.
12
+ # @return [String] Anchor-safe identifier fragment.
13
+ def anchor_component(value)
14
+ value.to_s.each_char.map do |char|
15
+ char.match?(/[A-Za-z0-9_-]/) ? char : format("-%X", char.ord)
16
+ end.join
17
+ end
8
18
 
9
19
  # Returns the primary anchor id for a documented object.
10
20
  #
@@ -13,12 +23,12 @@ module YARD
13
23
  def aref(object)
14
24
  type = object.type
15
25
 
16
- return "class-#{object.path.gsub('::', '-')}" if type == :class
17
- return "module-#{object.path.gsub('::', '-')}" if type == :module
26
+ return "class-#{object.path.gsub("::", "-")}" if type == :class
27
+ return "module-#{object.path.gsub("::", "-")}" if type == :module
18
28
  return "constant-#{object.name}" if type == :constant
19
29
  return "classvariable-#{anchor_component(object.name)}" if type == :classvariable
20
30
 
21
- scope = object.scope == :class ? 'c' : 'i'
31
+ scope = (object.scope == :class) ? "c" : "i"
22
32
 
23
33
  if !object.attr_info.nil?
24
34
  "attribute-#{scope}-#{object.name}"
@@ -10,27 +10,7 @@ module YARD
10
10
  # @param group_order [Array<String>, nil] Preferred ordering for group headings.
11
11
  # @return [String] Markdown for the constants section.
12
12
  def render_constants(constants, group_order)
13
- lines = ['## Constants']
14
- grouped_constants = grouped_items(constants.sort_by { |item| item.name }, group_order)
15
- uses_groups = grouped_constants.any? { |name, _items| !name.nil? }
16
-
17
- grouped_constants.each do |group_name, items|
18
- if uses_groups
19
- lines << "### #{group_name || 'General'}"
20
- item_heading = '####'
21
- else
22
- item_heading = '###'
23
- end
24
-
25
- lines << items.map { |item|
26
- item_lines = [heading_with_anchors("#{item_heading} `#{item.name}`", item)]
27
- append_lines(item_lines, documented_text(item), separated: false)
28
- append_lines(item_lines, render_tags(item), separated: false)
29
- item_lines.join("\n")
30
- }.join("\n\n")
31
- end
32
-
33
- lines.join("\n")
13
+ render_collection("Constants", constants.sort_by { |item| item.name }, group_order) { |item| "`#{item.name}`" }
34
14
  end
35
15
 
36
16
  # Renders the attributes section for an object page.
@@ -39,27 +19,7 @@ module YARD
39
19
  # @param group_order [Array<String>, nil] Preferred ordering for group headings.
40
20
  # @return [String] Markdown for the attributes section.
41
21
  def render_attributes(attrs, group_order)
42
- lines = ['## Attributes']
43
- grouped_attrs = grouped_items(attrs, group_order)
44
- uses_groups = grouped_attrs.any? { |name, _items| !name.nil? }
45
-
46
- grouped_attrs.each do |group_name, items|
47
- if uses_groups
48
- lines << "### #{group_name || 'General'}"
49
- item_heading = '####'
50
- else
51
- item_heading = '###'
52
- end
53
-
54
- lines << items.map { |item|
55
- item_lines = [heading_with_anchors("#{item_heading} `#{item.name}` [#{attribute_access(item)}]", item)]
56
- append_lines(item_lines, documented_text(item), separated: false)
57
- append_lines(item_lines, render_tags(item), separated: false)
58
- item_lines.join("\n")
59
- }.join("\n\n")
60
- end
61
-
62
- lines.join("\n")
22
+ render_collection("Attributes", attrs, group_order) { |item| "`#{item.name}` [#{attribute_access(item)}]" }
63
23
  end
64
24
 
65
25
  # Renders a method section for an object page.
@@ -69,20 +29,26 @@ module YARD
69
29
  # @param group_order [Array<String>, nil] Preferred ordering for group headings.
70
30
  # @return [String] Markdown for the method section.
71
31
  def render_methods(section_title, methods, group_order)
32
+ render_collection(section_title, methods, group_order) { |item| "`#{formatted_method_heading(item)}`" }
33
+ end
34
+
35
+ # Renders a grouped collection with a caller-provided item label.
36
+ #
37
+ # @param section_title [String] Section title to render.
38
+ # @param items [Array<YARD::CodeObjects::Base>] Objects to group and render.
39
+ # @param group_order [Array<String>, nil] Preferred ordering for group headings.
40
+ # @return [String] Markdown for the collection section.
41
+ def render_collection(section_title, items, group_order)
72
42
  lines = ["## #{section_title}"]
73
- grouped_methods = grouped_items(methods, group_order)
74
- uses_groups = grouped_methods.any? { |name, _items| !name.nil? }
43
+ groups = grouped_items(items, group_order)
44
+ uses_groups = groups.any? { |name, _items| !name.nil? }
45
+ item_heading = uses_groups ? "####" : "###"
75
46
 
76
- grouped_methods.each do |group_name, items|
77
- if uses_groups
78
- lines << "### #{group_name || 'General'}"
79
- item_heading = '####'
80
- else
81
- item_heading = '###'
82
- end
47
+ groups.each do |group_name, group_items|
48
+ lines << "### #{group_name || "General"}" if uses_groups
83
49
 
84
- lines << items.map { |item|
85
- item_lines = [heading_with_anchors("#{item_heading} `#{formatted_method_heading(item)}`", item)]
50
+ lines << group_items.map { |item|
51
+ item_lines = [heading_with_anchors("#{item_heading} #{yield(item)}", item)]
86
52
  append_lines(item_lines, documented_text(item), separated: false)
87
53
  append_lines(item_lines, render_tags(item), separated: false)
88
54
  item_lines.join("\n")
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rdoc'
3
+ require "rdoc"
4
4
 
5
5
  module YARD
6
6
  module Markdown
@@ -13,9 +13,9 @@ module YARD
13
13
  def documented_text(object)
14
14
  text = rdoc_to_md(object.docstring)
15
15
  return text unless text.empty?
16
- return '' unless object.tags.empty?
16
+ return "" unless object.tags.empty?
17
17
 
18
- 'Not documented.'
18
+ "Not documented."
19
19
  end
20
20
 
21
21
  # Converts an RDoc-formatted docstring to Markdown.
@@ -23,7 +23,19 @@ module YARD
23
23
  # @param docstring [Object] Raw docstring content.
24
24
  # @return [String] Markdown-rendered docstring content.
25
25
  def rdoc_to_md(docstring)
26
- RDoc::Markup::ToMarkdown.new.convert(docstring).rstrip
26
+ fenced_code_blocks = []
27
+ placeholder = "YARD_MARKDOWN_FENCED_CODE_BLOCK_%d"
28
+ content = docstring.gsub(/^```[^\n]*\n.*?^```[ \t]*$/m) do |block|
29
+ fenced_code_blocks << block
30
+ format(placeholder, fenced_code_blocks.length - 1)
31
+ end
32
+
33
+ markdown = RDoc::Markup::ToMarkdown.new.convert(content).rstrip
34
+ fenced_code_blocks.each_with_index do |block, index|
35
+ markdown = markdown.sub(format(placeholder, index), block)
36
+ end
37
+
38
+ markdown
27
39
  end
28
40
  end
29
41
  end
@@ -37,7 +37,7 @@ module YARD
37
37
  # @param object [YARD::CodeObjects::Base] Object being rendered.
38
38
  # @return [String] Heading text with embedded anchor tags.
39
39
  def heading_with_anchors(heading, object)
40
- "#{heading} #{anchor_tags_for(object).join(' ')}"
40
+ "#{heading} #{anchor_tags_for(object).join(" ")}"
41
41
  end
42
42
 
43
43
  # Builds an HTML anchor tag for a generated id.
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'pathname'
4
-
5
3
  module YARD
6
4
  module Markdown
7
5
  # Rewrites generated Markdown links so they point at Markdown output.
@@ -31,12 +29,12 @@ module YARD
31
29
  markdown.gsub(%r{\[(.+?)\]\((?!https?://|mailto:|#)([^)\n]+)\)}) do
32
30
  label = Regexp.last_match(1)
33
31
  target = Regexp.last_match(2)
34
- path = target.sub(/[?#].*\z/, '')
32
+ path = target.sub(/[?#].*\z/, "")
35
33
  suffix = target[path.length..]
36
34
  rewritten_path = resolve_local_link_target(path, current_dir)
37
35
 
38
36
  if rewritten_path.nil?
39
- "`#{label.tr('`', '')}`"
37
+ "`#{label.tr("`", "")}`"
40
38
  else
41
39
  "[#{label}](#{rewritten_path}#{suffix})"
42
40
  end
@@ -49,15 +47,15 @@ module YARD
49
47
  # @param current_dir [Pathname] Directory for the current output file.
50
48
  # @return [YARD::CodeObjects::Base, nil] Matched registry object, if any.
51
49
  def resolve_registry_object(path, current_dir)
52
- cleaned = path.sub(%r{\A(?:(?:\.\./)+|\./)}, '')
50
+ cleaned = path.sub(%r{\A(?:(?:\.\./)+|\./)}, "")
53
51
  candidates = [path]
54
52
 
55
53
  if constant_reference_path?(cleaned)
56
- current_parts = current_dir.to_s.split('/').reject { |part| part.empty? || part == '.' }
57
- target_parts = cleaned.split('/')
54
+ current_parts = current_dir.to_s.split("/").reject { |part| part.empty? || part == "." }
55
+ target_parts = cleaned.split("/")
58
56
 
59
57
  current_parts.length.downto(0) do |depth|
60
- candidates << (current_parts.first(depth) + target_parts).join('::')
58
+ candidates << (current_parts.first(depth) + target_parts).join("::")
61
59
  end
62
60
  end
63
61
 
@@ -77,7 +75,7 @@ module YARD
77
75
  # @param current_dir [Pathname] Directory for the current output file.
78
76
  # @return [String, nil] Relative Markdown path, or nil when unresolved.
79
77
  def resolve_local_link_target(path, current_dir)
80
- normalized = path.sub(%r{\A/+}, '')
78
+ normalized = path.sub(%r{\A/+}, "")
81
79
 
82
80
  obj = resolve_registry_object(normalized, current_dir)
83
81
  if obj
@@ -86,11 +84,11 @@ module YARD
86
84
  end
87
85
 
88
86
  if normalized.match?(/\.html\z/i)
89
- normalized = normalized.sub(/\.html\z/i, '.md')
87
+ normalized = normalized.sub(/\.html\z/i, ".md")
90
88
  elsif File.extname(normalized).empty?
91
89
  return nil if unresolved_identifier_target?(normalized)
92
90
 
93
- normalized = "#{normalized}.md" if normalized.include?('/')
91
+ normalized = "#{normalized}.md" if normalized.include?("/")
94
92
  end
95
93
 
96
94
  relative_output_path(current_dir, normalized)
@@ -112,8 +110,8 @@ module YARD
112
110
  # @param path [String] Link target to inspect.
113
111
  # @return [Boolean] True when the target should be treated as unresolved.
114
112
  def unresolved_identifier_target?(path)
115
- cleaned = path.sub(%r{\A(?:(?:\.\./)+|\./)}, '')
116
- return true if cleaned.start_with?(':') || cleaned.match?(/\A\d/)
113
+ cleaned = path.sub(%r{\A(?:(?:\.\./)+|\./)}, "")
114
+ return true if cleaned.start_with?(":") || cleaned.match?(/\A\d/)
117
115
 
118
116
  cleaned.match?(/\A[a-z_]\w*\z/)
119
117
  end
@@ -125,10 +123,10 @@ module YARD
125
123
  # @return [String] Relative path suitable for a Markdown link.
126
124
  def relative_output_path(current_dir, target_path)
127
125
  target = target_path.to_s
128
- return target if target.start_with?('../')
126
+ return target if target.start_with?("../")
129
127
 
130
128
  Pathname.new(target).relative_path_from(current_dir).to_s
131
- rescue StandardError
129
+ rescue
132
130
  target
133
131
  end
134
132
 
@@ -11,7 +11,7 @@ module YARD
11
11
  def formatted_method_heading(method_object)
12
12
  name = method_object.name
13
13
  signature = method_signature(method_object)
14
- signature = " #{signature}" if name.end_with?(']')
14
+ signature = " #{signature}" if name.end_with?("]")
15
15
  "#{name}#{signature}"
16
16
  end
17
17
 
@@ -20,13 +20,13 @@ module YARD
20
20
  # @param method_object [YARD::CodeObjects::MethodObject] Method being rendered.
21
21
  # @return [String] Parenthesized method signature.
22
22
  def method_signature(method_object)
23
- return '()' if method_object.parameters.nil?
23
+ return "()" if method_object.parameters.nil?
24
24
 
25
25
  rendered = method_object.parameters.map do |name, default|
26
- default.nil? || default.empty? ? name : "#{name} = #{default}"
26
+ (default.nil? || default.empty?) ? name : "#{name} = #{default}"
27
27
  end
28
28
 
29
- "(#{rendered.join(', ')})"
29
+ "(#{rendered.join(", ")})"
30
30
  end
31
31
 
32
32
  # Returns the access marker for an attribute.
@@ -34,15 +34,11 @@ module YARD
34
34
  # @param attribute [YARD::CodeObjects::MethodObject] Attribute reader or writer.
35
35
  # @return [String] Access mode marker such as `R`, `W`, or `RW`.
36
36
  def attribute_access(attribute)
37
- info = attribute.attr_info || {}
38
- return 'RW' if info[:read] && info[:write]
39
- return 'R' if info[:read]
40
- return 'W' if info[:write]
37
+ read, write = attribute.attr_info.fetch_values(:read, :write)
38
+ return "RW" if read && write
39
+ return "R" if read
41
40
 
42
- return 'RW' if attribute.reader? && attribute.writer?
43
- return 'R' if attribute.reader?
44
-
45
- 'W'
41
+ "W"
46
42
  end
47
43
  end
48
44
  end
@@ -80,7 +80,7 @@ module YARD
80
80
  # @param object [YARD::CodeObjects::Base] Listed object whose docstring may start with `:nodoc:`.
81
81
  # @return [Boolean] True when the object should be hidden.
82
82
  def hidden_object?(object)
83
- object.docstring.lstrip.start_with?(':nodoc:')
83
+ object.docstring.start_with?(":nodoc:")
84
84
  end
85
85
  end
86
86
  end
@@ -10,7 +10,7 @@ module YARD
10
10
  # @return [String] Section content followed by blank-line spacing.
11
11
  def render_section_content(content)
12
12
  text = content.to_s.strip
13
- return '' if text.empty?
13
+ return "" if text.empty?
14
14
 
15
15
  "#{text}\n\n"
16
16
  end
@@ -24,11 +24,11 @@ module YARD
24
24
 
25
25
  lines << "**Inherits:** `#{object.superclass}`" if object.instance_of?(CodeObjects::ClassObject)
26
26
 
27
- [[:class, 'Extended by'], [:instance, 'Includes']].each do |scope, label|
27
+ [[:class, "Extended by"], [:instance, "Includes"]].each do |scope, label|
28
28
  mixins = run_verifier(object.mixins(scope)).sort_by { |item| item.path }
29
29
  next if mixins.empty?
30
30
 
31
- lines << "**#{label}:** #{mixins.map { |mixin| "`#{mixin.path}`" }.join(', ')}"
31
+ lines << "**#{label}:** #{mixins.map { |mixin| "`#{mixin.path}`" }.join(", ")}"
32
32
  end
33
33
 
34
34
  lines.join("\n")
@@ -10,23 +10,12 @@ module YARD
10
10
  # @param group_order [Array<String>, nil] Preferred ordering for named groups.
11
11
  # @return [Array<Array>] Ordered pairs of group names and grouped items.
12
12
  def grouped_items(items, group_order)
13
- grouped = Hash.new { |hash, key| hash[key] = [] }
14
- items.each { |item| grouped[item.group] << item }
13
+ groups = items.group_by(&:group)
14
+ names = groups.keys
15
+ order = Array(group_order)
16
+ ordered_names = (order & names) + (names.compact - order).sort + ([nil] & names)
15
17
 
16
- ordered = []
17
-
18
- Array(group_order).each do |name|
19
- next unless grouped.key?(name)
20
-
21
- ordered << [name, grouped.delete(name)]
22
- end
23
-
24
- grouped.keys.compact.sort.each do |name|
25
- ordered << [name, grouped.delete(name)]
26
- end
27
-
28
- ordered << [nil, grouped.delete(nil)] if grouped.key?(nil)
29
- ordered
18
+ ordered_names.map { |name| [name, groups.fetch(name)] }
30
19
  end
31
20
 
32
21
  # Appends non-empty content to a mutable list of lines.
@@ -38,7 +27,7 @@ module YARD
38
27
  def append_lines(lines, content, separated: true)
39
28
  return if content.lstrip.empty?
40
29
 
41
- lines << '' if separated && !lines.empty? && !lines.last.empty?
30
+ lines << "" if separated && !lines.empty? && !lines.last.empty?
42
31
  lines.concat(content.split("\n"))
43
32
  end
44
33
  end
@@ -9,21 +9,16 @@ module YARD
9
9
  # @param object [YARD::CodeObjects::Base] Object whose tags are being rendered.
10
10
  # @return [String] Markdown representation of the object's tags.
11
11
  def render_tags(object)
12
- lines = []
13
- regular_tags = object.tags.reject { |tag| tag.tag_name == 'example' }
14
- example_tags = object.tags.select { |tag| tag.tag_name == 'example' }
15
-
16
- regular_tags.each do |tag|
17
- lines << "- #{format_tag(tag)}"
18
- end
12
+ example_tags, regular_tags = object.tags.partition { |tag| tag.tag_name == "example" }
13
+ lines = regular_tags.map { |tag| "- #{format_tag(tag)}" }
19
14
 
20
15
  example_tags.each do |tag|
21
16
  lines << nil unless lines.empty?
22
- title = tag.name.to_s.rstrip.empty? ? '**@example**' : "**@example #{tag.name}**"
17
+ title = tag.name.to_s.rstrip.empty? ? "**@example**" : "**@example #{tag.name}**"
23
18
  lines << title
24
- lines << '```ruby'
19
+ lines << "```ruby"
25
20
  lines << tag.text.to_s.rstrip
26
- lines << '```'
21
+ lines << "```"
27
22
  end
28
23
 
29
24
  lines.join("\n")
@@ -38,37 +33,18 @@ module YARD
38
33
  parts << "`#{tag.name}`" unless tag.name.to_s.lstrip.empty?
39
34
 
40
35
  cleaned_types = normalized_tag_types(tag.types)
41
- parts << "[#{cleaned_types.join(', ')}]" unless cleaned_types.empty?
36
+ parts << "[#{cleaned_types.join(", ")}]" unless cleaned_types.empty?
42
37
  parts << tag.text.strip unless tag.text.to_s.lstrip.empty?
43
38
 
44
- parts.join(' ')
39
+ parts.join(" ")
45
40
  end
46
41
 
47
42
  # Normalizes tag type declarations into printable strings.
48
43
  #
49
- # @param types [Array<Object>, Hash, nil] Raw tag types from YARD.
44
+ # @param types [Array<Object>, nil] Raw tag types from YARD.
50
45
  # @return [Array<String>] Cleaned type strings.
51
46
  def normalized_tag_types(types)
52
- values = if types.instance_of?(Hash)
53
- types.map { |name, value| format_hash_tag_type(name, value) }
54
- else
55
- Array(types)
56
- end
57
-
58
- values.map(&:to_s).map(&:strip).reject(&:empty?)
59
- end
60
-
61
- # Formats a hash-style tag type entry.
62
- #
63
- # @param name [String] Type name to format.
64
- # @param value [Object] Associated type detail.
65
- # @return [String, nil] Formatted type entry, or nil when blank.
66
- def format_hash_tag_type(name, value)
67
- key = name.rstrip
68
- return nil if key.empty?
69
- return key if value.nil? || value == true || (value.respond_to?(:empty?) && value.empty?)
70
-
71
- "#{key}: #{value}"
47
+ Array(types).map(&:to_s).map(&:strip).reject(&:empty?)
72
48
  end
73
49
  end
74
50
  end
data/lib/yard-markdown.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "yard"
4
- require_relative "yard/markdown/anchor_component_helper"
5
4
  require_relative "yard/markdown/aref_helper"
6
5
  require_relative "yard/markdown/collection_rendering_helper"
7
6
  require_relative "yard/markdown/documentation_helper"