123456789_123456789_123456789_123456789_123456789_

Class: RDoc::Markup::Heading

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Element
Instance Chain:
self, Element
Inherits: RDoc::Markup::Element
Defined in: lib/rdoc/markup/heading.rb

Overview

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

RDoc syntax:
 = Heading 1
 == Heading 2
 === Heading 3

Markdown syntax:
 # Heading 1
 ## Heading 2
 ### Heading 3

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Element - Inherited

#accept

: (untyped) -> void.

#pretty_print

: (PP) -> void.

Constructor Details

.new(level, text) ⇒ Heading

: (Integer, String) -> void

[ GitHub ]

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

def initialize(level, text)
  super()

  @level = level
  @text = text
end

Class Method Details

.to_html

A singleton plain HTML formatter for headings. Used for creating labels for the Table of Contents : () -> ToHtml

[ GitHub ]

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

def self.to_html
  @to_html ||= begin
    markup = Markup.new
    markup.add_regexp_handling CrossReference::CROSSREF_REGEXP, :CROSSREF

    to_html = Markup::ToHtml.new nil

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

    to_html
  end
end

.to_label

A singleton ToLabel formatter for headings. : () -> ToLabel

[ GitHub ]

  
# File 'lib/rdoc/markup/heading.rb', line 25

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

Instance Attribute Details

#level (rw)

: Integer

[ GitHub ]

  
# File 'lib/rdoc/markup/heading.rb', line 21

attr_accessor :level

#text (readonly)

: String

[ GitHub ]

  
# File 'lib/rdoc/markup/heading.rb', line 18

attr_reader :text

Instance Method Details

#==(other)

: (Object) -> bool

[ GitHub ]

  
# File 'lib/rdoc/markup/heading.rb', line 55

def ==(other)
  other.is_a?(Heading) && other.level == @level && other.text == @text
end

#accept(visitor)

: (untyped) -> void

[ GitHub ]

  
# File 'lib/rdoc/markup/heading.rb', line 61

def accept(visitor)
  visitor.accept_heading(self)
end

#aref

An HTML-safe anchor reference for this header. : () -> String

[ GitHub ]

  
# File 'lib/rdoc/markup/heading.rb', line 67

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

#label(context = nil)

Creates a fully-qualified label which will include the label from context. This helps keep ids unique in HTML. : (RDoc::Context?) -> String

[ GitHub ]

  
# File 'lib/rdoc/markup/heading.rb', line 73

def label(context = nil)
  label = +""
  label << "#{context.aref}-" if context&.respond_to?(:aref)
  label << aref
  label
end

#plain_html

HTML markup of the text of this label without the surrounding header element. : () -> String

[ GitHub ]

  
# File 'lib/rdoc/markup/heading.rb', line 82

def plain_html
  no_image_text = text

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

  self.class.to_html.to_html(no_image_text)
end

#pretty_print(q)

: (PP) -> void

[ GitHub ]

  
# File 'lib/rdoc/markup/heading.rb', line 94

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