Class: RDoc::Markup::ToMarkdown
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
|
|
Instance Chain:
|
|
Inherits: |
RDoc::Markup::ToRdoc
|
Defined in: | lib/rdoc/markup/to_markdown.rb |
Overview
Outputs parsed markup as ::RDoc::Markdown
Class Method Summary
-
.new(markup = nil) ⇒ ToMarkdown
constructor
Creates a new formatter that will output
::RDoc::Markdown
format text.
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 |
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
-
#accept_list_end(list)
Finishes consumption of
list
-
#accept_list_item_end(list_item)
Finishes consumption of
list_item
-
#accept_list_item_start(list_item)
Prepares the visitor for consuming
list_item
-
#accept_list_start(list)
Prepares the visitor for consuming
list
-
#accept_rule(rule)
Adds
rule
to the output. -
#accept_verbatim(verbatim)
Outputs
verbatim
indented 4 columns. -
#gen_url(url, text)
Creates a Markdown-style URL from
url
withtext
. -
#handle_rdoc_link(url)
Handles
rdoc-
type links for footnotes. -
#handle_regexp_HARD_BREAK(target)
Adds a newline to the output.
-
#handle_regexp_RDOCLINK(target)
Converts the rdoc-…: links into a
Markdown.style
links. -
#handle_regexp_TIDYLINK(target)
Converts the
::RDoc::RDoc
markup tidylink into aMarkdown.style
link. -
#init_tags
Maps attributes to HTML sequences.
ToRdoc
- Inherited
#accept_blank_line | Adds |
#accept_block_quote | Adds |
#accept_heading | Adds |
#accept_indented_paragraph | Adds |
#accept_list_end | Finishes consumption of |
#accept_list_item_end | Finishes consumption of |
#accept_list_item_start | Prepares the visitor for consuming |
#accept_list_start | Prepares the visitor for consuming |
#accept_paragraph | Adds |
#accept_raw | Adds |
#accept_rule | Adds |
#accept_table | Adds |
#accept_verbatim | Outputs |
#attributes | Applies attribute-specific markup to |
#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 |
#init_tags | Maps attributes to HTML sequences. |
#start_accepting | Prepares the visitor for text generation. |
#use_prefix | Adds the stored |
#wrap | Wraps |
Formatter
- Inherited
#accept_document | Adds |
#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 |
#add_tag | Add a new set of tags for an attribute. |
#annotate | Allows |
#convert | Marks up |
#convert_flow | Converts flow items |
#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 |
#on_tags | Turns on tags for |
#parse_url | Extracts and a scheme, url and an anchor id from |
#tt? | Is |
Constructor Details
.new(markup = nil) ⇒ ToMarkdown
Creates a new formatter that will output ::RDoc::Markdown
format text
# 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
# 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
# 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
# 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
# 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
# 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
# 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
.
# 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_rdoc_link(url)
Handles rdoc-
type links for footnotes.
# File 'lib/rdoc/markup/to_markdown.rb', line 149
def handle_rdoc_link url case url when /^rdoc-ref:/ then $' when /^rdoc-label:footmark-(\d+)/ then "[^#{$1}]:" when /^rdoc-label:foottext-(\d+)/ then "[^#{$1}]" when /^rdoc-label:label-/ then gen_url url, $' when /^rdoc-image:/ then "![](#{$'})" when /^rdoc-[a-z]+:/ then $' end end
#handle_regexp_HARD_BREAK(target)
Adds a newline to the output
# File 'lib/rdoc/markup/to_markdown.rb', line 40
def handle_regexp_HARD_BREAK target " \n" end
#handle_regexp_RDOCLINK(target)
Converts the rdoc-…: links into a Markdown.style
links.
# File 'lib/rdoc/markup/to_markdown.rb', line 187
def handle_regexp_RDOCLINK target handle_rdoc_link target.text end
#handle_regexp_TIDYLINK(target)
Converts the ::RDoc::RDoc
markup tidylink into a Markdown.style
link.
# File 'lib/rdoc/markup/to_markdown.rb', line 169
def handle_regexp_TIDYLINK target text = target.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
#init_tags
Maps attributes to HTML sequences
# File 'lib/rdoc/markup/to_markdown.rb', line 31
def add_tag :BOLD, '**', '**' add_tag :EM, '*', '*' add_tag :TT, '`', '`' end