1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/lib/rdoc/markup/heading.rb
drbrain df7dac9174 * lib/rdoc: Update to RDoc 4.1.0.preview.1
RDoc 4.1.0 contains a number of enhancements including a new default
  style and accessibility support.  You can see the changelog here:

  https://github.com/rdoc/rdoc/blob/v4.1.0.preview.1/History.rdoc

* test/rdoc:  ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42971 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-18 23:33:36 +00:00

78 lines
1.5 KiB
Ruby

##
# A heading with a level (1-6) and text
RDoc::Markup::Heading =
Struct.new :level, :text do
@to_html = nil
@to_label = nil
##
# A singleton RDoc::Markup::ToLabel formatter for headings.
def self.to_label
@to_label ||= RDoc::Markup::ToLabel.new
end
##
# A singleton plain HTML formatter for headings. Used for creating labels
# for the Table of Contents
def self.to_html
return @to_html if @to_html
markup = RDoc::Markup.new
markup.add_special RDoc::CrossReference::CROSSREF_REGEXP, :CROSSREF
@to_html = RDoc::Markup::ToHtml.new nil
def @to_html.handle_special_CROSSREF special
special.text.sub(/^\\/, '')
end
@to_html
end
##
# Calls #accept_heading on +visitor+
def accept visitor
visitor.accept_heading self
end
##
# An HTML-safe anchor reference for this header.
def aref
"label-#{self.class.to_label.convert text.dup}"
end
##
# Creates a fully-qualified label which will include the label from
# +context+. This helps keep ids unique in HTML.
def label context = nil
label = aref
label = [context.aref, label].compact.join '-' if
context and context.respond_to? :aref
label
end
##
# HTML markup of the text of this label without the surrounding header
# element.
def plain_html
self.class.to_html.to_html(text.dup)
end
def pretty_print q # :nodoc:
q.group 2, "[head: #{level} ", ']' do
q.pp text
end
end
end