123456789_123456789_123456789_123456789_123456789_

Class: RDoc::Markup::ToLabel

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Formatter
Instance Chain:
self, Formatter
Inherits: RDoc::Markup::Formatter
Defined in: lib/rdoc/markup/to_label.rb

Overview

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 Method Summary

Formatter - Inherited

.gen_relative_url

Converts a target url to one that is relative to a given path.

.new

Creates a new Formatter.

Instance Attribute Summary

  • #res readonly Internal use only

Instance Method Summary

Formatter - Inherited

#accept_document

Adds document to the output.

#add_regexp_handling_RDOCLINK

Adds a regexp handling for links of the form rdoc-…:

#annotate

Allows tag to be decorated with additional information.

#apply_regexp_handling

Applies regexp handling to text and returns an array of [text, converted?] pairs.

#convert

Marks up content

#convert_string

Converts a string to be fancier if desired.

#handle_BOLD

Called when processing bold nodes while traversing inline nodes from handle_inline.

#handle_BOLD_WORD

Called when processing bold word nodes while traversing inline nodes from handle_inline.

#handle_EM

Called when processing emphasis nodes while traversing inline nodes from handle_inline.

#handle_EM_WORD

Called when processing emphasis word nodes while traversing inline nodes from handle_inline.

#handle_HARD_BREAK

Called when processing a hard break while traversing inline nodes from handle_inline.

#handle_inline

Parses inline text, traverse the resulting nodes, and calls the appropriate handler methods.

#handle_PLAIN_TEXT

Called when processing plain text while traversing inline nodes from handle_inline.

#handle_REGEXP_HANDLING_TEXT

Called when processing regexp-handling-processed text while traversing inline nodes from handle_inline.

#handle_STRIKE

Called when processing strike nodes while traversing inline nodes from handle_inline.

#handle_TEXT

Called when processing text node while traversing inline nodes from handle_inline.

#handle_TIDYLINK

Called when processing tidylink nodes while traversing inline nodes from handle_inline.

#handle_TT

Called when processing tt nodes while traversing inline nodes from handle_inline.

#ignore

Use ignore in your subclass to ignore the content of a node.

#parse_url

Extracts and a scheme, url and an anchor id from url and returns them.

#traverse_inline_nodes

Traverses nodes and calls the appropriate handler methods Nodes formats are described in InlineParser#parse

#tt?

Is tag a tt tag?

Constructor Details

.new(markup = nil) ⇒ ToLabel

Creates a new formatter that will output HTML-safe labels

[ GitHub ]

  
# 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

Instance Attribute Details

#res (readonly)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rdoc/markup/to_label.rb', line 12

attr_reader :res # :nodoc:

Instance Method Details

#accept_blank_line

[ GitHub ]

  
# File 'lib/rdoc/markup/to_label.rb', line 70

alias accept_blank_line         ignore

#accept_block_quote

[ GitHub ]

  
# File 'lib/rdoc/markup/to_label.rb', line 71

alias accept_block_quote        ignore

#accept_heading

[ GitHub ]

  
# File 'lib/rdoc/markup/to_label.rb', line 72

alias accept_heading            ignore

#accept_list_end

[ GitHub ]

  
# File 'lib/rdoc/markup/to_label.rb', line 73

alias accept_list_end           ignore

#accept_list_item_end

[ GitHub ]

  
# File 'lib/rdoc/markup/to_label.rb', line 74

alias accept_list_item_end      ignore

#accept_list_item_start

[ GitHub ]

  
# File 'lib/rdoc/markup/to_label.rb', line 75

alias accept_list_item_start    ignore

#accept_list_start

[ GitHub ]

  
# File 'lib/rdoc/markup/to_label.rb', line 76

alias accept_list_start         ignore

#accept_paragraph

[ GitHub ]

  
# File 'lib/rdoc/markup/to_label.rb', line 77

alias accept_paragraph          ignore

#accept_raw

[ GitHub ]

  
# File 'lib/rdoc/markup/to_label.rb', line 78

alias accept_raw                ignore

#accept_rule

[ GitHub ]

  
# File 'lib/rdoc/markup/to_label.rb', line 79

alias accept_rule               ignore

#accept_verbatim

[ GitHub ]

  
# File 'lib/rdoc/markup/to_label.rb', line 80

alias accept_verbatim           ignore

#convert(text)

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

[ GitHub ]

  
# File 'lib/rdoc/markup/to_label.rb', line 46

def convert(text)
  label = extract_plaintext(text)

  RDoc::Text.to_anchor(label)
end

#convert_legacy(text)

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

[ GitHub ]

  
# File 'lib/rdoc/markup/to_label.rb', line 56

def convert_legacy(text)
  label = extract_plaintext(text)

  CGI.escape(label).gsub('%', '-').sub(/^-/, '')
end

#end_accepting

[ GitHub ]

  
# File 'lib/rdoc/markup/to_label.rb', line 81

alias end_accepting             ignore

#extract_plaintext(text)

[ GitHub ]

  
# File 'lib/rdoc/markup/to_label.rb', line 37

def extract_plaintext(text)
  @res = []
  handle_inline(text)
  @res.join
end

#handle_PLAIN_TEXT(text)

[ GitHub ]

  
# File 'lib/rdoc/markup/to_label.rb', line 25

def handle_PLAIN_TEXT(text)
  @res << text
end

#handle_regexp_CROSSREF(text)

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

[ GitHub ]

  
# File 'lib/rdoc/markup/to_label.rb', line 66

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

#handle_REGEXP_HANDLING_TEXT(text)

[ GitHub ]

  
# File 'lib/rdoc/markup/to_label.rb', line 29

def handle_REGEXP_HANDLING_TEXT(text)
  @res << text
end

#handle_TT(text)

[ GitHub ]

  
# File 'lib/rdoc/markup/to_label.rb', line 33

def handle_TT(text)
  @res << text
end

#start_accepting

[ GitHub ]

  
# File 'lib/rdoc/markup/to_label.rb', line 82

alias start_accepting           ignore