# 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

new(markup = nil) click to toggle source

Creates a new formatter that will output HTML-safe labels

    # File lib/rdoc/markup/to_label.rb, line 13
    def initialize markup = nil
      super

      @markup.add_special RDoc::CrossReference::CROSSREF_REGEXP, :CROSSREF
      @markup.add_special(%r(((\{.*?\})|\b\S+?)\[\S+?\])/, :TIDYLINK)

      add_tag :BOLD, '', ''
      add_tag :TT,   '', ''
      add_tag :EM,   '', ''
    end

### Public Instance Methods

convert(text) click to toggle source

Converts `text` to an HTML-safe label

    # File lib/rdoc/markup/to_label.rb, line 27
    def convert text
      label = convert_flow @am.flow text

      CGI.escape label
    end

handle_special_CROSSREF(special) click to toggle source

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

    # File lib/rdoc/markup/to_label.rb, line 37
    def handle_special_CROSSREF special
      text = special.text

      text.sub(%r^\\/, '')
    end

handle_special_TIDYLINK(special) click to toggle source

Converts the TIDYLINK `special` to just the text part

    # File lib/rdoc/markup/to_label.rb, line 46
    def handle_special_TIDYLINK special
      text = special.text

      return text unless text =~ %r\{(.*?)\}\[(.*?)\]/ or text =~ %r(\S+)\[(.*?)\]/

      $1
    end