Sha256: 30edf6ec192623d0db1cd4bcaa03338d2a4956eee5706c31203180163fdbd9f6
Contents?: true
Size: 1.06 KB
Versions: 54
Compression:
Stored size: 1.06 KB
Contents
require 'rdoc' require 'reverse_markdown' module AppMap module Swagger # Transform description fields into Markdown. class MarkdownDescriptions def initialize(swagger_yaml) @swagger_yaml = swagger_yaml end def converter method(:rdoc_to_markdown) end def perform to_markdown = lambda do |obj| return obj.each(&to_markdown) if obj.is_a?(Array) return unless obj.is_a?(Hash) description = obj['description'] obj['description'] = converter.(description) if description obj.reject { |k,v| k == 'properties' }.each_value(&to_markdown) obj end to_markdown.(Util.deep_dup(@swagger_yaml)) end protected def rdoc_to_markdown(comment) # Strip tags comment = comment.split("\n").reject { |line| line =~ /^\s*@/ }.join("\n") converter = ::RDoc::Markup::ToHtml.new(::RDoc::Options.new) html = converter.convert(comment).strip ::ReverseMarkdown.convert(html).strip end end end end
Version data entries
54 entries across 54 versions & 1 rubygems