Class: RDoc::Markup::Heading

Inherits:
Struct
  • Object
show all
Defined in:
lib/rdoc/markup/heading.rb

Overview

A heading with a level (1-6) and text

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#levelObject

Returns the value of attribute level

Returns:

  • (Object)

    the current value of level



5
6
7
# File 'lib/rdoc/markup/heading.rb', line 5

def level
  @level
end

#textObject

Returns the value of attribute text

Returns:

  • (Object)

    the current value of text



5
6
7
# File 'lib/rdoc/markup/heading.rb', line 5

def text
  @text
end

Class Method Details

.handle_regexp_CROSSREF(target) ⇒ Object



30
31
32
# File 'lib/rdoc/markup/heading.rb', line 30

def @to_html.handle_regexp_CROSSREF(target)
  target.text.sub(/^\\/, '')
end

.to_htmlObject

A singleton plain HTML formatter for headings. Used for creating labels for the Table of Contents



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rdoc/markup/heading.rb', line 22

def self.to_html
  return @to_html if @to_html

  markup = RDoc::Markup.new
  markup.add_regexp_handling RDoc::CrossReference::CROSSREF_REGEXP, :CROSSREF

  @to_html = RDoc::Markup::ToHtml.new nil

  def @to_html.handle_regexp_CROSSREF(target)
    target.text.sub(/^\\/, '')
  end

  @to_html
end

.to_labelObject

A singleton RDoc::Markup::ToLabel formatter for headings.



14
15
16
# File 'lib/rdoc/markup/heading.rb', line 14

def self.to_label
  @to_label ||= RDoc::Markup::ToLabel.new
end

Instance Method Details

#accept(visitor) ⇒ Object

Calls #accept_heading on visitor



40
41
42
# File 'lib/rdoc/markup/heading.rb', line 40

def accept(visitor)
  visitor.accept_heading self
end

#arefObject

An HTML-safe anchor reference for this header.



47
48
49
# File 'lib/rdoc/markup/heading.rb', line 47

def aref
  "label-#{self.class.to_label.convert text.dup}"
end

#label(context = nil) ⇒ Object

Creates a fully-qualified label which will include the label from context. This helps keep ids unique in HTML.



55
56
57
58
59
60
61
62
# File 'lib/rdoc/markup/heading.rb', line 55

def label(context = nil)
  label = aref

  label = [context.aref, label].compact.join '-' if
    context and context.respond_to? :aref

  label
end

#plain_htmlObject

HTML markup of the text of this label without the surrounding header element.



68
69
70
71
72
73
74
75
76
# File 'lib/rdoc/markup/heading.rb', line 68

def plain_html
  text = self.text.dup

  if matched = text.match(/rdoc-image:[^:]+:(.*)/)
    text = matched[1]
  end

  self.class.to_html.to_html(text)
end

#pretty_print(q) ⇒ Object

:nodoc:



78
79
80
81
82
# File 'lib/rdoc/markup/heading.rb', line 78

def pretty_print(q) # :nodoc:
  q.group 2, "[head: #{level} ", ']' do
    q.pp text
  end
end