Class: RDoc::Markup::Formatter
| Relationships & Source Files | |
| Namespace Children | |
|
Classes:
| |
| Extension / Inclusion / Inheritance Descendants | |
|
Subclasses:
|
|
| Inherits: | Object |
| Defined in: | lib/rdoc/markup/formatter.rb |
Class Method Summary
-
.gen_relative_url(path, target)
Converts a target url to one that is relative to a given path.
-
.new(options, markup = nil) ⇒ Formatter
constructor
Creates a new
Formatter.
Instance Method Summary
-
#accept_document(document)
Adds
documentto the output. -
#add_regexp_handling_RDOCLINK
Adds a regexp handling for links of the form rdoc-…:
-
#annotate(tag)
Allows
tagto be decorated with additional information. -
#apply_regexp_handling(text)
Applies regexp handling to
textand returns an array of [text, converted?] pairs. -
#convert(content)
Marks up
content -
#convert_string(string)
Converts a string to be fancier if desired.
-
#handle_BOLD(nodes)
Called when processing bold nodes while traversing inline nodes from handle_inline.
-
#handle_BOLD_WORD(word)
Called when processing bold word nodes while traversing inline nodes from handle_inline.
-
#handle_EM(nodes)
Called when processing emphasis nodes while traversing inline nodes from handle_inline.
-
#handle_EM_WORD(word)
Called when processing emphasis word nodes while traversing inline nodes from handle_inline.
-
#handle_HARD_BREAK
Called when processing a hard break while traversing inline nodes from handle_inline.
-
#handle_inline(text)
Parses inline
text, traverse the resulting nodes, and calls the appropriate handler methods. -
#handle_PLAIN_TEXT(text)
Called when processing plain text while traversing inline nodes from handle_inline.
-
#handle_REGEXP_HANDLING_TEXT(text)
Called when processing regexp-handling-processed text while traversing inline nodes from handle_inline.
-
#handle_STRIKE(nodes)
Called when processing strike nodes while traversing inline nodes from handle_inline.
-
#handle_TEXT(text)
Called when processing text node while traversing inline nodes from handle_inline.
-
#handle_TIDYLINK(label_part, url)
Called when processing tidylink nodes while traversing inline nodes from handle_inline.
-
#handle_TT(code)
Called when processing tt nodes while traversing inline nodes from handle_inline.
-
#ignore(*node)
(also: #accept_raw, #accept_rule, #accept_block_quote, #accept_heading, #accept_list_end, #accept_list_item_end, #accept_list_item_start, #accept_list_start, #accept_raw, #accept_rule, #accept_verbatim, #accept_table, #accept_block_quote, #accept_raw, #accept_rule, #accept_blank_line, #accept_paragraph, #accept_verbatim, #accept_list_end, #accept_list_item_start, #accept_list_item_end, #accept_list_end_bullet, #accept_list_start, #accept_table)
Use ignore in your subclass to ignore the content of a node.
-
#parse_url(url)
Extracts and a scheme, url and an anchor id from
urland returns them. -
#traverse_inline_nodes(nodes)
Traverses
nodesand calls the appropriate handler methods Nodes formats are described in InlineParser#parse -
#tt?(tag) ⇒ Boolean
Is
taga tt tag?
Constructor Details
.new(options, markup = nil) ⇒ Formatter
Creates a new Formatter
Class Method Details
.gen_relative_url(path, target)
Converts a target url to one that is relative to a given path
# File 'lib/rdoc/markup/formatter.rb', line 27
def self.gen_relative_url(path, target) from = File.dirname path to, to_file = File.split target from = from.split "/" to = to.split "/" from.delete '.' to.delete '.' while from.size > 0 and to.size > 0 and from[0] == to[0] do from.shift to.shift end from.fill ".." from.concat to from << to_file File.join(*from) end
Instance Method Details
#accept_document(document)
Adds document to the output
#add_regexp_handling_RDOCLINK
Adds a regexp handling for links of the form rdoc-…:
# File 'lib/rdoc/markup/formatter.rb', line 76
def add_regexp_handling_RDOCLINK @markup.add_regexp_handling(/rdoc-[a-z]:[^\s\]]/, :RDOCLINK) end
#annotate(tag)
Allows tag to be decorated with additional information.
# File 'lib/rdoc/markup/formatter.rb', line 83
def annotate(tag) tag end
#apply_regexp_handling(text)
Applies regexp handling to text and returns an array of [text, converted?] pairs.
# File 'lib/rdoc/markup/formatter.rb', line 96
def apply_regexp_handling(text) output = [] start = 0 loop do pos = text.size matched_name = matched_text = nil @markup.regexp_handlings.each do |pattern, name| m = text.match(pattern, start) next unless m idx = m[1] ? 1 : 0 if m.begin(idx) < pos pos = m.begin(idx) matched_text = m[idx] matched_name = name end end output << [text[start...pos], false] if pos > start if matched_name handled = public_send(:"handle_regexp_#{matched_name}", matched_text) output << [handled, true] start = pos + matched_text.size else start = pos end break if pos == text.size end output end
#convert(content)
Marks up content
# File 'lib/rdoc/markup/formatter.rb', line 90
def convert(content) @markup.convert content, self end
#convert_string(string)
Converts a string to be fancier if desired
# File 'lib/rdoc/markup/formatter.rb', line 243
def convert_string(string) string end
#handle_BOLD(nodes)
Called when processing bold nodes while traversing inline nodes from handle_inline. Traverse the children nodes and dispatch to the appropriate handlers.
# File 'lib/rdoc/markup/formatter.rb', line 158
def handle_BOLD(nodes) traverse_inline_nodes(nodes) end
#handle_BOLD_WORD(word)
Called when processing bold word nodes while traversing inline nodes from handle_inline. word may need proper escaping.
# File 'lib/rdoc/markup/formatter.rb', line 172
def handle_BOLD_WORD(word) handle_PLAIN_TEXT(word) end
#handle_EM(nodes)
Called when processing emphasis nodes while traversing inline nodes from handle_inline. Traverse the children nodes and dispatch to the appropriate handlers.
# File 'lib/rdoc/markup/formatter.rb', line 165
def handle_EM(nodes) traverse_inline_nodes(nodes) end
#handle_EM_WORD(word)
Called when processing emphasis word nodes while traversing inline nodes from handle_inline. word may need proper escaping.
# File 'lib/rdoc/markup/formatter.rb', line 179
def handle_EM_WORD(word) handle_PLAIN_TEXT(word) end
#handle_HARD_BREAK
Called when processing a hard break while traversing inline nodes from handle_inline.
# File 'lib/rdoc/markup/formatter.rb', line 152
def handle_HARD_BREAK end
#handle_inline(text)
Parses inline text, traverse the resulting nodes, and calls the appropriate handler methods.
# File 'lib/rdoc/markup/formatter.rb', line 208
def handle_inline(text) nodes = RDoc::Markup::InlineParser.new(text).parse traverse_inline_nodes(nodes) end
#handle_PLAIN_TEXT(text)
Called when processing plain text while traversing inline nodes from handle_inline. text may need proper escaping.
# File 'lib/rdoc/markup/formatter.rb', line 128
def handle_PLAIN_TEXT(text) end
#handle_REGEXP_HANDLING_TEXT(text)
Called when processing regexp-handling-processed text while traversing inline nodes from handle_inline. text may contain markup tags.
# File 'lib/rdoc/markup/formatter.rb', line 134
def handle_REGEXP_HANDLING_TEXT(text) end
#handle_STRIKE(nodes)
Called when processing strike nodes while traversing inline nodes from handle_inline. Traverse the children nodes and dispatch to the appropriate handlers.
# File 'lib/rdoc/markup/formatter.rb', line 193
def handle_STRIKE(nodes) traverse_inline_nodes(nodes) end
#handle_TEXT(text)
Called when processing text node while traversing inline nodes from handle_inline. Apply regexp handling and dispatch to the appropriate handler: handle_REGEXP_HANDLING_TEXT or handle_PLAIN_TEXT.
# File 'lib/rdoc/markup/formatter.rb', line 140
def handle_TEXT(text) apply_regexp_handling(text).each do |part, converted| if converted handle_REGEXP_HANDLING_TEXT(part) else handle_PLAIN_TEXT(part) end end end
#handle_TIDYLINK(label_part, url)
Called when processing tidylink nodes while traversing inline nodes from handle_inline. label_part is an array of strings or nodes representing the link label. url is the link URL. Traverse the label_part nodes and dispatch to the appropriate handlers.
# File 'lib/rdoc/markup/formatter.rb', line 202
def handle_TIDYLINK(label_part, url) traverse_inline_nodes(label_part) end
#handle_TT(code)
Called when processing tt nodes while traversing inline nodes from handle_inline. code may need proper escaping.
# File 'lib/rdoc/markup/formatter.rb', line 186
def handle_TT(code) handle_PLAIN_TEXT(code) end
#ignore(*node) Also known as: #accept_raw, #accept_rule, #accept_block_quote, #accept_heading, #accept_list_end, #accept_list_item_end, #accept_list_item_start, #accept_list_start, #accept_raw, #accept_rule, #accept_verbatim, #accept_table, #accept_block_quote, #accept_raw, #accept_rule, #accept_blank_line, #accept_paragraph, #accept_verbatim, #accept_list_end, #accept_list_item_start, #accept_list_item_end, #accept_list_end_bullet, #accept_list_start, #accept_table
Use ignore in your subclass to ignore the content of a node.
##
# We don't support raw nodes in ToNoRaw
alias accept_raw ignore
# File 'lib/rdoc/markup/formatter.rb', line 255
def ignore *node end
#parse_url(url)
Extracts and a scheme, url and an anchor id from url and returns them.
# File 'lib/rdoc/markup/formatter.rb', line 261
def parse_url(url) case url when /^rdoc-label:([^:]*)(?::(.*))?/ then scheme = 'link' path = "##{$1}" id = " id=\"#{$2}\"" if $2 when /([A-Za-z]+):(.*)/ then scheme = $1.downcase path = $2 when /^#/ then else scheme = 'http' path = url url = url end if scheme == 'link' then url = if path[0, 1] == '#' then # is this meaningful? path else self.class.gen_relative_url @from_path, path end end [scheme, url, id] end
#traverse_inline_nodes(nodes)
Traverses nodes and calls the appropriate handler methods Nodes formats are described in InlineParser#parse
# File 'lib/rdoc/markup/formatter.rb', line 216
def traverse_inline_nodes(nodes) nodes.each do |node| next handle_TEXT(node) if String === node case node[:type] when :TIDYLINK handle_TIDYLINK(node[:children], node[:url]) when :HARD_BREAK handle_HARD_BREAK when :BOLD handle_BOLD(node[:children]) when :BOLD_WORD handle_BOLD_WORD(node[:children][0] || '') when :EM handle_EM(node[:children]) when :EM_WORD handle_EM_WORD(node[:children][0] || '') when :TT handle_TT(node[:children][0] || '') when :STRIKE handle_STRIKE(node[:children]) end end end
#tt?(tag) ⇒ Boolean
Is tag a tt tag?
# File 'lib/rdoc/markup/formatter.rb', line 291
def tt?(tag) tag.bit == @tt_bit end