Sha256: dc1052af55e18dbf320c9821d763bbdca216e38b6980f6aef301d25f7836bb4c

Contents?: true

Size: 1.48 KB

Versions: 19

Compression:

Stored size: 1.48 KB

Contents

# frozen_string_literal: true
##
# 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_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

  ##
  # 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

Version data entries

19 entries across 17 versions & 7 rubygems

Version Path
rdoc-6.12.0 lib/rdoc/markup/heading.rb
tailscale_middleware-0.0.3 vendor/cache/ruby/3.4.0/gems/rdoc-6.11.0/lib/rdoc/markup/heading.rb
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/rdoc-6.10.0/lib/rdoc/markup/heading.rb
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.1.0/gems/rdoc-6.7.0/lib/rdoc/markup/heading.rb
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/rdoc-6.8.1/lib/rdoc/markup/heading.rb
rdoc-6.11.0 lib/rdoc/markup/heading.rb
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/rdoc-6.7.0/lib/rdoc/markup/heading.rb
rdoc-6.10.0 lib/rdoc/markup/heading.rb
rdoc-6.9.1 lib/rdoc/markup/heading.rb
rdoc-6.9.0 lib/rdoc/markup/heading.rb
rdoc-6.8.1 lib/rdoc/markup/heading.rb
rdoc-6.8.0 lib/rdoc/markup/heading.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/rdoc-6.7.0/lib/rdoc/markup/heading.rb
tinymce-rails-7.1.2 vendor/bundle/ruby/3.3.0/gems/rdoc-6.7.0/lib/rdoc/markup/heading.rb
rdoc-6.6.3.1 lib/rdoc/markup/heading.rb
rdoc-6.6.2 lib/rdoc/markup/heading.rb
rdoc-6.6.1 lib/rdoc/markup/heading.rb
honeybadger-5.4.0 vendor/bundle/ruby/3.2.0/gems/rdoc-6.6.0/lib/rdoc/markup/heading.rb
rdoc-6.6.0 lib/rdoc/markup/heading.rb