X7ROOT File Manager
Current Path:
/opt/alt/ruby19/lib64/ruby/1.9.1/rdoc/markup
opt
/
alt
/
ruby19
/
lib64
/
ruby
/
1.9.1
/
rdoc
/
markup
/
ðŸ“
..
📄
attribute_manager.rb
(7.8 KB)
📄
blank_line.rb
(361 B)
📄
document.rb
(2.42 KB)
📄
formatter.rb
(3.3 KB)
📄
formatter_test_case.rb
(15.71 KB)
📄
heading.rb
(314 B)
📄
indented_paragraph.rb
(534 B)
📄
inline.rb
(2.76 KB)
📄
list.rb
(1.08 KB)
📄
list_item.rb
(1.26 KB)
📄
paragraph.rb
(191 B)
📄
parser.rb
(12.65 KB)
📄
pre_process.rb
(6.33 KB)
📄
raw.rb
(965 B)
📄
rule.rb
(285 B)
📄
text_formatter_test_case.rb
(2.53 KB)
📄
to_ansi.rb
(1.79 KB)
📄
to_bs.rb
(1.7 KB)
📄
to_html.rb
(6.66 KB)
📄
to_html_crossref.rb
(3.34 KB)
📄
to_rdoc.rb
(5.58 KB)
📄
to_test.rb
(1.16 KB)
📄
to_tt_only.rb
(2.11 KB)
📄
verbatim.rb
(634 B)
Editing: to_rdoc.rb
require 'rdoc/markup/formatter' require 'rdoc/markup/inline' ## # Outputs RDoc markup as RDoc markup! (mostly) class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter ## # Current indent amount for output in characters attr_accessor :indent ## # Output width in characters attr_accessor :width ## # Stack of current list indexes for alphabetic and numeric lists attr_reader :list_index ## # Stack of list types attr_reader :list_type ## # Stack of list widths for indentation attr_reader :list_width ## # Prefix for the next list item. See #use_prefix attr_reader :prefix ## # Output accumulator attr_reader :res ## # Creates a new formatter that will output (mostly) \RDoc markup def initialize markup = nil super @markup.add_special(/\\\S/, :SUPPRESSED_CROSSREF) @width = 78 init_tags @headings = {} @headings.default = [] @headings[1] = ['= ', ''] @headings[2] = ['== ', ''] @headings[3] = ['=== ', ''] @headings[4] = ['==== ', ''] @headings[5] = ['===== ', ''] @headings[6] = ['====== ', ''] end ## # Maps attributes to HTML sequences def init_tags add_tag :BOLD, "<b>", "</b>" add_tag :TT, "<tt>", "</tt>" add_tag :EM, "<em>", "</em>" end ## # Adds +blank_line+ to the output def accept_blank_line blank_line @res << "\n" end ## # Adds +heading+ to the output def accept_heading heading use_prefix or @res << ' ' * @indent @res << @headings[heading.level][0] @res << attributes(heading.text) @res << @headings[heading.level][1] @res << "\n" end ## # Finishes consumption of +list+ def accept_list_end list @list_index.pop @list_type.pop @list_width.pop end ## # Finishes consumption of +list_item+ def accept_list_item_end list_item width = case @list_type.last when :BULLET then 2 when :NOTE, :LABEL then @res << "\n" 2 else bullet = @list_index.last.to_s @list_index[-1] = @list_index.last.succ bullet.length + 2 end @indent -= width end ## # Prepares the visitor for consuming +list_item+ def accept_list_item_start list_item type = @list_type.last case type when :NOTE, :LABEL then bullet = attributes(list_item.label) + ":\n" @prefix = ' ' * @indent @indent += 2 @prefix << bullet + (' ' * @indent) else bullet = type == :BULLET ? '*' : @list_index.last.to_s + '.' @prefix = (' ' * @indent) + bullet.ljust(bullet.length + 1) width = bullet.length + 1 @indent += width end end ## # Prepares the visitor for consuming +list+ def accept_list_start list case list.type when :BULLET then @list_index << nil @list_width << 1 when :LABEL, :NOTE then @list_index << nil @list_width << 2 when :LALPHA then @list_index << 'a' @list_width << list.items.length.to_s.length when :NUMBER then @list_index << 1 @list_width << list.items.length.to_s.length when :UALPHA then @list_index << 'A' @list_width << list.items.length.to_s.length else raise RDoc::Error, "invalid list type #{list.type}" end @list_type << list.type end ## # Adds +paragraph+ to the output def accept_paragraph paragraph wrap attributes(paragraph.text) end ## # Adds +paragraph+ to the output def accept_indented_paragraph paragraph @indent += paragraph.indent wrap attributes(paragraph.text) @indent -= paragraph.indent end ## # Adds +raw+ to the output def accept_raw raw @res << raw.parts.join("\n") end ## # Adds +rule+ to the output def accept_rule rule use_prefix or @res << ' ' * @indent @res << '-' * (@width - @indent) @res << "\n" end ## # Outputs +verbatim+ indented 2 columns def accept_verbatim verbatim indent = ' ' * (@indent + 2) verbatim.parts.each do |part| @res << indent unless part == "\n" @res << part end @res << "\n" unless @res =~ /\n\z/ end ## # Applies attribute-specific markup to +text+ using RDoc::AttributeManager def attributes text flow = @am.flow text.dup convert_flow flow end ## # Returns the generated output def end_accepting @res.join end ## # Removes preceding \\ from the suppressed crossref +special+ def handle_special_SUPPRESSED_CROSSREF special text = special.text text = text.sub('\\', '') unless in_tt? text end ## # Prepares the visitor for text generation def start_accepting @res = [""] @indent = 0 @prefix = nil @list_index = [] @list_type = [] @list_width = [] end ## # Adds the stored #prefix to the output and clears it. Lists generate a # prefix for later consumption. def use_prefix prefix = @prefix @prefix = nil @res << prefix if prefix prefix end ## # Wraps +text+ to #width def wrap text return unless text && !text.empty? text_len = @width - @indent text_len = 20 if text_len < 20 re = /^(.{0,#{text_len}})[ \n]/ next_prefix = ' ' * @indent prefix = @prefix || next_prefix @prefix = nil @res << prefix while text.length > text_len if text =~ re then @res << $1 text.slice!(0, $&.length) else @res << text.slice!(0, text_len) end @res << "\n" << next_prefix end if text.empty? then @res.pop @res.pop else @res << text @res << "\n" end end end
Upload File
Create Folder