Outputs parsed markup as Markdown
Methods
- A
- G
- H
- I
- N
Class Public methods
new(markup = nil)
Link
Creates a new formatter that will output Markdown format text
# File lib/rdoc/markup/to_markdown.rb, line 11 def initialize markup = nil super @headings[1] = ['# ', ''] @headings[2] = ['## ', ''] @headings[3] = ['### ', ''] @headings[4] = ['#### ', ''] @headings[5] = ['##### ', ''] @headings[6] = ['###### ', ''] add_special_RDOCLINK add_special_TIDYLINK @hard_break = " \n" end
Instance Public methods
accept_list_end(list)
Link
Finishes consumption of list
accept_list_item_end(list_item)
Link
Finishes consumption of list_item
accept_list_item_start(list_item)
Link
Prepares the visitor for consuming list_item
# File lib/rdoc/markup/to_markdown.rb, line 74 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:" @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)
Link
Prepares the visitor for consuming list
# File lib/rdoc/markup/to_markdown.rb, line 99 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)
Link
Adds rule
to the output
accept_verbatim(verbatim)
Link
Outputs verbatim
indented 4 columns
gen_url(url, text)
Link
Creates a Markdown-style URL from url
with text
.
handle_rdoc_link(url)
Link
Handles rdoc-
type links for footnotes.
# File lib/rdoc/markup/to_markdown.rb, line 148 def handle_rdoc_link url case url when /\Ardoc-ref:/ then $' when /\Ardoc-label:footmark-(\d+)/ then "[^#{$1}]:" when /\Ardoc-label:foottext-(\d+)/ then "[^#{$1}]" when /\Ardoc-label:label-/ then gen_url url, $' when /\Ardoc-[a-z]+:/ then $' end end
handle_special_HARD_BREAK(special)
Link
Adds a newline to the output
handle_special_RDOCLINK(special)
Link
Converts the rdoc-…: links into a Markdown.style links.
handle_special_TIDYLINK(special)
Link
Converts the RDoc markup tidylink into a Markdown.style link.
# File lib/rdoc/markup/to_markdown.rb, line 166 def handle_special_TIDYLINK special text = special.text return text unless text =~ /\{(.*?)\}\[(.*?)\]/ or text =~ /(\S+)\[(.*?)\]/ label = $1 url = $2 if url =~ /^rdoc-label:foot/ then handle_rdoc_link url else gen_url url, label end end