Module: YARD::Markdown::DocumentationHelper
- Defined in:
- lib/yard/markdown/documentation_helper.rb
Overview
Converts YARD docstrings into Markdown-friendly text.
Instance Method Summary collapse
-
#documented_text(object) ⇒ String
Returns the rendered documentation text for an object.
-
#rdoc_to_md(docstring) ⇒ String
Converts an RDoc-formatted docstring to Markdown.
Instance Method Details
#documented_text(object) ⇒ String
Returns the rendered documentation text for an object.
13 14 15 16 17 18 19 |
# File 'lib/yard/markdown/documentation_helper.rb', line 13 def documented_text(object) text = rdoc_to_md(object.docstring) return text unless text.empty? return "" unless object..empty? "Not documented." end |
#rdoc_to_md(docstring) ⇒ String
Converts an RDoc-formatted docstring to Markdown.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/yard/markdown/documentation_helper.rb', line 25 def rdoc_to_md(docstring) fenced_code_blocks = [] placeholder = "YARD_MARKDOWN_FENCED_CODE_BLOCK_%d" content = docstring.gsub(/^```[^\n]*\n.*?^```[ \t]*$/m) do |block| fenced_code_blocks << block format(placeholder, fenced_code_blocks.length - 1) end markdown = RDoc::Markup::ToMarkdown.new.convert(content).rstrip fenced_code_blocks.each_with_index do |block, index| markdown = markdown.sub(format(placeholder, index), block) end markdown end |