Sha256: 8bd4682923969554bbb7d90a7423f171fcae24e2952d7da7619c2fc3d67974dc

Contents?: true

Size: 1.15 KB

Versions: 102

Compression:

Stored size: 1.15 KB

Contents

require 'cgi'

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

class RDoc::Markup::ToLabel < RDoc::Markup::Formatter

  ##
  # Creates a new formatter that will output HTML-safe labels

  def initialize markup = nil
    super

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

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

  ##
  # Converts +text+ to an HTML-safe label

  def convert text
    label = convert_flow @am.flow text

    CGI.escape label
  end

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

  def handle_special_CROSSREF special
    text = special.text

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

  ##
  # Converts the TIDYLINK +special+ to just the text part

  def handle_special_TIDYLINK special
    text = special.text

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

    $1
  end

end

Version data entries

102 entries across 80 versions & 20 rubygems

Version Path
active_mailer-0.0.10 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/rdoc-3.12.1/lib/rdoc/markup/to_label.rb
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/rdoc-3.12.2/lib/rdoc/markup/to_label.rb
active_mailer-0.0.9 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/rdoc-3.12.1/lib/rdoc/markup/to_label.rb
active_mailer-0.0.8 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/rdoc-3.12.1/lib/rdoc/markup/to_label.rb
active_mailer-0.0.7 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/rdoc-3.12.1/lib/rdoc/markup/to_label.rb
active_mailer-0.0.6 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/rdoc-3.12.1/lib/rdoc/markup/to_label.rb
font-awesome-rails-3.1.1.2 vendor/ruby/1.9.1/gems/rdoc-3.12.2/lib/rdoc/markup/to_label.rb
font-awesome-rails-3.1.1.2 vendor/ruby/2.0.0/gems/rdoc-3.12.2/lib/rdoc/markup/to_label.rb
font-awesome-rails-3.1.1.1 vendor/ruby/2.0.0/gems/rdoc-3.12.2/lib/rdoc/markup/to_label.rb
font-awesome-rails-3.1.1.1 vendor/ruby/1.9.1/gems/rdoc-3.12.2/lib/rdoc/markup/to_label.rb
challah-1.0.0.beta3 vendor/bundle/gems/rdoc-3.12.2/lib/rdoc/markup/to_label.rb
fc-webicons-0.0.4 vendor/bundle/ruby/1.9.1/gems/rdoc-3.12.2/lib/rdoc/markup/to_label.rb
challah-1.0.0.beta2 vendor/bundle/gems/rdoc-3.12.2/lib/rdoc/markup/to_label.rb
challah-1.0.0.beta vendor/bundle/gems/rdoc-3.12/lib/rdoc/markup/to_label.rb
challah-1.0.0.beta vendor/bundle/gems/rdoc-3.12.2/lib/rdoc/markup/to_label.rb
fc-webicons-0.0.3 vendor/bundle/ruby/1.9.1/gems/rdoc-3.12.2/lib/rdoc/markup/to_label.rb
fc-webicons-0.0.2 vendor/bundle/ruby/1.9.1/gems/rdoc-3.12.2/lib/rdoc/markup/to_label.rb
fc-webicons-0.0.1 vendor/bundle/ruby/1.9.1/gems/rdoc-3.12.2/lib/rdoc/markup/to_label.rb
rdoc-3.12.2 lib/rdoc/markup/to_label.rb
active_mailer-0.0.5 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/rdoc-3.12.1/lib/rdoc/markup/to_label.rb