lib/rdoc/generator/markdown.rb in rdoc-markdown-0.1.8 vs lib/rdoc/generator/markdown.rb in rdoc-markdown-0.1.10

- old
+ new

@@ -4,13 +4,10 @@ require "pathname" require "erb" require "reverse_markdown" -# Markdown generator. -# Registers command line options and generates markdown files -# RDoc documentation and options. class RDoc::Generator::Markdown RDoc::RDoc.add_generator self TEMPLATE_DIR = File.expand_path( File.join(File.dirname(__FILE__), "..", "..", "templates") @@ -32,25 +29,10 @@ # displayed. See also #modsort attr_reader :classes ## - # Files to be displayed by this generator - - attr_reader :files - - ## - # Methods to be displayed by this generator - - attr_reader :methods - - ## - # Sorted list of classes and modules to be displayed by this generator - - attr_reader :modsort - - ## # Directory where generated class HTML files live relative to the output # dir. def class_dir nil @@ -64,13 +46,10 @@ @options = options @base_dir = Pathname.pwd.expand_path @classes = nil - @files = nil - @methods = nil - @modsort = nil end def generate setup @@ -122,35 +101,38 @@ end private - def replace_extensions_in_links(text) - text.gsub(/\[(.+)\]\((.+).html(.*)\)/) do |_| + def turn_to_path(class_name) + class_name.gsub("::", "/") + end + + def markdownify(input) + md= ReverseMarkdown.convert input, github_flavored: true + + # Replace .html to .md extension in all markdown links + md = md.gsub(/\[(.+)\]\((.+).html(.*)\)/) do |_| match = Regexp.last_match "[#{match[1]}](#{match[2]}.md#{match[3]})" end - end - def turn_to_path(class_name) - class_name.gsub("::", "/") - end + # clean up things, to make it look neat. - def h(string) - replace_extensions_in_links ReverseMarkdown.convert string.strip, github_flavored: true + md.gsub("[↑](#top)", "").lstrip end + alias_method :h, :markdownify + def setup return if instance_variable_defined?(:@output_dir) @output_dir = Pathname.new(@options.op_dir).expand_path(@base_dir) return unless @store @classes = @store.all_classes_and_modules.sort - @files = @store.all_files.sort - @methods = @classes.map(&:method_list).flatten.sort @modsort = get_sorted_module_list @classes end ## # Return a list of the documented modules sorted by salience first, then