Class RDoc::RI::AttributeFormatter
In: ri/formatter.rb
Parent: RDoc::RI::Formatter

Handle text with attributes. We‘re a base class: there are different presentation classes (one, for example, uses overstrikes to handle bold and underlining, while another using ANSI escape sequences.

Methods

Public Instance methods

[Source]

     # File ri/formatter.rb, line 314
314:   def add_attributes_to(txt)
315:     tokens = txt.split(%r{(</?(?:b|code|em|i|tt)>)})
316:     text = AttributeString.new
317:     attributes = 0
318:     tokens.each do |tok|
319:       case tok
320:       when %r{^</(\w+)>$} then attributes &= ~(ATTR_MAP[$1]||0)
321:       when %r{^<(\w+)>$}  then attributes  |= (ATTR_MAP[$1]||0)
322:       else
323:         tok.split(//).each {|ch| text << AttrChar.new(ch, attributes)}
324:       end
325:     end
326:     text
327:   end

[Source]

     # File ri/formatter.rb, line 308
308:   def bold_print(txt)
309:     @output.print txt
310:   end

Overrides base class. Looks for etc sequences and generates an array of AttrChars. This array is then used as the basis for the split.

[Source]

     # File ri/formatter.rb, line 276
276:   def wrap(txt, prefix=@indent, linelen=@width)
277:     return unless txt && !txt.empty?
278: 
279:     txt = add_attributes_to(txt)
280:     next_prefix = prefix.tr("^ ", " ")
281:     linelen -= prefix.size
282: 
283:     line = []
284: 
285:     until txt.empty?
286:       word = txt.next_word
287:       if word.size + line.size > linelen
288:         write_attribute_text(prefix, line)
289:         prefix = next_prefix
290:         line = []
291:       end
292:       line.concat(word)
293:     end
294: 
295:     write_attribute_text(prefix, line) if line.length > 0
296:   end

[Source]

     # File ri/formatter.rb, line 300
300:   def write_attribute_text(prefix, line)
301:     @output.print prefix
302:     line.each do |achar|
303:       @output.print achar.char
304:     end
305:     @output.puts
306:   end

[Validate]