1## 2# A section of verbatim text 3 4class RDoc::Markup::Verbatim < RDoc::Markup::Raw 5 6 ## 7 # Format of this verbatim section 8 9 attr_accessor :format 10 11 def initialize *parts # :nodoc: 12 super 13 14 @format = nil 15 end 16 17 def == other # :nodoc: 18 super and @format == other.format 19 end 20 21 ## 22 # Calls #accept_verbatim on +visitor+ 23 24 def accept visitor 25 visitor.accept_verbatim self 26 end 27 28 ## 29 # Collapses 3+ newlines into two newlines 30 31 def normalize 32 parts = [] 33 34 newlines = 0 35 36 @parts.each do |part| 37 case part 38 when /^\s*\n/ then 39 newlines += 1 40 parts << part if newlines == 1 41 else 42 newlines = 0 43 parts << part 44 end 45 end 46 47 parts.pop if parts.last =~ /\A\r?\n\z/ 48 49 @parts = parts 50 end 51 52 def pretty_print q # :nodoc: 53 self.class.name =~ /.*::(\w{1,4})/i 54 55 q.group 2, "[#{$1.downcase}: ", ']' do 56 if @format then 57 q.text "format: #{@format}" 58 q.breakable 59 end 60 61 q.seplist @parts do |part| 62 q.pp part 63 end 64 end 65 end 66 67 ## 68 # Is this verbatim section ruby code? 69 70 def ruby? 71 @format ||= nil # TODO for older ri data, switch the tree to marshal_dump 72 @format == :ruby 73 end 74 75 ## 76 # The text of the section 77 78 def text 79 @parts.join 80 end 81 82end 83 84