123456789_123456789_123456789_123456789_123456789_

Class: RDoc::Markup::ToMarkdown

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, ToRdoc, Formatter
Instance Chain:
self, ToRdoc, Formatter
Inherits: RDoc::Markup::ToRdoc
Defined in: lib/rdoc/markup/to_markdown.rb

Overview

Outputs parsed markup as ::RDoc::Markdown

Class Method Summary

ToRdoc - Inherited

.new

Creates a new formatter that will output (mostly) RDoc markup.

Formatter - Inherited

.gen_relative_url

Converts a target url to one that is relative to a given path.

.new

Creates a new Formatter.

Instance Attribute Summary

ToRdoc - Inherited

#indent

Current indent amount for output in characters.

#list_index

Stack of current list indexes for alphabetic and numeric lists.

#list_type

Stack of list types.

#list_width

Stack of list widths for indentation.

#prefix

Prefix for the next list item.

#res

Output accumulator.

#width

Output width in characters.

Formatter - Inherited

#in_tt?

Are we currently inside tt tags?

Instance Method Summary

ToRdoc - Inherited

#accept_blank_line

Adds blank_line to the output.

#accept_block_quote

Adds paragraph to the output.

#accept_heading

Adds heading to the output.

#accept_indented_paragraph

Adds paragraph to the output.

#accept_list_end

Finishes consumption of list

#accept_list_item_end

Finishes consumption of list_item

#accept_list_item_start

Prepares the visitor for consuming list_item

#accept_list_start

Prepares the visitor for consuming list

#accept_paragraph

Adds paragraph to the output.

#accept_raw

Adds raw to the output.

#accept_rule

Adds rule to the output.

#accept_table

Adds table to the output.

#accept_verbatim

Outputs verbatim indented 2 columns.

#attributes

Applies attribute-specific markup to text using RDoc::AttributeManager

#end_accepting

Returns the generated output.

#handle_regexp_HARD_BREAK

Adds a newline to the output.

#handle_regexp_SUPPRESSED_CROSSREF

Removes preceding \ from the suppressed crossref target

#init_tags

Maps attributes to HTML sequences.

#start_accepting

Prepares the visitor for text generation.

#use_prefix

Adds the stored #prefix to the output and clears it.

#wrap

Wraps text to #width

Formatter - Inherited

#accept_document

Adds document to the output.

#add_regexp_handling_RDOCLINK

Adds a regexp handling for links of the form rdoc-…:

#add_regexp_handling_TIDYLINK

Adds a regexp handling for links of the form <text> and <word>.

#add_tag

Add a new set of tags for an attribute.

#annotate

Allows tag to be decorated with additional information.

#convert

Marks up content

#convert_flow

Converts flow items flow

#convert_regexp_handling

Converts added regexp handlings.

#convert_string

Converts a string to be fancier if desired.

#ignore

Use ignore in your subclass to ignore the content of a node.

#off_tags

Turns off tags for item on res

#on_tags

Turns on tags for item on res

#parse_url

Extracts and a scheme, url and an anchor id from url and returns them.

#tt?

Is tag a tt tag?

Constructor Details

.new(markup = nil) ⇒ ToMarkdown

Creates a new formatter that will output ::RDoc::Markdown format text

[ GitHub ]

  
# File 'lib/rdoc/markup/to_markdown.rb', line 12

def initialize markup = nil
  super

  @headings[1] = ['# ',      '']
  @headings[2] = ['## ',     '']
  @headings[3] = ['### ',    '']
  @headings[4] = ['#### ',   '']
  @headings[5] = ['##### ',  '']
  @headings[6] = ['###### ', '']

  add_regexp_handling_RDOCLINK
  add_regexp_handling_TIDYLINK

  @hard_break = "  \n"
end

Instance Method Details

#accept_list_end(list)

Finishes consumption of list

[ GitHub ]

  
# File 'lib/rdoc/markup/to_markdown.rb', line 47

def accept_list_end list
  super
end

#accept_list_item_end(list_item)

Finishes consumption of list_item

[ GitHub ]

  
# File 'lib/rdoc/markup/to_markdown.rb', line 54

def accept_list_item_end list_item
  width = case @list_type.last
          when :BULLET then
            4
          when :NOTE, :LABEL then
            use_prefix

            @res << "\n"

            4
          else
            @list_index[-1] = @list_index.last.succ
            4
          end

  @indent -= width
end

#accept_list_item_start(list_item)

Prepares the visitor for consuming list_item

[ GitHub ]

  
# File 'lib/rdoc/markup/to_markdown.rb', line 75

def accept_list_item_start list_item
  type = @list_type.last

  case type
  when :NOTE, :LABEL then
    bullets = Array(list_item.label).map do |label|
      attributes(label).strip
    end.join "\n"

    bullets << "\n" unless bullets.empty?

    @prefix = ' ' * @indent
    @indent += 4
    @prefix << bullets << ":" << (' ' * (@indent - 1))
  else
    bullet = type == :BULLET ? '*' : @list_index.last.to_s + '.'
    @prefix = (' ' * @indent) + bullet.ljust(4)

    @indent += 4
  end
end

#accept_list_start(list)

Prepares the visitor for consuming list

[ GitHub ]

  
# File 'lib/rdoc/markup/to_markdown.rb', line 100

def accept_list_start list
  case list.type
  when :BULLET, :LABEL, :NOTE then
    @list_index << nil
  when :LALPHA, :NUMBER, :UALPHA then
    @list_index << 1
  else
    raise RDoc::Error, "invalid list type #{list.type}"
  end

  @list_width << 4
  @list_type << list.type
end

#accept_rule(rule)

Adds rule to the output

[ GitHub ]

  
# File 'lib/rdoc/markup/to_markdown.rb', line 117

def accept_rule rule
  use_prefix or @res << ' ' * @indent
  @res << '-' * 3
  @res << "\n"
end

#accept_verbatim(verbatim)

Outputs verbatim indented 4 columns

[ GitHub ]

  
# File 'lib/rdoc/markup/to_markdown.rb', line 126

def accept_verbatim verbatim
  indent = ' ' * (@indent + 4)

  verbatim.parts.each do |part|
    @res << indent unless part == "\n"
    @res << part
  end

  @res << "\n"
end

#gen_url(url, text)

Creates a Markdown-style URL from url with text.

[ GitHub ]

  
# File 'lib/rdoc/markup/to_markdown.rb', line 140

def gen_url url, text
  scheme, url, = parse_url url

  "[#{text.sub(%r{^#{scheme}:/*}i, '')}](#{url})"
end

#handle_regexp_HARD_BREAK(target)

Adds a newline to the output

[ GitHub ]

  
# File 'lib/rdoc/markup/to_markdown.rb', line 40

def handle_regexp_HARD_BREAK target
  "  \n"
end

#init_tags

Maps attributes to HTML sequences

[ GitHub ]

  
# File 'lib/rdoc/markup/to_markdown.rb', line 31

def init_tags
  add_tag :BOLD, '**', '**'
  add_tag :EM,   '*',  '*'
  add_tag :TT,   '`',  '`'
end