Class: RDoc::Markup::Heading
- 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
Instance Attribute Summary collapse
-
#level ⇒ Object
: Integer.
-
#text ⇒ Object
readonly
: String.
Class Method Summary collapse
-
.to_html ⇒ Object
A singleton plain HTML formatter for headings.
-
.to_label ⇒ Object
A singleton RDoc::Markup::ToLabel formatter for headings.
Instance Method Summary collapse
-
#==(other) ⇒ Object
: (Object) -> bool.
-
#accept(visitor) ⇒ Object
: (untyped) -> void.
-
#aref ⇒ Object
An HTML-safe anchor reference for this header.
-
#initialize(level, text) ⇒ Heading
constructor
: (Integer, String) -> void.
-
#label(context = nil) ⇒ Object
Creates a fully-qualified label which will include the label from
context. -
#plain_html ⇒ Object
HTML markup of the text of this label without the surrounding header element.
-
#pretty_print(q) ⇒ Object
: (PP) -> void.
Constructor Details
#initialize(level, text) ⇒ Heading
: (Integer, String) -> void
47 48 49 50 51 52 |
# File 'lib/rdoc/markup/heading.rb', line 47 def initialize(level, text) super() @level = level @text = text end |
Instance Attribute Details
#level ⇒ Object
: Integer
21 22 23 |
# File 'lib/rdoc/markup/heading.rb', line 21 def level @level end |
#text ⇒ Object (readonly)
: String
18 19 20 |
# File 'lib/rdoc/markup/heading.rb', line 18 def text @text end |
Class Method Details
.to_html ⇒ Object
A singleton plain HTML formatter for headings. Used for creating labels for the Table of Contents : () -> RDoc::Markup::ToHtml
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# 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 ⇒ Object
A singleton RDoc::Markup::ToLabel formatter for headings. : () -> RDoc::Markup::ToLabel
25 26 27 |
# File 'lib/rdoc/markup/heading.rb', line 25 def self.to_label @to_label ||= Markup::ToLabel.new end |
Instance Method Details
#==(other) ⇒ Object
: (Object) -> bool
55 56 57 |
# File 'lib/rdoc/markup/heading.rb', line 55 def ==(other) other.is_a?(Heading) && other.level == @level && other.text == @text end |
#accept(visitor) ⇒ Object
: (untyped) -> void
61 62 63 |
# File 'lib/rdoc/markup/heading.rb', line 61 def accept(visitor) visitor.accept_heading(self) end |
#aref ⇒ Object
An HTML-safe anchor reference for this header. : () -> String
67 68 69 |
# File 'lib/rdoc/markup/heading.rb', line 67 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. : (RDoc::Context?) -> String
73 74 75 76 77 78 |
# 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 ⇒ Object
HTML markup of the text of this label without the surrounding header element. : () -> String
82 83 84 85 86 87 88 89 90 |
# 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) ⇒ Object
: (PP) -> void
94 95 96 97 98 |
# File 'lib/rdoc/markup/heading.rb', line 94 def pretty_print(q) q.group 2, "[head: #{level} ", ']' do q.pp text end end |