2017-11-27 05:45:24 -05:00
|
|
|
# frozen_string_literal: true
|
2010-04-01 03:45:16 -04:00
|
|
|
##
|
|
|
|
# A section of verbatim text
|
|
|
|
|
2010-04-26 23:45:22 -04:00
|
|
|
class RDoc::Markup::Verbatim < RDoc::Markup::Raw
|
2010-04-01 03:45:16 -04:00
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
##
|
|
|
|
# Format of this verbatim section
|
|
|
|
|
|
|
|
attr_accessor :format
|
|
|
|
|
|
|
|
def initialize *parts # :nodoc:
|
|
|
|
super
|
|
|
|
|
|
|
|
@format = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def == other # :nodoc:
|
|
|
|
super and @format == other.format
|
|
|
|
end
|
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
##
|
|
|
|
# Calls #accept_verbatim on +visitor+
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
def accept visitor
|
|
|
|
visitor.accept_verbatim self
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Collapses 3+ newlines into two newlines
|
|
|
|
|
|
|
|
def normalize
|
|
|
|
parts = []
|
|
|
|
|
|
|
|
newlines = 0
|
|
|
|
|
|
|
|
@parts.each do |part|
|
|
|
|
case part
|
2010-12-19 22:22:49 -05:00
|
|
|
when /^\s*\n/ then
|
2010-04-01 03:45:16 -04:00
|
|
|
newlines += 1
|
2010-12-19 22:22:49 -05:00
|
|
|
parts << part if newlines == 1
|
2010-04-01 03:45:16 -04:00
|
|
|
else
|
|
|
|
newlines = 0
|
|
|
|
parts << part
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
parts.pop if parts.last =~ /\A\r?\n\z/
|
2010-04-01 03:45:16 -04:00
|
|
|
|
|
|
|
@parts = parts
|
|
|
|
end
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
def pretty_print q # :nodoc:
|
|
|
|
self.class.name =~ /.*::(\w{1,4})/i
|
|
|
|
|
|
|
|
q.group 2, "[#{$1.downcase}: ", ']' do
|
|
|
|
if @format then
|
|
|
|
q.text "format: #{@format}"
|
|
|
|
q.breakable
|
|
|
|
end
|
|
|
|
|
|
|
|
q.seplist @parts do |part|
|
|
|
|
q.pp part
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
2013-07-18 22:26:08 -04:00
|
|
|
# Is this verbatim section Ruby code?
|
2012-11-26 23:28:14 -05:00
|
|
|
|
|
|
|
def ruby?
|
|
|
|
@format ||= nil # TODO for older ri data, switch the tree to marshal_dump
|
|
|
|
@format == :ruby
|
|
|
|
end
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
##
|
|
|
|
# The text of the section
|
|
|
|
|
|
|
|
def text
|
|
|
|
@parts.join
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|