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

This formatter uses HTML.

Methods

Public Instance methods

[Source]

     # File ri/formatter.rb, line 457
457:   def blankline()
458:     @output.puts("<p>")
459:   end

[Source]

     # File ri/formatter.rb, line 453
453:   def bold_print(txt)
454:     tag("b") { txt }
455:   end

[Source]

     # File ri/formatter.rb, line 461
461:   def break_to_newline
462:     @output.puts("<br>")
463:   end

[Source]

     # File ri/formatter.rb, line 465
465:   def display_heading(text, level, indent)
466:     level = 4 if level > 4
467:     tag("h#{level}") { text }
468:     @output.puts
469:   end

[Source]

     # File ri/formatter.rb, line 471
471:   def display_list(list)
472:     case list.type
473:     when :BULLET then
474:       list_type = "ul"
475:       prefixer = proc { |ignored| "<li>" }
476: 
477:     when :NUMBER, :UPPERALPHA, :LOWERALPHA then
478:       list_type = "ol"
479:       prefixer = proc { |ignored| "<li>" }
480: 
481:     when :LABELED then
482:       list_type = "dl"
483:       prefixer = proc do |li|
484:           "<dt><b>" + escape(li.label) + "</b><dd>"
485:       end
486: 
487:     when :NOTE then
488:       list_type = "table"
489:       prefixer = proc do |li|
490:           %{<tr valign="top"><td>#{li.label.gsub(/ /, '&nbsp;')}</td><td>}
491:       end
492:     else
493:       fail "unknown list type"
494:     end
495: 
496:     @output.print "<#{list_type}>"
497:     list.contents.each do |item|
498:       if item.kind_of? RDoc::Markup::Flow::LI
499:         prefix = prefixer.call(item)
500:         @output.print prefix
501:         display_flow_item(item, prefix)
502:       else
503:         display_flow_item(item)
504:       end
505:     end
506:     @output.print "</#{list_type}>"
507:   end

[Source]

     # File ri/formatter.rb, line 509
509:   def display_verbatim_flow_item(item, prefix=@indent)
510:     @output.print("<pre>")
511:     item.body.split(/\n/).each do |line|
512:       @output.puts conv_html(line)
513:     end
514:     @output.puts("</pre>")
515:   end

[Source]

     # File ri/formatter.rb, line 446
446:   def draw_line(label=nil)
447:     if label != nil
448:       bold_print(label)
449:     end
450:     @output.puts("<hr>")
451:   end

[Source]

     # File ri/formatter.rb, line 550
550:   def escape(str)
551:     str = str.gsub(/&/n, '&amp;')
552:     str.gsub!(/\"/n, '&quot;')
553:     str.gsub!(/>/n, '&gt;')
554:     str.gsub!(/</n, '&lt;')
555:     str
556:   end

[Source]

     # File ri/formatter.rb, line 544
544:   def tag(code)
545:     @output.print("<#{code}>")
546:     @output.print(yield)
547:     @output.print("</#{code}>")
548:   end

[Source]

     # File ri/formatter.rb, line 525
525:   def update_attributes(current, wanted)
526:     str = ""
527:     # first turn off unwanted ones
528:     off = current & ~wanted
529:     for quality in [ BOLD, ITALIC, CODE]
530:       if (off & quality) > 0
531:         str << "</" + ATTR_MAP[quality]
532:       end
533:     end
534: 
535:     # now turn on wanted
536:     for quality in [ BOLD, ITALIC, CODE]
537:       unless (wanted & quality).zero?
538:         str << "<" << ATTR_MAP[quality]
539:       end
540:     end
541:     @output.print str
542:   end

[Source]

     # File ri/formatter.rb, line 433
433:   def write_attribute_text(prefix, line)
434:     curr_attr = 0
435:     line.each do |achar|
436:       attr = achar.attr
437:       if achar.attr != curr_attr
438:         update_attributes(curr_attr, achar.attr)
439:         curr_attr = achar.attr
440:       end
441:       @output.print(escape(achar.char))
442:     end
443:     update_attributes(curr_attr, 0) unless curr_attr.zero?
444:   end

[Validate]