class RDoc::Markup::ToLabel

Creates HTML-safe labels suitable for use in id attributes. Tidylinks are converted to their link part and cross-reference links have the suppression marks removed (\SomeClass is converted to SomeClass).

Public Class Methods

Creates a new formatter that will output HTML-safe labels

Calls superclass method RDoc::Markup::Formatter::new
# File lib/rdoc/markup/to_label.rb, line 19
def initialize
  super

  @markup.add_regexp_handling CrossReference::CROSSREF_REGEXP, :CROSSREF

  @res = []
end

Public Instance Methods

Converts text to an HTML-safe label using GitHub-style anchor formatting.

# File lib/rdoc/markup/to_label.rb, line 48
def convert(text)
  label = extract_plaintext(text)

  Text.to_anchor(label)
end

Converts text to an HTML-safe label using legacy RDoc formatting. Used for generating backward-compatible anchor aliases.

# File lib/rdoc/markup/to_label.rb, line 58
def convert_legacy(text)
  label = extract_plaintext(text)

  CGI.escape(label).gsub('%', '-').sub(/^-/, '')
end
# File lib/rdoc/markup/to_label.rb, line 39
def extract_plaintext(text)
  @res = []
  handle_inline(text)
  @res.join
end
# File lib/rdoc/markup/to_label.rb, line 27
def handle_PLAIN_TEXT(text)
  @res << text
end
# File lib/rdoc/markup/to_label.rb, line 31
def handle_REGEXP_HANDLING_TEXT(text)
  @res << text
end
# File lib/rdoc/markup/to_label.rb, line 35
def handle_TT(text)
  @res << text
end

Converts the CROSSREF target to plain text, removing the suppression marker, if any

# File lib/rdoc/markup/to_label.rb, line 68
def handle_regexp_CROSSREF(text)
  text.sub(/^\\/, '')
end