In Files

RDoc::Text

Methods for manipulating comment text

Public Instance Methods

expand_tabs(text) click to toggle source

Expands tab characters in text to eight spaces

    # File lib/rdoc/text.rb, line 9
 9:   def expand_tabs text
10:     expanded = []
11: 
12:     text.each_line do |line|
13:       line.gsub!(/^(.{8}*?)([^\t\r\n]{0,7})\t/) do
14:         "#{$1}#{$2}#{' ' * (8 - $2.size)}"
15:       end until line !~ /\t/
16: 
17:       expanded << line
18:     end
19: 
20:     expanded.join
21:   end
flush_left(text) click to toggle source

Flush text left based on the shortest line

    # File lib/rdoc/text.rb, line 26
26:   def flush_left text
27:     indents = []
28: 
29:     text.each_line do |line|
30:       indents << (line =~ /[^\s]/ || 9999)
31:     end
32: 
33:     indent = indents.min
34: 
35:     flush = []
36: 
37:     text.each_line do |line|
38:       line[/^ {0,#{indent}}/] = ''
39:       flush << line
40:     end
41: 
42:     flush.join
43:   end
markup(text) click to toggle source

Convert a string in markup format into HTML. Removes the first paragraph tags if remove_para is true.

Requires the including class to implement formatter

    # File lib/rdoc/text.rb, line 51
51:   def markup text
52:     document = parse text
53: 
54:     document.accept formatter
55:   end
normalize_comment(text) click to toggle source

Strips hashes, expands tabs then flushes text to the left

    # File lib/rdoc/text.rb, line 60
60:   def normalize_comment text
61:     return text if text.empty?
62: 
63:     text = strip_hashes text
64:     text = expand_tabs text
65:     text = flush_left text
66:     strip_newlines text
67:   end
parse(text) click to toggle source

Normalizes text then builds a RDoc::Markup::Document from it

    # File lib/rdoc/text.rb, line 72
72:   def parse text
73:     return text if RDoc::Markup::Document === text
74: 
75:     text = normalize_comment text
76: 
77:     return RDoc::Markup::Document.new if text =~ /\A\n*\z/
78: 
79:     RDoc::Markup::Parser.parse text
80:   rescue RDoc::Markup::Parser::Error => e
81:     $stderr.puts While parsing markup, RDoc encountered a #{e.class}:#{e}\tfrom #{e.backtrace.join "\n\tfrom "}---8<---#{text}---8<---RDoc #{RDoc::VERSION}Ruby #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL} #{RUBY_RELEASE_DATE}Please file a bug report with the above information at:http://rubyforge.org/tracker/?atid=2472&group_id=627&func=browse
82:     raise
83:   end
strip_hashes(text) click to toggle source

Strips leading # characters from text

     # File lib/rdoc/text.rb, line 106
106:   def strip_hashes text
107:     return text if text =~ /^(?>\s*)[^\#]/
108:     text.gsub(/^\s*(#+)/) { $1.tr '#',' ' }
109:   end
strip_newlines(text) click to toggle source

Strips leading and trailing n characters from text

     # File lib/rdoc/text.rb, line 114
114:   def strip_newlines text
115:     text.gsub(/\A\n*(.*?)\n*\z/, '\1')
116:   end
strip_stars(text) click to toggle source

Strips /* */ style comments

     # File lib/rdoc/text.rb, line 121
121:   def strip_stars text
122:     text = text.gsub %Document-method:\s+[\w:.#]+%, ''
123:     text.sub!  %/\*+%       do " " * $&.length end
124:     text.sub!  %\*+/%       do " " * $&.length end
125:     text.gsub! %^[ \t]*\*% do " " * $&.length end
126:     text
127:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.