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
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue