mirror of
https://github.com/ruby/ruby.git
synced 2025-08-23 21:14:23 +02:00
Sync RDoc 6.14.0
This commit is contained in:
parent
ca1ea95784
commit
03eb777c69
185 changed files with 2008 additions and 1655 deletions
|
@ -107,7 +107,7 @@ class RDoc::Markup::AttributeManager
|
|||
##
|
||||
# Changes the current attribute from +current+ to +new+
|
||||
|
||||
def change_attribute current, new
|
||||
def change_attribute(current, new)
|
||||
diff = current ^ new
|
||||
attribute(new & diff, current & diff)
|
||||
end
|
||||
|
@ -116,7 +116,7 @@ class RDoc::Markup::AttributeManager
|
|||
# Used by the tests to change attributes by name from +current_set+ to
|
||||
# +new_set+
|
||||
|
||||
def changed_attribute_by_name current_set, new_set
|
||||
def changed_attribute_by_name(current_set, new_set)
|
||||
current = new = 0
|
||||
current_set.each do |name|
|
||||
current |= @attributes.bitmap_for(name)
|
||||
|
@ -220,7 +220,7 @@ class RDoc::Markup::AttributeManager
|
|||
##
|
||||
# Converts regexp handling sequences to RDoc attributes
|
||||
|
||||
def convert_regexp_handlings str, attrs, exclusive = false
|
||||
def convert_regexp_handlings(str, attrs, exclusive = false)
|
||||
@regexp_handlings.each do |regexp, attribute|
|
||||
next unless exclusive == exclusive?(attribute)
|
||||
str.scan(regexp) do
|
||||
|
@ -295,7 +295,7 @@ class RDoc::Markup::AttributeManager
|
|||
#
|
||||
# @am.add_regexp_handling(/((https?:)\S+\w)/, :HYPERLINK)
|
||||
|
||||
def add_regexp_handling pattern, name, exclusive = false
|
||||
def add_regexp_handling(pattern, name, exclusive = false)
|
||||
bitmap = @attributes.bitmap_for(name)
|
||||
@regexp_handlings << [pattern, bitmap]
|
||||
@exclusive_bitmap |= bitmap if exclusive
|
||||
|
@ -304,7 +304,7 @@ class RDoc::Markup::AttributeManager
|
|||
##
|
||||
# Processes +str+ converting attributes, HTML and regexp handlings
|
||||
|
||||
def flow str
|
||||
def flow(str)
|
||||
@str = str.dup
|
||||
|
||||
mask_protected_sequences
|
||||
|
|
|
@ -26,7 +26,7 @@ class RDoc::Markup::Attributes
|
|||
##
|
||||
# Returns a unique bit for +name+
|
||||
|
||||
def bitmap_for name
|
||||
def bitmap_for(name)
|
||||
bitmap = @name_to_bitmap.assoc name
|
||||
|
||||
unless bitmap then
|
||||
|
@ -43,7 +43,7 @@ class RDoc::Markup::Attributes
|
|||
##
|
||||
# Returns a string representation of +bitmap+
|
||||
|
||||
def as_string bitmap
|
||||
def as_string(bitmap)
|
||||
return 'none' if bitmap.zero?
|
||||
res = []
|
||||
|
||||
|
@ -57,7 +57,7 @@ class RDoc::Markup::Attributes
|
|||
##
|
||||
# yields each attribute name in +bitmap+
|
||||
|
||||
def each_name_of bitmap
|
||||
def each_name_of(bitmap)
|
||||
return enum_for __method__, bitmap unless block_given?
|
||||
|
||||
@name_to_bitmap.each do |name, bit|
|
||||
|
|
|
@ -16,11 +16,11 @@ class RDoc::Markup::BlankLine
|
|||
##
|
||||
# Calls #accept_blank_line on +visitor+
|
||||
|
||||
def accept visitor
|
||||
def accept(visitor)
|
||||
visitor.accept_blank_line self
|
||||
end
|
||||
|
||||
def pretty_print q # :nodoc:
|
||||
def pretty_print(q) # :nodoc:
|
||||
q.text 'blankline'
|
||||
end
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ class RDoc::Markup::BlockQuote < RDoc::Markup::Raw
|
|||
##
|
||||
# Calls #accept_block_quote on +visitor+
|
||||
|
||||
def accept visitor
|
||||
def accept(visitor)
|
||||
visitor.accept_block_quote self
|
||||
end
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ class RDoc::Markup::Document
|
|||
##
|
||||
# Appends +part+ to the document
|
||||
|
||||
def << part
|
||||
def <<(part)
|
||||
case part
|
||||
when RDoc::Markup::Document then
|
||||
unless part.empty? then
|
||||
|
@ -53,7 +53,7 @@ class RDoc::Markup::Document
|
|||
end
|
||||
end
|
||||
|
||||
def == other # :nodoc:
|
||||
def ==(other) # :nodoc:
|
||||
self.class == other.class and
|
||||
@file == other.file and
|
||||
@parts == other.parts
|
||||
|
@ -62,7 +62,7 @@ class RDoc::Markup::Document
|
|||
##
|
||||
# Runs this document and all its #items through +visitor+
|
||||
|
||||
def accept visitor
|
||||
def accept(visitor)
|
||||
visitor.start_accepting
|
||||
|
||||
visitor.accept_document self
|
||||
|
@ -73,14 +73,14 @@ class RDoc::Markup::Document
|
|||
##
|
||||
# Concatenates the given +parts+ onto the document
|
||||
|
||||
def concat parts
|
||||
def concat(parts)
|
||||
self.parts.concat parts
|
||||
end
|
||||
|
||||
##
|
||||
# Enumerator for the parts of this document
|
||||
|
||||
def each &block
|
||||
def each(&block)
|
||||
@parts.each(&block)
|
||||
end
|
||||
|
||||
|
@ -94,7 +94,7 @@ class RDoc::Markup::Document
|
|||
##
|
||||
# The file this Document was created from.
|
||||
|
||||
def file= location
|
||||
def file=(location)
|
||||
@file = case location
|
||||
when RDoc::TopLevel then
|
||||
location.relative_name
|
||||
|
@ -111,7 +111,7 @@ class RDoc::Markup::Document
|
|||
#
|
||||
# The information in +other+ is preferred over the receiver
|
||||
|
||||
def merge other
|
||||
def merge(other)
|
||||
if empty? then
|
||||
@parts = other.parts
|
||||
return self
|
||||
|
@ -135,7 +135,7 @@ class RDoc::Markup::Document
|
|||
RDoc::Markup::Document === @parts.first
|
||||
end
|
||||
|
||||
def pretty_print q # :nodoc:
|
||||
def pretty_print(q) # :nodoc:
|
||||
start = @file ? "[doc (#{@file}): " : '[doc: '
|
||||
|
||||
q.group 2, start, ']' do
|
||||
|
|
|
@ -21,7 +21,7 @@ class RDoc::Markup::Formatter
|
|||
##
|
||||
# Converts a target url to one that is relative to a given path
|
||||
|
||||
def self.gen_relative_url path, target
|
||||
def self.gen_relative_url(path, target)
|
||||
from = File.dirname path
|
||||
to, to_file = File.split target
|
||||
|
||||
|
@ -45,7 +45,7 @@ class RDoc::Markup::Formatter
|
|||
##
|
||||
# Creates a new Formatter
|
||||
|
||||
def initialize options, markup = nil
|
||||
def initialize(options, markup = nil)
|
||||
@options = options
|
||||
|
||||
@markup = markup || RDoc::Markup.new
|
||||
|
@ -66,7 +66,7 @@ class RDoc::Markup::Formatter
|
|||
##
|
||||
# Adds +document+ to the output
|
||||
|
||||
def accept_document document
|
||||
def accept_document(document)
|
||||
document.parts.each do |item|
|
||||
case item
|
||||
when RDoc::Markup::Document then # HACK
|
||||
|
@ -117,7 +117,7 @@ class RDoc::Markup::Formatter
|
|||
##
|
||||
# Marks up +content+
|
||||
|
||||
def convert content
|
||||
def convert(content)
|
||||
@markup.convert content, self
|
||||
end
|
||||
|
||||
|
@ -147,7 +147,7 @@ class RDoc::Markup::Formatter
|
|||
##
|
||||
# Converts added regexp handlings. See RDoc::Markup#add_regexp_handling
|
||||
|
||||
def convert_regexp_handling target
|
||||
def convert_regexp_handling(target)
|
||||
return target.text if in_tt?
|
||||
|
||||
handled = false
|
||||
|
@ -173,7 +173,7 @@ class RDoc::Markup::Formatter
|
|||
##
|
||||
# Converts a string to be fancier if desired
|
||||
|
||||
def convert_string string
|
||||
def convert_string(string)
|
||||
string
|
||||
end
|
||||
|
||||
|
@ -195,7 +195,7 @@ class RDoc::Markup::Formatter
|
|||
@in_tt > 0
|
||||
end
|
||||
|
||||
def tt_tag? attr_mask, reverse = false
|
||||
def tt_tag?(attr_mask, reverse = false)
|
||||
each_attr_tag(attr_mask, reverse) do |tag|
|
||||
return true if tt? tag
|
||||
end
|
||||
|
@ -205,7 +205,7 @@ class RDoc::Markup::Formatter
|
|||
##
|
||||
# Turns on tags for +item+ on +res+
|
||||
|
||||
def on_tags res, item
|
||||
def on_tags(res, item)
|
||||
each_attr_tag(item.turn_on) do |tag|
|
||||
res << annotate(tag.on)
|
||||
@in_tt += 1 if tt? tag
|
||||
|
@ -215,14 +215,14 @@ class RDoc::Markup::Formatter
|
|||
##
|
||||
# Turns off tags for +item+ on +res+
|
||||
|
||||
def off_tags res, item
|
||||
def off_tags(res, item)
|
||||
each_attr_tag(item.turn_off, true) do |tag|
|
||||
@in_tt -= 1 if tt? tag
|
||||
res << annotate(tag.off)
|
||||
end
|
||||
end
|
||||
|
||||
def each_attr_tag attr_mask, reverse = false
|
||||
def each_attr_tag(attr_mask, reverse = false)
|
||||
return if attr_mask.zero?
|
||||
|
||||
@attr_tags.public_send(reverse ? :reverse_each : :each) do |tag|
|
||||
|
@ -235,7 +235,7 @@ class RDoc::Markup::Formatter
|
|||
##
|
||||
# Extracts and a scheme, url and an anchor id from +url+ and returns them.
|
||||
|
||||
def parse_url url
|
||||
def parse_url(url)
|
||||
case url
|
||||
when /^rdoc-label:([^:]*)(?::(.*))?/ then
|
||||
scheme = 'link'
|
||||
|
@ -265,7 +265,7 @@ class RDoc::Markup::Formatter
|
|||
##
|
||||
# Is +tag+ a tt tag?
|
||||
|
||||
def tt? tag
|
||||
def tt?(tag)
|
||||
tag.bit == @tt_bit
|
||||
end
|
||||
|
||||
|
|
|
@ -16,15 +16,15 @@ class RDoc::Markup::HardBreak
|
|||
##
|
||||
# Calls #accept_hard_break on +visitor+
|
||||
|
||||
def accept visitor
|
||||
def accept(visitor)
|
||||
visitor.accept_hard_break self
|
||||
end
|
||||
|
||||
def == other # :nodoc:
|
||||
def ==(other) # :nodoc:
|
||||
self.class === other
|
||||
end
|
||||
|
||||
def pretty_print q # :nodoc:
|
||||
def pretty_print(q) # :nodoc:
|
||||
q.text "[break]"
|
||||
end
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ RDoc::Markup::Heading =
|
|||
|
||||
@to_html = RDoc::Markup::ToHtml.new nil
|
||||
|
||||
def @to_html.handle_regexp_CROSSREF target
|
||||
def @to_html.handle_regexp_CROSSREF(target)
|
||||
target.text.sub(/^\\/, '')
|
||||
end
|
||||
|
||||
|
@ -37,7 +37,7 @@ RDoc::Markup::Heading =
|
|||
##
|
||||
# Calls #accept_heading on +visitor+
|
||||
|
||||
def accept visitor
|
||||
def accept(visitor)
|
||||
visitor.accept_heading self
|
||||
end
|
||||
|
||||
|
@ -52,7 +52,7 @@ RDoc::Markup::Heading =
|
|||
# Creates a fully-qualified label which will include the label from
|
||||
# +context+. This helps keep ids unique in HTML.
|
||||
|
||||
def label context = nil
|
||||
def label(context = nil)
|
||||
label = aref
|
||||
|
||||
label = [context.aref, label].compact.join '-' if
|
||||
|
@ -66,10 +66,16 @@ RDoc::Markup::Heading =
|
|||
# element.
|
||||
|
||||
def plain_html
|
||||
self.class.to_html.to_html(text.dup)
|
||||
text = self.text.dup
|
||||
|
||||
if matched = text.match(/rdoc-image:[^:]+:(.*)/)
|
||||
text = matched[1]
|
||||
end
|
||||
|
||||
self.class.to_html.to_html(text)
|
||||
end
|
||||
|
||||
def pretty_print q # :nodoc:
|
||||
def pretty_print(q) # :nodoc:
|
||||
q.group 2, "[head: #{level} ", ']' do
|
||||
q.pp text
|
||||
end
|
||||
|
|
|
@ -20,17 +20,17 @@ class RDoc::Markup::Include
|
|||
##
|
||||
# Creates a new include that will import +file+ from +include_path+
|
||||
|
||||
def initialize file, include_path
|
||||
def initialize(file, include_path)
|
||||
@file = file
|
||||
@include_path = include_path
|
||||
end
|
||||
|
||||
def == other # :nodoc:
|
||||
def ==(other) # :nodoc:
|
||||
self.class === other and
|
||||
@file == other.file and @include_path == other.include_path
|
||||
end
|
||||
|
||||
def pretty_print q # :nodoc:
|
||||
def pretty_print(q) # :nodoc:
|
||||
q.group 2, '[incl ', ']' do
|
||||
q.text file
|
||||
q.breakable
|
||||
|
|
|
@ -19,14 +19,14 @@ class RDoc::Markup::IndentedParagraph < RDoc::Markup::Raw
|
|||
super(*parts)
|
||||
end
|
||||
|
||||
def == other # :nodoc:
|
||||
def ==(other) # :nodoc:
|
||||
super and indent == other.indent
|
||||
end
|
||||
|
||||
##
|
||||
# Calls #accept_indented_paragraph on +visitor+
|
||||
|
||||
def accept visitor
|
||||
def accept(visitor)
|
||||
visitor.accept_indented_paragraph self
|
||||
end
|
||||
|
||||
|
@ -34,7 +34,7 @@ class RDoc::Markup::IndentedParagraph < RDoc::Markup::Raw
|
|||
# Joins the raw paragraph text and converts inline HardBreaks to the
|
||||
# +hard_break+ text followed by the indent.
|
||||
|
||||
def text hard_break = nil
|
||||
def text(hard_break = nil)
|
||||
@parts.map do |part|
|
||||
if RDoc::Markup::HardBreak === part then
|
||||
'%1$s%3$*2$s' % [hard_break, @indent, ' '] if hard_break
|
||||
|
|
|
@ -46,11 +46,11 @@ class RDoc::Markup::List
|
|||
##
|
||||
# Appends +item+ to the list
|
||||
|
||||
def << item
|
||||
def <<(item)
|
||||
@items << item
|
||||
end
|
||||
|
||||
def == other # :nodoc:
|
||||
def ==(other) # :nodoc:
|
||||
self.class == other.class and
|
||||
@type == other.type and
|
||||
@items == other.items
|
||||
|
@ -59,7 +59,7 @@ class RDoc::Markup::List
|
|||
##
|
||||
# Runs this list and all its #items through +visitor+
|
||||
|
||||
def accept visitor
|
||||
def accept(visitor)
|
||||
visitor.accept_list_start self
|
||||
|
||||
@items.each do |item|
|
||||
|
@ -83,7 +83,7 @@ class RDoc::Markup::List
|
|||
@items.last
|
||||
end
|
||||
|
||||
def pretty_print q # :nodoc:
|
||||
def pretty_print(q) # :nodoc:
|
||||
q.group 2, "[list: #{@type} ", ']' do
|
||||
q.seplist @items do |item|
|
||||
q.pp item
|
||||
|
|
|
@ -33,11 +33,11 @@ class RDoc::Markup::ListItem
|
|||
##
|
||||
# Appends +part+ to the ListItem
|
||||
|
||||
def << part
|
||||
def <<(part)
|
||||
@parts << part
|
||||
end
|
||||
|
||||
def == other # :nodoc:
|
||||
def ==(other) # :nodoc:
|
||||
self.class == other.class and
|
||||
@label == other.label and
|
||||
@parts == other.parts
|
||||
|
@ -46,7 +46,7 @@ class RDoc::Markup::ListItem
|
|||
##
|
||||
# Runs this list item and all its #parts through +visitor+
|
||||
|
||||
def accept visitor
|
||||
def accept(visitor)
|
||||
visitor.accept_list_item_start self
|
||||
|
||||
@parts.each do |part|
|
||||
|
@ -70,7 +70,7 @@ class RDoc::Markup::ListItem
|
|||
@parts.length
|
||||
end
|
||||
|
||||
def pretty_print q # :nodoc:
|
||||
def pretty_print(q) # :nodoc:
|
||||
q.group 2, '[item: ', ']' do
|
||||
case @label
|
||||
when Array then
|
||||
|
|
|
@ -7,7 +7,7 @@ class RDoc::Markup::Paragraph < RDoc::Markup::Raw
|
|||
##
|
||||
# Calls #accept_paragraph on +visitor+
|
||||
|
||||
def accept visitor
|
||||
def accept(visitor)
|
||||
visitor.accept_paragraph self
|
||||
end
|
||||
|
||||
|
@ -15,7 +15,7 @@ class RDoc::Markup::Paragraph < RDoc::Markup::Raw
|
|||
# Joins the raw paragraph text and converts inline HardBreaks to the
|
||||
# +hard_break+ text.
|
||||
|
||||
def text hard_break = ''
|
||||
def text(hard_break = '')
|
||||
@parts.map do |part|
|
||||
if RDoc::Markup::HardBreak === part then
|
||||
hard_break
|
||||
|
|
|
@ -57,7 +57,7 @@ class RDoc::Markup::Parser
|
|||
#
|
||||
# Use RDoc::Markup#parse instead of this method.
|
||||
|
||||
def self.parse str
|
||||
def self.parse(str)
|
||||
parser = new
|
||||
parser.tokenize str
|
||||
doc = RDoc::Markup::Document.new
|
||||
|
@ -67,7 +67,7 @@ class RDoc::Markup::Parser
|
|||
##
|
||||
# Returns a token stream for +str+, for testing
|
||||
|
||||
def self.tokenize str
|
||||
def self.tokenize(str)
|
||||
parser = new
|
||||
parser.tokenize str
|
||||
parser.tokens
|
||||
|
@ -87,7 +87,7 @@ class RDoc::Markup::Parser
|
|||
##
|
||||
# Builds a Heading of +level+
|
||||
|
||||
def build_heading level
|
||||
def build_heading(level)
|
||||
type, text, = get
|
||||
|
||||
text = case type
|
||||
|
@ -105,7 +105,7 @@ class RDoc::Markup::Parser
|
|||
##
|
||||
# Builds a List flush to +margin+
|
||||
|
||||
def build_list margin
|
||||
def build_list(margin)
|
||||
p :list_start => margin if @debug
|
||||
|
||||
list = RDoc::Markup::List.new
|
||||
|
@ -205,7 +205,7 @@ class RDoc::Markup::Parser
|
|||
##
|
||||
# Builds a Paragraph that is flush to +margin+
|
||||
|
||||
def build_paragraph margin
|
||||
def build_paragraph(margin)
|
||||
p :paragraph_start => margin if @debug
|
||||
|
||||
paragraph = RDoc::Markup::Paragraph.new
|
||||
|
@ -240,7 +240,7 @@ class RDoc::Markup::Parser
|
|||
# terminated by a newline. Blank lines always consist of a single newline
|
||||
# character, and there is never a single newline at the end of the verbatim.
|
||||
|
||||
def build_verbatim margin
|
||||
def build_verbatim(margin)
|
||||
p :verbatim_begin => margin if @debug
|
||||
verbatim = RDoc::Markup::Verbatim.new
|
||||
|
||||
|
@ -339,7 +339,7 @@ class RDoc::Markup::Parser
|
|||
#
|
||||
# Returns +parent+.
|
||||
|
||||
def parse parent, indent = 0
|
||||
def parse(parent, indent = 0)
|
||||
p :parse_start => indent if @debug
|
||||
|
||||
until @tokens.empty? do
|
||||
|
@ -403,7 +403,7 @@ class RDoc::Markup::Parser
|
|||
##
|
||||
# Small hook that is overridden by RDoc::TomDoc
|
||||
|
||||
def parse_text parent, indent # :nodoc:
|
||||
def parse_text(parent, indent) # :nodoc:
|
||||
parent << build_paragraph(indent)
|
||||
end
|
||||
|
||||
|
@ -465,7 +465,7 @@ class RDoc::Markup::Parser
|
|||
##
|
||||
# Creates the StringScanner
|
||||
|
||||
def setup_scanner input
|
||||
def setup_scanner(input)
|
||||
@s = MyStringScanner.new input
|
||||
end
|
||||
|
||||
|
@ -474,7 +474,7 @@ class RDoc::Markup::Parser
|
|||
#
|
||||
# Optionally raises an error if the next token is not of the expected type.
|
||||
|
||||
def skip token_type, error = true
|
||||
def skip(token_type, error = true)
|
||||
type, = get
|
||||
return unless type # end of stream
|
||||
return @current_token if token_type == type
|
||||
|
@ -485,7 +485,7 @@ class RDoc::Markup::Parser
|
|||
##
|
||||
# Turns text +input+ into a stream of tokens
|
||||
|
||||
def tokenize input
|
||||
def tokenize(input)
|
||||
setup_scanner input
|
||||
|
||||
until @s.eos? do
|
||||
|
|
|
@ -27,7 +27,7 @@ class RDoc::Markup::PreProcess
|
|||
# with the result RDoc::Comment (or text String) and the code object for the
|
||||
# comment (if any).
|
||||
|
||||
def self.post_process &block
|
||||
def self.post_process(&block)
|
||||
@post_processors << block
|
||||
end
|
||||
|
||||
|
@ -50,7 +50,7 @@ class RDoc::Markup::PreProcess
|
|||
# # replace text, etc.
|
||||
# end
|
||||
|
||||
def self.register directive, &block
|
||||
def self.register(directive, &block)
|
||||
@registered[directive] = block
|
||||
end
|
||||
|
||||
|
@ -96,7 +96,7 @@ class RDoc::Markup::PreProcess
|
|||
# directive's parameter is set as metadata on the +code_object+. See
|
||||
# RDoc::CodeObject#metadata for details.
|
||||
|
||||
def handle text, code_object = nil, &block
|
||||
def handle(text, code_object = nil, &block)
|
||||
first_line = 1
|
||||
if RDoc::Comment === text then
|
||||
comment = text
|
||||
|
@ -150,8 +150,8 @@ class RDoc::Markup::PreProcess
|
|||
#--
|
||||
# When 1.8.7 support is ditched prefix can be defaulted to ''
|
||||
|
||||
def handle_directive prefix, directive, param, code_object = nil,
|
||||
encoding = nil, line = nil
|
||||
def handle_directive(prefix, directive, param, code_object = nil,
|
||||
encoding = nil, line = nil)
|
||||
blankline = "#{prefix.strip}\n"
|
||||
directive = directive.downcase
|
||||
|
||||
|
@ -279,7 +279,7 @@ class RDoc::Markup::PreProcess
|
|||
# TODO shift left the whole file content in that case
|
||||
# TODO comment stop/start #-- and #++ in included file must be processed here
|
||||
|
||||
def include_file name, indent, encoding
|
||||
def include_file(name, indent, encoding)
|
||||
full_name = find_include_file name
|
||||
|
||||
unless full_name then
|
||||
|
|
|
@ -20,29 +20,29 @@ class RDoc::Markup::Raw
|
|||
##
|
||||
# Appends +text+
|
||||
|
||||
def << text
|
||||
def <<(text)
|
||||
@parts << text
|
||||
end
|
||||
|
||||
def == other # :nodoc:
|
||||
def ==(other) # :nodoc:
|
||||
self.class == other.class and @parts == other.parts
|
||||
end
|
||||
|
||||
##
|
||||
# Calls #accept_raw+ on +visitor+
|
||||
|
||||
def accept visitor
|
||||
def accept(visitor)
|
||||
visitor.accept_raw self
|
||||
end
|
||||
|
||||
##
|
||||
# Appends +other+'s parts
|
||||
|
||||
def merge other
|
||||
def merge(other)
|
||||
@parts.concat other.parts
|
||||
end
|
||||
|
||||
def pretty_print q # :nodoc:
|
||||
def pretty_print(q) # :nodoc:
|
||||
self.class.name =~ /.*::(\w{1,4})/i
|
||||
|
||||
q.group 2, "[#{$1.downcase}: ", ']' do
|
||||
|
|
|
@ -7,11 +7,11 @@ class RDoc::Markup::Rule < Struct.new :weight
|
|||
##
|
||||
# Calls #accept_rule on +visitor+
|
||||
|
||||
def accept visitor
|
||||
def accept(visitor)
|
||||
visitor.accept_rule self
|
||||
end
|
||||
|
||||
def pretty_print q # :nodoc:
|
||||
def pretty_print(q) # :nodoc:
|
||||
q.group 2, '[rule:', ']' do
|
||||
q.pp weight
|
||||
end
|
||||
|
|
|
@ -13,23 +13,23 @@ class RDoc::Markup::Table
|
|||
attr_accessor :body
|
||||
|
||||
# Creates new instance
|
||||
def initialize header, align, body
|
||||
def initialize(header, align, body)
|
||||
@header, @align, @body = header, align, body
|
||||
end
|
||||
|
||||
# :stopdoc:
|
||||
def == other
|
||||
def ==(other)
|
||||
self.class == other.class and
|
||||
@header == other.header and
|
||||
@align == other.align and
|
||||
@body == other.body
|
||||
end
|
||||
|
||||
def accept visitor
|
||||
def accept(visitor)
|
||||
visitor.accept_table @header, @body, @align
|
||||
end
|
||||
|
||||
def pretty_print q
|
||||
def pretty_print(q)
|
||||
q.group 2, '[Table: ', ']' do
|
||||
q.group 2, '[Head: ', ']' do
|
||||
q.seplist @header.zip(@align) do |text, align|
|
||||
|
|
|
@ -7,7 +7,7 @@ class RDoc::Markup::ToAnsi < RDoc::Markup::ToRdoc
|
|||
##
|
||||
# Creates a new ToAnsi visitor that is ready to output vibrant ANSI color!
|
||||
|
||||
def initialize markup = nil
|
||||
def initialize(markup = nil)
|
||||
super
|
||||
|
||||
@headings.clear
|
||||
|
@ -28,7 +28,7 @@ class RDoc::Markup::ToAnsi < RDoc::Markup::ToRdoc
|
|||
##
|
||||
# Overrides indent width to ensure output lines up correctly.
|
||||
|
||||
def accept_list_item_end list_item
|
||||
def accept_list_item_end(list_item)
|
||||
width = case @list_type.last
|
||||
when :BULLET then
|
||||
2
|
||||
|
@ -52,7 +52,7 @@ class RDoc::Markup::ToAnsi < RDoc::Markup::ToRdoc
|
|||
##
|
||||
# Adds coloring to note and label list items
|
||||
|
||||
def accept_list_item_start list_item
|
||||
def accept_list_item_start(list_item)
|
||||
bullet = case @list_type.last
|
||||
when :BULLET then
|
||||
'*'
|
||||
|
|
|
@ -10,7 +10,7 @@ class RDoc::Markup::ToBs < RDoc::Markup::ToRdoc
|
|||
##
|
||||
# Returns a new ToBs that is ready for hot backspace action!
|
||||
|
||||
def initialize markup = nil
|
||||
def initialize(markup = nil)
|
||||
super
|
||||
|
||||
@in_b = false
|
||||
|
@ -30,7 +30,7 @@ class RDoc::Markup::ToBs < RDoc::Markup::ToRdoc
|
|||
##
|
||||
# Makes heading text bold.
|
||||
|
||||
def accept_heading heading
|
||||
def accept_heading(heading)
|
||||
use_prefix or @res << ' ' * @indent
|
||||
@res << @headings[heading.level][0]
|
||||
@in_b = true
|
||||
|
@ -43,7 +43,7 @@ class RDoc::Markup::ToBs < RDoc::Markup::ToRdoc
|
|||
##
|
||||
# Prepares the visitor for consuming +list_item+
|
||||
|
||||
def accept_list_item_start list_item
|
||||
def accept_list_item_start(list_item)
|
||||
type = @list_type.last
|
||||
|
||||
case type
|
||||
|
@ -68,7 +68,7 @@ class RDoc::Markup::ToBs < RDoc::Markup::ToRdoc
|
|||
##
|
||||
# Turns on or off regexp handling for +convert_string+
|
||||
|
||||
def annotate tag
|
||||
def annotate(tag)
|
||||
case tag
|
||||
when '+b' then @in_b = true
|
||||
when '-b' then @in_b = false
|
||||
|
@ -81,14 +81,14 @@ class RDoc::Markup::ToBs < RDoc::Markup::ToRdoc
|
|||
##
|
||||
# Calls convert_string on the result of convert_regexp_handling
|
||||
|
||||
def convert_regexp_handling target
|
||||
def convert_regexp_handling(target)
|
||||
convert_string super
|
||||
end
|
||||
|
||||
##
|
||||
# Adds bold or underline mixed with backspaces
|
||||
|
||||
def convert_string string
|
||||
def convert_string(string)
|
||||
return string unless @in_b or @in_em
|
||||
chars = if @in_b then
|
||||
string.chars.map do |char| "#{char}\b#{char}" end
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
require 'cgi/util'
|
||||
require 'cgi/escape'
|
||||
# For CGI.unescape on earlier rubies
|
||||
require 'cgi/util' if RUBY_VERSION < '3.5'
|
||||
|
||||
##
|
||||
# Outputs RDoc markup as HTML.
|
||||
|
@ -42,7 +44,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|||
##
|
||||
# Creates a new formatter that will output HTML
|
||||
|
||||
def initialize options, markup = nil
|
||||
def initialize(options, markup = nil)
|
||||
super
|
||||
|
||||
@code_object = nil
|
||||
|
@ -82,7 +84,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|||
add_regexp_handling_TIDYLINK
|
||||
end
|
||||
|
||||
def handle_RDOCLINK url # :nodoc:
|
||||
def handle_RDOCLINK(url) # :nodoc:
|
||||
case url
|
||||
when /^rdoc-ref:/
|
||||
CGI.escapeHTML($')
|
||||
|
@ -98,7 +100,15 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|||
|
||||
gen_url CGI.escapeHTML(url), CGI.escapeHTML(text)
|
||||
when /^rdoc-image:/
|
||||
%[<img src=\"#{CGI.escapeHTML($')}\">]
|
||||
# Split the string after "rdoc-image:" into url and alt.
|
||||
# "path/to/image.jpg:alt text" => ["path/to/image.jpg", "alt text"]
|
||||
# "http://example.com/path/to/image.jpg:alt text" => ["http://example.com/path/to/image.jpg", "alt text"]
|
||||
url, alt = $'.split(/:(?!\/)/, 2)
|
||||
if alt && !alt.empty?
|
||||
%[<img src="#{CGI.escapeHTML(url)}" alt="#{CGI.escapeHTML(alt)}">]
|
||||
else
|
||||
%[<img src="#{CGI.escapeHTML(url)}">]
|
||||
end
|
||||
when /\Ardoc-[a-z]+:/
|
||||
CGI.escapeHTML($')
|
||||
end
|
||||
|
@ -107,7 +117,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|||
##
|
||||
# +target+ is a <code><br></code>
|
||||
|
||||
def handle_regexp_HARD_BREAK target
|
||||
def handle_regexp_HARD_BREAK(target)
|
||||
'<br>'
|
||||
end
|
||||
|
||||
|
@ -138,7 +148,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|||
# For the +rdoc-label+ scheme the footnote and label prefixes are stripped
|
||||
# when creating a link. All other contents will be linked verbatim.
|
||||
|
||||
def handle_regexp_RDOCLINK target
|
||||
def handle_regexp_RDOCLINK(target)
|
||||
handle_RDOCLINK target.text
|
||||
end
|
||||
|
||||
|
@ -187,7 +197,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|||
##
|
||||
# Adds +block_quote+ to the output
|
||||
|
||||
def accept_block_quote block_quote
|
||||
def accept_block_quote(block_quote)
|
||||
@res << "\n<blockquote>"
|
||||
|
||||
block_quote.parts.each do |part|
|
||||
|
@ -200,7 +210,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|||
##
|
||||
# Adds +paragraph+ to the output
|
||||
|
||||
def accept_paragraph paragraph
|
||||
def accept_paragraph(paragraph)
|
||||
@res << "\n<p>"
|
||||
text = paragraph.text @hard_break
|
||||
text = text.gsub(/(#{SPACE_SEPARATED_LETTER_CLASS})?\K\r?\n(?=(?(1)(#{SPACE_SEPARATED_LETTER_CLASS})?))/o) {
|
||||
|
@ -213,7 +223,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|||
##
|
||||
# Adds +verbatim+ to the output
|
||||
|
||||
def accept_verbatim verbatim
|
||||
def accept_verbatim(verbatim)
|
||||
text = verbatim.text.rstrip
|
||||
|
||||
klass = nil
|
||||
|
@ -243,7 +253,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|||
##
|
||||
# Adds +rule+ to the output
|
||||
|
||||
def accept_rule rule
|
||||
def accept_rule(rule)
|
||||
@res << "<hr>\n"
|
||||
end
|
||||
|
||||
|
@ -296,7 +306,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|||
# Adds +heading+ to the output. The headings greater than 6 are trimmed to
|
||||
# level 6.
|
||||
|
||||
def accept_heading heading
|
||||
def accept_heading(heading)
|
||||
level = [6, heading.level].min
|
||||
|
||||
label = heading.label @code_object
|
||||
|
@ -317,14 +327,14 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|||
##
|
||||
# Adds +raw+ to the output
|
||||
|
||||
def accept_raw raw
|
||||
def accept_raw(raw)
|
||||
@res << raw.parts.join("\n")
|
||||
end
|
||||
|
||||
##
|
||||
# Adds +table+ to the output
|
||||
|
||||
def accept_table header, body, aligns
|
||||
def accept_table(header, body, aligns)
|
||||
@res << "\n<table role=\"table\">\n<thead>\n<tr>\n"
|
||||
header.zip(aligns) do |text, align|
|
||||
@res << '<th'
|
||||
|
@ -357,7 +367,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|||
# Generate a link to +url+ with content +text+. Handles the special cases
|
||||
# for img: and link: described under handle_regexp_HYPERLINK
|
||||
|
||||
def gen_url url, text
|
||||
def gen_url(url, text)
|
||||
scheme, url, id = parse_url url
|
||||
|
||||
if %w[http https link].include?(scheme) and
|
||||
|
@ -431,7 +441,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|||
##
|
||||
# Returns true if text is valid ruby syntax
|
||||
|
||||
def parseable? text
|
||||
def parseable?(text)
|
||||
verbose, $VERBOSE = $VERBOSE, nil
|
||||
catch(:valid) do
|
||||
eval("BEGIN { throw :valid, true }\n#{text}")
|
||||
|
@ -445,7 +455,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|||
##
|
||||
# Converts +item+ to HTML using RDoc::Text#to_html
|
||||
|
||||
def to_html item
|
||||
def to_html(item)
|
||||
super convert_flow @am.flow item
|
||||
end
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
|
|||
# Creates a link to the reference +name+ if the name exists. If +text+ is
|
||||
# given it is used as the link text, otherwise +name+ is used.
|
||||
|
||||
def cross_reference name, text = nil, code = true, rdoc_ref: false
|
||||
def cross_reference(name, text = nil, code = true, rdoc_ref: false)
|
||||
lookup = name
|
||||
|
||||
name = name[1..-1] unless @show_hash if name[0, 1] == '#'
|
||||
|
@ -83,6 +83,8 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
|
|||
def handle_regexp_CROSSREF(target)
|
||||
name = target.text
|
||||
|
||||
return name if @options.autolink_excluded_words&.include?(name)
|
||||
|
||||
return name if name =~ /@[\w-]+\.[\w-]/ # labels that look like emails
|
||||
|
||||
unless @hyperlink_all then
|
||||
|
@ -99,7 +101,7 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
|
|||
# Handles <tt>rdoc-ref:</tt> scheme links and allows RDoc::Markup::ToHtml to
|
||||
# handle other schemes.
|
||||
|
||||
def handle_regexp_HYPERLINK target
|
||||
def handle_regexp_HYPERLINK(target)
|
||||
url = target.text
|
||||
|
||||
case url
|
||||
|
@ -118,7 +120,7 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
|
|||
# All other contents are handled by
|
||||
# {the superclass}[rdoc-ref:RDoc::Markup::ToHtml#handle_regexp_RDOCLINK]
|
||||
|
||||
def handle_regexp_RDOCLINK target
|
||||
def handle_regexp_RDOCLINK(target)
|
||||
url = target.text
|
||||
|
||||
case url
|
||||
|
@ -133,7 +135,7 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
|
|||
# Generates links for <tt>rdoc-ref:</tt> scheme URLs and allows
|
||||
# RDoc::Markup::ToHtml to handle other schemes.
|
||||
|
||||
def gen_url url, text
|
||||
def gen_url(url, text)
|
||||
if url =~ /\Ardoc-ref:/
|
||||
name = $'
|
||||
cross_reference name, text, name == text, rdoc_ref: true
|
||||
|
@ -145,7 +147,7 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
|
|||
##
|
||||
# Creates an HTML link to +name+ with the given +text+.
|
||||
|
||||
def link name, text, code = true, rdoc_ref: false
|
||||
def link(name, text, code = true, rdoc_ref: false)
|
||||
if !(name.end_with?('+@', '-@')) and name =~ /(.*[^#:])?@/
|
||||
name = $1
|
||||
label = $'
|
||||
|
|
|
@ -34,7 +34,7 @@ class RDoc::Markup::ToHtmlSnippet < RDoc::Markup::ToHtml
|
|||
# next word boundary after the given number of +characters+ or +paragraphs+
|
||||
# of text have been encountered.
|
||||
|
||||
def initialize options, characters = 100, paragraphs = 3, markup = nil
|
||||
def initialize(options, characters = 100, paragraphs = 3, markup = nil)
|
||||
super options, markup
|
||||
|
||||
@character_limit = characters
|
||||
|
@ -50,7 +50,7 @@ class RDoc::Markup::ToHtmlSnippet < RDoc::Markup::ToHtml
|
|||
##
|
||||
# Adds +heading+ to the output as a paragraph
|
||||
|
||||
def accept_heading heading
|
||||
def accept_heading(heading)
|
||||
@res << "<p>#{to_html heading.text}\n"
|
||||
|
||||
add_paragraph
|
||||
|
@ -69,7 +69,7 @@ class RDoc::Markup::ToHtmlSnippet < RDoc::Markup::ToHtml
|
|||
##
|
||||
# Adds +paragraph+ to the output
|
||||
|
||||
def accept_paragraph paragraph
|
||||
def accept_paragraph(paragraph)
|
||||
para = @in_list_entry.last || "<p>"
|
||||
|
||||
text = paragraph.text @hard_break
|
||||
|
@ -82,20 +82,20 @@ class RDoc::Markup::ToHtmlSnippet < RDoc::Markup::ToHtml
|
|||
##
|
||||
# Finishes consumption of +list_item+
|
||||
|
||||
def accept_list_item_end list_item
|
||||
def accept_list_item_end(list_item)
|
||||
end
|
||||
|
||||
##
|
||||
# Prepares the visitor for consuming +list_item+
|
||||
|
||||
def accept_list_item_start list_item
|
||||
def accept_list_item_start(list_item)
|
||||
@res << list_item_start(list_item, @list.last)
|
||||
end
|
||||
|
||||
##
|
||||
# Prepares the visitor for consuming +list+
|
||||
|
||||
def accept_list_start list
|
||||
def accept_list_start(list)
|
||||
@list << list.type
|
||||
@res << html_list_name(list.type, true)
|
||||
@in_list_entry.push ''
|
||||
|
@ -104,7 +104,7 @@ class RDoc::Markup::ToHtmlSnippet < RDoc::Markup::ToHtml
|
|||
##
|
||||
# Adds +verbatim+ to the output
|
||||
|
||||
def accept_verbatim verbatim
|
||||
def accept_verbatim(verbatim)
|
||||
throw :done if @characters >= @character_limit
|
||||
input = verbatim.text.rstrip
|
||||
|
||||
|
@ -128,14 +128,14 @@ class RDoc::Markup::ToHtmlSnippet < RDoc::Markup::ToHtml
|
|||
##
|
||||
# Removes escaping from the cross-references in +target+
|
||||
|
||||
def handle_regexp_CROSSREF target
|
||||
def handle_regexp_CROSSREF(target)
|
||||
target.text.sub(/\A\\/, '')
|
||||
end
|
||||
|
||||
##
|
||||
# +target+ is a <code><br></code>
|
||||
|
||||
def handle_regexp_HARD_BREAK target
|
||||
def handle_regexp_HARD_BREAK(target)
|
||||
@characters -= 4
|
||||
'<br>'
|
||||
end
|
||||
|
@ -143,7 +143,7 @@ class RDoc::Markup::ToHtmlSnippet < RDoc::Markup::ToHtml
|
|||
##
|
||||
# Lists are paragraphs, but notes and labels have a separator
|
||||
|
||||
def list_item_start list_item, list_type
|
||||
def list_item_start(list_item, list_type)
|
||||
throw :done if @characters >= @character_limit
|
||||
|
||||
case list_type
|
||||
|
@ -168,7 +168,7 @@ class RDoc::Markup::ToHtmlSnippet < RDoc::Markup::ToHtml
|
|||
# Returns just the text of +link+, +url+ is only used to determine the link
|
||||
# type.
|
||||
|
||||
def gen_url url, text
|
||||
def gen_url(url, text)
|
||||
if url =~ /^rdoc-label:([^:]*)(?::(.*))?/ then
|
||||
type = "link"
|
||||
elsif url =~ /([A-Za-z]+):(.*)/ then
|
||||
|
@ -188,7 +188,7 @@ class RDoc::Markup::ToHtmlSnippet < RDoc::Markup::ToHtml
|
|||
##
|
||||
# In snippets, there are no lists
|
||||
|
||||
def html_list_name list_type, open_tag
|
||||
def html_list_name(list_type, open_tag)
|
||||
''
|
||||
end
|
||||
|
||||
|
@ -204,7 +204,7 @@ class RDoc::Markup::ToHtmlSnippet < RDoc::Markup::ToHtml
|
|||
##
|
||||
# Marks up +content+
|
||||
|
||||
def convert content
|
||||
def convert(content)
|
||||
catch :done do
|
||||
return super
|
||||
end
|
||||
|
@ -215,7 +215,7 @@ class RDoc::Markup::ToHtmlSnippet < RDoc::Markup::ToHtml
|
|||
##
|
||||
# Converts flow items +flow+
|
||||
|
||||
def convert_flow flow
|
||||
def convert_flow(flow)
|
||||
throw :done if @characters >= @character_limit
|
||||
|
||||
res = []
|
||||
|
@ -251,7 +251,7 @@ class RDoc::Markup::ToHtmlSnippet < RDoc::Markup::ToHtml
|
|||
# Maintains a bitmask to allow HTML elements to be closed properly. See
|
||||
# RDoc::Markup::Formatter.
|
||||
|
||||
def on_tags res, item
|
||||
def on_tags(res, item)
|
||||
@mask ^= item.turn_on
|
||||
|
||||
super
|
||||
|
@ -261,7 +261,7 @@ class RDoc::Markup::ToHtmlSnippet < RDoc::Markup::ToHtml
|
|||
# Maintains a bitmask to allow HTML elements to be closed properly. See
|
||||
# RDoc::Markup::Formatter.
|
||||
|
||||
def off_tags res, item
|
||||
def off_tags(res, item)
|
||||
@mask ^= item.turn_off
|
||||
|
||||
super
|
||||
|
@ -270,7 +270,7 @@ class RDoc::Markup::ToHtmlSnippet < RDoc::Markup::ToHtml
|
|||
##
|
||||
# Truncates +text+ at the end of the first word after the character_limit.
|
||||
|
||||
def truncate text
|
||||
def truncate(text)
|
||||
length = text.length
|
||||
characters = @characters
|
||||
@characters += length
|
||||
|
|
|
@ -22,7 +22,7 @@ class RDoc::Markup::ToJoinedParagraph < RDoc::Markup::Formatter
|
|||
##
|
||||
# Converts the parts of +paragraph+ to a single entry.
|
||||
|
||||
def accept_paragraph paragraph
|
||||
def accept_paragraph(paragraph)
|
||||
parts = paragraph.parts.chunk do |part|
|
||||
String === part
|
||||
end.flat_map do |string, chunk|
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
require 'cgi/util'
|
||||
require 'cgi/escape'
|
||||
|
||||
##
|
||||
# Creates HTML-safe labels suitable for use in id attributes. Tidylinks are
|
||||
|
@ -13,7 +13,7 @@ class RDoc::Markup::ToLabel < RDoc::Markup::Formatter
|
|||
##
|
||||
# Creates a new formatter that will output HTML-safe labels
|
||||
|
||||
def initialize markup = nil
|
||||
def initialize(markup = nil)
|
||||
super nil, markup
|
||||
|
||||
@markup.add_regexp_handling RDoc::CrossReference::CROSSREF_REGEXP, :CROSSREF
|
||||
|
@ -29,7 +29,7 @@ class RDoc::Markup::ToLabel < RDoc::Markup::Formatter
|
|||
##
|
||||
# Converts +text+ to an HTML-safe label
|
||||
|
||||
def convert text
|
||||
def convert(text)
|
||||
label = convert_flow @am.flow text
|
||||
|
||||
CGI.escape(label).gsub('%', '-').sub(/^-/, '')
|
||||
|
@ -39,7 +39,7 @@ class RDoc::Markup::ToLabel < RDoc::Markup::Formatter
|
|||
# Converts the CROSSREF +target+ to plain text, removing the suppression
|
||||
# marker, if any
|
||||
|
||||
def handle_regexp_CROSSREF target
|
||||
def handle_regexp_CROSSREF(target)
|
||||
text = target.text
|
||||
|
||||
text.sub(/^\\/, '')
|
||||
|
@ -48,7 +48,7 @@ class RDoc::Markup::ToLabel < RDoc::Markup::Formatter
|
|||
##
|
||||
# Converts the TIDYLINK +target+ to just the text part
|
||||
|
||||
def handle_regexp_TIDYLINK target
|
||||
def handle_regexp_TIDYLINK(target)
|
||||
text = target.text
|
||||
|
||||
return text unless text =~ /\{(.*?)\}\[(.*?)\]/ or text =~ /(\S+)\[(.*?)\]/
|
||||
|
|
|
@ -9,7 +9,7 @@ class RDoc::Markup::ToMarkdown < RDoc::Markup::ToRdoc
|
|||
##
|
||||
# Creates a new formatter that will output Markdown format text
|
||||
|
||||
def initialize markup = nil
|
||||
def initialize(markup = nil)
|
||||
super
|
||||
|
||||
@headings[1] = ['# ', '']
|
||||
|
@ -37,21 +37,21 @@ class RDoc::Markup::ToMarkdown < RDoc::Markup::ToRdoc
|
|||
##
|
||||
# Adds a newline to the output
|
||||
|
||||
def handle_regexp_HARD_BREAK target
|
||||
def handle_regexp_HARD_BREAK(target)
|
||||
" \n"
|
||||
end
|
||||
|
||||
##
|
||||
# Finishes consumption of `list`
|
||||
|
||||
def accept_list_end list
|
||||
def accept_list_end(list)
|
||||
super
|
||||
end
|
||||
|
||||
##
|
||||
# Finishes consumption of `list_item`
|
||||
|
||||
def accept_list_item_end list_item
|
||||
def accept_list_item_end(list_item)
|
||||
width = case @list_type.last
|
||||
when :BULLET then
|
||||
4
|
||||
|
@ -72,7 +72,7 @@ class RDoc::Markup::ToMarkdown < RDoc::Markup::ToRdoc
|
|||
##
|
||||
# Prepares the visitor for consuming `list_item`
|
||||
|
||||
def accept_list_item_start list_item
|
||||
def accept_list_item_start(list_item)
|
||||
type = @list_type.last
|
||||
|
||||
case type
|
||||
|
@ -97,7 +97,7 @@ class RDoc::Markup::ToMarkdown < RDoc::Markup::ToRdoc
|
|||
##
|
||||
# Prepares the visitor for consuming `list`
|
||||
|
||||
def accept_list_start list
|
||||
def accept_list_start(list)
|
||||
case list.type
|
||||
when :BULLET, :LABEL, :NOTE then
|
||||
@list_index << nil
|
||||
|
@ -114,7 +114,7 @@ class RDoc::Markup::ToMarkdown < RDoc::Markup::ToRdoc
|
|||
##
|
||||
# Adds `rule` to the output
|
||||
|
||||
def accept_rule rule
|
||||
def accept_rule(rule)
|
||||
use_prefix or @res << ' ' * @indent
|
||||
@res << '-' * 3
|
||||
@res << "\n"
|
||||
|
@ -123,7 +123,7 @@ class RDoc::Markup::ToMarkdown < RDoc::Markup::ToRdoc
|
|||
##
|
||||
# Outputs `verbatim` indented 4 columns
|
||||
|
||||
def accept_verbatim verbatim
|
||||
def accept_verbatim(verbatim)
|
||||
indent = ' ' * (@indent + 4)
|
||||
|
||||
verbatim.parts.each do |part|
|
||||
|
@ -137,7 +137,7 @@ class RDoc::Markup::ToMarkdown < RDoc::Markup::ToRdoc
|
|||
##
|
||||
# Creates a Markdown-style URL from +url+ with +text+.
|
||||
|
||||
def gen_url url, text
|
||||
def gen_url(url, text)
|
||||
scheme, url, = parse_url url
|
||||
|
||||
"[#{text.sub(%r{^#{scheme}:/*}i, '')}](#{url})"
|
||||
|
@ -146,7 +146,7 @@ class RDoc::Markup::ToMarkdown < RDoc::Markup::ToRdoc
|
|||
##
|
||||
# Handles <tt>rdoc-</tt> type links for footnotes.
|
||||
|
||||
def handle_rdoc_link url
|
||||
def handle_rdoc_link(url)
|
||||
case url
|
||||
when /^rdoc-ref:/ then
|
||||
$'
|
||||
|
@ -166,7 +166,7 @@ class RDoc::Markup::ToMarkdown < RDoc::Markup::ToRdoc
|
|||
##
|
||||
# Converts the RDoc markup tidylink into a Markdown.style link.
|
||||
|
||||
def handle_regexp_TIDYLINK target
|
||||
def handle_regexp_TIDYLINK(target)
|
||||
text = target.text
|
||||
|
||||
return text unless text =~ /\{(.*?)\}\[(.*?)\]/ or text =~ /(\S+)\[(.*?)\]/
|
||||
|
@ -184,7 +184,7 @@ class RDoc::Markup::ToMarkdown < RDoc::Markup::ToRdoc
|
|||
##
|
||||
# Converts the rdoc-...: links into a Markdown.style links.
|
||||
|
||||
def handle_regexp_RDOCLINK target
|
||||
def handle_regexp_RDOCLINK(target)
|
||||
handle_rdoc_link target.text
|
||||
end
|
||||
|
||||
|
|
|
@ -3,6 +3,16 @@
|
|||
# Outputs RDoc markup as RDoc markup! (mostly)
|
||||
|
||||
class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
|
||||
DEFAULT_HEADINGS = {
|
||||
1 => ['= ', ''],
|
||||
2 => ['== ', ''],
|
||||
3 => ['=== ', ''],
|
||||
4 => ['==== ', ''],
|
||||
5 => ['===== ', ''],
|
||||
6 => ['====== ', '']
|
||||
}
|
||||
DEFAULT_HEADINGS.default = []
|
||||
DEFAULT_HEADINGS.freeze
|
||||
|
||||
##
|
||||
# Current indent amount for output in characters
|
||||
|
@ -42,23 +52,14 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
|
|||
##
|
||||
# Creates a new formatter that will output (mostly) \RDoc markup
|
||||
|
||||
def initialize markup = nil
|
||||
def initialize(markup = nil)
|
||||
super nil, markup
|
||||
|
||||
@markup.add_regexp_handling(/\\\S/, :SUPPRESSED_CROSSREF)
|
||||
@width = 78
|
||||
init_tags
|
||||
|
||||
@headings = {}
|
||||
@headings.default = []
|
||||
|
||||
@headings[1] = ['= ', '']
|
||||
@headings[2] = ['== ', '']
|
||||
@headings[3] = ['=== ', '']
|
||||
@headings[4] = ['==== ', '']
|
||||
@headings[5] = ['===== ', '']
|
||||
@headings[6] = ['====== ', '']
|
||||
|
||||
@headings = DEFAULT_HEADINGS.dup
|
||||
@hard_break = "\n"
|
||||
end
|
||||
|
||||
|
@ -74,14 +75,14 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
|
|||
##
|
||||
# Adds +blank_line+ to the output
|
||||
|
||||
def accept_blank_line blank_line
|
||||
def accept_blank_line(blank_line)
|
||||
@res << "\n"
|
||||
end
|
||||
|
||||
##
|
||||
# Adds +paragraph+ to the output
|
||||
|
||||
def accept_block_quote block_quote
|
||||
def accept_block_quote(block_quote)
|
||||
@indent += 2
|
||||
|
||||
block_quote.parts.each do |part|
|
||||
|
@ -96,7 +97,7 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
|
|||
##
|
||||
# Adds +heading+ to the output
|
||||
|
||||
def accept_heading heading
|
||||
def accept_heading(heading)
|
||||
use_prefix or @res << ' ' * @indent
|
||||
@res << @headings[heading.level][0]
|
||||
@res << attributes(heading.text)
|
||||
|
@ -107,7 +108,7 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
|
|||
##
|
||||
# Finishes consumption of +list+
|
||||
|
||||
def accept_list_end list
|
||||
def accept_list_end(list)
|
||||
@list_index.pop
|
||||
@list_type.pop
|
||||
@list_width.pop
|
||||
|
@ -116,7 +117,7 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
|
|||
##
|
||||
# Finishes consumption of +list_item+
|
||||
|
||||
def accept_list_item_end list_item
|
||||
def accept_list_item_end(list_item)
|
||||
width = case @list_type.last
|
||||
when :BULLET then
|
||||
2
|
||||
|
@ -140,7 +141,7 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
|
|||
##
|
||||
# Prepares the visitor for consuming +list_item+
|
||||
|
||||
def accept_list_item_start list_item
|
||||
def accept_list_item_start(list_item)
|
||||
type = @list_type.last
|
||||
|
||||
case type
|
||||
|
@ -173,7 +174,7 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
|
|||
##
|
||||
# Prepares the visitor for consuming +list+
|
||||
|
||||
def accept_list_start list
|
||||
def accept_list_start(list)
|
||||
case list.type
|
||||
when :BULLET then
|
||||
@list_index << nil
|
||||
|
@ -200,7 +201,7 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
|
|||
##
|
||||
# Adds +paragraph+ to the output
|
||||
|
||||
def accept_paragraph paragraph
|
||||
def accept_paragraph(paragraph)
|
||||
text = paragraph.text @hard_break
|
||||
wrap attributes text
|
||||
end
|
||||
|
@ -208,7 +209,7 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
|
|||
##
|
||||
# Adds +paragraph+ to the output
|
||||
|
||||
def accept_indented_paragraph paragraph
|
||||
def accept_indented_paragraph(paragraph)
|
||||
@indent += paragraph.indent
|
||||
text = paragraph.text @hard_break
|
||||
wrap attributes text
|
||||
|
@ -218,14 +219,14 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
|
|||
##
|
||||
# Adds +raw+ to the output
|
||||
|
||||
def accept_raw raw
|
||||
def accept_raw(raw)
|
||||
@res << raw.parts.join("\n")
|
||||
end
|
||||
|
||||
##
|
||||
# Adds +rule+ to the output
|
||||
|
||||
def accept_rule rule
|
||||
def accept_rule(rule)
|
||||
use_prefix or @res << ' ' * @indent
|
||||
@res << '-' * (@width - @indent)
|
||||
@res << "\n"
|
||||
|
@ -234,7 +235,7 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
|
|||
##
|
||||
# Outputs +verbatim+ indented 2 columns
|
||||
|
||||
def accept_verbatim verbatim
|
||||
def accept_verbatim(verbatim)
|
||||
indent = ' ' * (@indent + 2)
|
||||
|
||||
verbatim.parts.each do |part|
|
||||
|
@ -248,7 +249,7 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
|
|||
##
|
||||
# Adds +table+ to the output
|
||||
|
||||
def accept_table header, body, aligns
|
||||
def accept_table(header, body, aligns)
|
||||
widths = header.zip(*body).map do |cols|
|
||||
cols.map(&:size).max
|
||||
end
|
||||
|
@ -276,7 +277,7 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
|
|||
##
|
||||
# Applies attribute-specific markup to +text+ using RDoc::AttributeManager
|
||||
|
||||
def attributes text
|
||||
def attributes(text)
|
||||
flow = @am.flow text.dup
|
||||
convert_flow flow
|
||||
end
|
||||
|
@ -291,7 +292,7 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
|
|||
##
|
||||
# Removes preceding \\ from the suppressed crossref +target+
|
||||
|
||||
def handle_regexp_SUPPRESSED_CROSSREF target
|
||||
def handle_regexp_SUPPRESSED_CROSSREF(target)
|
||||
text = target.text
|
||||
text = text.sub('\\', '') unless in_tt?
|
||||
text
|
||||
|
@ -300,7 +301,7 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
|
|||
##
|
||||
# Adds a newline to the output
|
||||
|
||||
def handle_regexp_HARD_BREAK target
|
||||
def handle_regexp_HARD_BREAK(target)
|
||||
"\n"
|
||||
end
|
||||
|
||||
|
@ -331,7 +332,7 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
|
|||
##
|
||||
# Wraps +text+ to #width
|
||||
|
||||
def wrap text
|
||||
def wrap(text)
|
||||
return unless text && !text.empty?
|
||||
|
||||
text_len = @width - @indent
|
||||
|
|
|
@ -33,7 +33,7 @@ class RDoc::Markup::ToTableOfContents < RDoc::Markup::Formatter
|
|||
##
|
||||
# Adds +document+ to the output, using its heading cutoff if present
|
||||
|
||||
def accept_document document
|
||||
def accept_document(document)
|
||||
@omit_headings_below = document.omit_headings_below
|
||||
|
||||
super
|
||||
|
@ -42,7 +42,7 @@ class RDoc::Markup::ToTableOfContents < RDoc::Markup::Formatter
|
|||
##
|
||||
# Adds +heading+ to the table of contents
|
||||
|
||||
def accept_heading heading
|
||||
def accept_heading(heading)
|
||||
@res << heading unless suppressed? heading
|
||||
end
|
||||
|
||||
|
@ -64,7 +64,7 @@ class RDoc::Markup::ToTableOfContents < RDoc::Markup::Formatter
|
|||
##
|
||||
# Returns true if +heading+ is below the display threshold
|
||||
|
||||
def suppressed? heading
|
||||
def suppressed?(heading)
|
||||
return false unless @omit_headings_below
|
||||
|
||||
heading.level > @omit_headings_below
|
||||
|
|
|
@ -22,7 +22,7 @@ class RDoc::Markup::ToTest < RDoc::Markup::Formatter
|
|||
@res << convert_flow(@am.flow(paragraph.text))
|
||||
end
|
||||
|
||||
def accept_raw raw
|
||||
def accept_raw(raw)
|
||||
@res << raw.parts.join
|
||||
end
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ class RDoc::Markup::ToTtOnly < RDoc::Markup::Formatter
|
|||
##
|
||||
# Creates a new tt-only formatter.
|
||||
|
||||
def initialize markup = nil
|
||||
def initialize(markup = nil)
|
||||
super nil, markup
|
||||
|
||||
add_tag :TT, nil, nil
|
||||
|
@ -27,28 +27,28 @@ class RDoc::Markup::ToTtOnly < RDoc::Markup::Formatter
|
|||
##
|
||||
# Adds tts from +block_quote+ to the output
|
||||
|
||||
def accept_block_quote block_quote
|
||||
def accept_block_quote(block_quote)
|
||||
tt_sections block_quote.text
|
||||
end
|
||||
|
||||
##
|
||||
# Pops the list type for +list+ from #list_type
|
||||
|
||||
def accept_list_end list
|
||||
def accept_list_end(list)
|
||||
@list_type.pop
|
||||
end
|
||||
|
||||
##
|
||||
# Pushes the list type for +list+ onto #list_type
|
||||
|
||||
def accept_list_start list
|
||||
def accept_list_start(list)
|
||||
@list_type << list.type
|
||||
end
|
||||
|
||||
##
|
||||
# Prepares the visitor for consuming +list_item+
|
||||
|
||||
def accept_list_item_start list_item
|
||||
def accept_list_item_start(list_item)
|
||||
case @list_type.last
|
||||
when :NOTE, :LABEL then
|
||||
Array(list_item.label).map do |label|
|
||||
|
@ -60,7 +60,7 @@ class RDoc::Markup::ToTtOnly < RDoc::Markup::Formatter
|
|||
##
|
||||
# Adds +paragraph+ to the output
|
||||
|
||||
def accept_paragraph paragraph
|
||||
def accept_paragraph(paragraph)
|
||||
tt_sections(paragraph.text)
|
||||
end
|
||||
|
||||
|
@ -68,7 +68,7 @@ class RDoc::Markup::ToTtOnly < RDoc::Markup::Formatter
|
|||
# Does nothing to +markup_item+ because it doesn't have any user-built
|
||||
# content
|
||||
|
||||
def do_nothing markup_item
|
||||
def do_nothing(markup_item)
|
||||
end
|
||||
|
||||
alias accept_blank_line do_nothing # :nodoc:
|
||||
|
@ -81,7 +81,7 @@ class RDoc::Markup::ToTtOnly < RDoc::Markup::Formatter
|
|||
##
|
||||
# Extracts tt sections from +text+
|
||||
|
||||
def tt_sections text
|
||||
def tt_sections(text)
|
||||
flow = @am.flow text.dup
|
||||
|
||||
flow.each do |item|
|
||||
|
|
|
@ -15,14 +15,14 @@ class RDoc::Markup::Verbatim < RDoc::Markup::Raw
|
|||
@format = nil
|
||||
end
|
||||
|
||||
def == other # :nodoc:
|
||||
def ==(other) # :nodoc:
|
||||
super and @format == other.format
|
||||
end
|
||||
|
||||
##
|
||||
# Calls #accept_verbatim on +visitor+
|
||||
|
||||
def accept visitor
|
||||
def accept(visitor)
|
||||
visitor.accept_verbatim self
|
||||
end
|
||||
|
||||
|
@ -50,7 +50,7 @@ class RDoc::Markup::Verbatim < RDoc::Markup::Raw
|
|||
@parts = parts
|
||||
end
|
||||
|
||||
def pretty_print q # :nodoc:
|
||||
def pretty_print(q) # :nodoc:
|
||||
self.class.name =~ /.*::(\w{1,4})/i
|
||||
|
||||
q.group 2, "[#{$1.downcase}: ", ']' do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue