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 17
def initialize(markup = nil)
  super nil, markup

  @markup.add_regexp_handling RDoc::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 46
def convert(text)
  label = extract_plaintext(text)

  RDoc::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 56
def convert_legacy(text)
  label = extract_plaintext(text)

  CGI.escape(label).gsub('%', '-').sub(/^-/, '')
end
# File lib/rdoc/markup/to_label.rb, line 37
def extract_plaintext(text)
  @res = []
  handle_inline(text)
  @res.join
end
# File lib/rdoc/markup/to_label.rb, line 25
def handle_PLAIN_TEXT(text)
  @res << text
end
# File lib/rdoc/markup/to_label.rb, line 29
def handle_REGEXP_HANDLING_TEXT(text)
  @res << text
end
# File lib/rdoc/markup/to_label.rb, line 33
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 66
def handle_regexp_CROSSREF(text)
  text.sub(/^\\/, '')
end