123456789_123456789_123456789_123456789_123456789_

Class: RDoc::Markup::ToHtmlCrossref

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

Overview

Subclass of the ToHtml class that supports looking up method names, classes, etc to create links. ::RDoc::CrossReference is used to generate those links based on the current context.

Constant Summary

::RDoc::Text - Included

MARKUP_FORMAT, SPACE_SEPARATED_LETTER_CLASS, TO_HTML_CHARACTERS

ToHtml - Inherited

LIST_TYPE_TO_HTML, URL_CHARACTERS_REGEXP_STR

Class Method Summary

ToHtml - Inherited

.new

Creates a new formatter that will output HTML.

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

ToHtml - Inherited

#code_object

The ::RDoc::CodeObject HTML is being generated for.

#from_path

Path to this document for relative links.

#in_tidylink_label?

Returns true if we are processing inside a tidy link label.

#in_list_entry, #list, #res

::RDoc::Text - Included

#language

The language for this text.

Instance Method Summary

ToHtml - Inherited

#accept_blank_line

Adds blank_line to the output.

#accept_block_quote

Adds block_quote to the output.

#accept_heading

Adds heading to the output.

#accept_list_end

Finishes consumption of list

#accept_list_item_end

Finishes consumption of list_item

#accept_list_item_start

Prepares the visitor for consuming list_item

#accept_list_start

Prepares the visitor for consuming list

#accept_paragraph

Adds paragraph to the output.

#accept_raw

Adds raw to the output.

#accept_rule

Adds rule to the output.

#accept_table

Adds table to the output.

#accept_verbatim

Adds verbatim to the output.

#apply_tidylink_label_special_handling

Special handling for tidy link labels.

#convert_string

CGI-escapes text

#deduplicate_heading_id

Returns a unique heading ID, appending -1, -2, etc.

#emit_inline,
#end_accepting

Returns the generated output.

#gen_url

Generates an HTML link or image tag for the given url and text.

#handle_BOLD, #handle_BOLD_WORD, #handle_EM, #handle_EM_WORD, #handle_HARD_BREAK, #handle_PLAIN_TEXT, #handle_REGEXP_HANDLING_TEXT,
#handle_regexp_HYPERLINK

target is a potential link.

#handle_regexp_RDOCLINK

target is an rdoc-schemed link that will be converted into a hyperlink.

#handle_regexp_SUPPRESSED_CROSSREF

Converts suppressed cross-reference text to HTML by removing the leading backslash.

#handle_STRIKE, #handle_TIDYLINK, #handle_TT,
#html_list_name

Determines the HTML list element for list_type and open_tag

#init_link_notation_regexp_handlings

Adds regexp handlings about link notations.

#init_regexp_handlings

Adds regexp handlings.

#list_end_for

Returns the HTML end-tag for list_type

#list_item_start

Returns the HTML tag for list_type, possible using a label from list_item

#parseable?

Returns true if text is valid ruby syntax.

#start_accepting

Prepares the visitor for HTML generation.

#to_html

Converts item to HTML using Text#to_html

#handle_inline, #handle_RDOCLINK

::RDoc::Text - Included

#flush_left

Flush text left based on the shortest line.

#markup

Convert a string in markup format into HTML.

#normalize_comment

Strips hashes, expands tabs then flushes text to the left.

#parse

Normalizes text then builds a Document from it.

#snippet

The first limit characters of text as HTML.

#strip_hashes

Strips leading # characters from text

#strip_newlines

Strips leading and trailing n characters from text

#strip_stars

Strips /* */ style comments.

#to_html,
#to_html_characters

Converts ampersand, dashes, ellipsis, quotes, copyright and registered trademark symbols in text to properly encoded characters.

#wrap

Wraps txt to line_len

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(options, from_path, context, markup = nil) ⇒ ToHtmlCrossref

Creates a new crossref resolver that generates links relative to #context which lives at from_path in the generated files. ‘#’ characters on references are removed unless #show_hash is true. Only method names preceded by ‘#’ or ‘::’ are linked, unless hyperlink_all is true.

Raises:

  • (ArgumentError)
[ GitHub ]

  
# File 'lib/rdoc/markup/to_html_crossref.rb', line 32

def initialize(options, from_path, context, markup = nil)
  raise ArgumentError, 'from_path cannot be nil' if from_path.nil?

  super options, markup

  @context       = context
  @from_path     = from_path
  @hyperlink_all = @options.hyperlink_all
  @show_hash     = @options.show_hash

  @cross_reference = RDoc::CrossReference.new @context
end

Instance Attribute Details

#context (rw)

::RDoc::CodeObject for generating references

[ GitHub ]

  
# File 'lib/rdoc/markup/to_html_crossref.rb', line 19

attr_accessor :context

#show_hash (rw)

Should we show ‘#’ characters on method references?

[ GitHub ]

  
# File 'lib/rdoc/markup/to_html_crossref.rb', line 24

attr_accessor :show_hash

Instance Method Details

#cross_reference(name, text = nil, code = true, rdoc_ref: false)

Creates a link to the reference name if the name exists. If text is given it is used as the link text, otherwise name is used.

[ GitHub ]

  
# File 'lib/rdoc/markup/to_html_crossref.rb', line 59

def cross_reference(name, text = nil, code = true, rdoc_ref: false)
  lookup = name

  name = name[1..-1] unless @show_hash if name[0, 1] == '#'

  if !name.end_with?('+@', '-@') && match = name.match(/(.*[^#:])?@(.*)/)
    context_name = match[1]
    label = RDoc::Text.decode_legacy_label(match[2])
    text ||= "#{label} at <code>#{context_name}</code>" if context_name
    text ||= label
    code = false
  else
    text ||= name
  end

  link lookup, text, code, rdoc_ref: rdoc_ref
end

#gen_url(url, text)

Generates links for rdoc-ref: scheme URLs and allows ToHtml to handle other schemes.

[ GitHub ]

  
# File 'lib/rdoc/markup/to_html_crossref.rb', line 140

def gen_url(url, text)
  if url =~ /\Ardoc-ref:/
    name = $'
    cross_reference name, text, name == text, rdoc_ref: true
  else
    super
  end
end

#handle_regexp_CROSSREF(name)

We’re invoked when any text matches the CROSSREF pattern. If we find the corresponding reference, generate a link. If the name we’re looking for contains no punctuation, we look for it up the module/class chain. For example, ToHtml is found, even without the RDoc::Markup:: prefix, because we look for it in module ::RDoc::Markup first.

[ GitHub ]

  
# File 'lib/rdoc/markup/to_html_crossref.rb', line 84

def handle_regexp_CROSSREF(name)
  return convert_string(name) if in_tidylink_label?
  return name if @options.autolink_excluded_words&.include?(name)

  return name if name =~ /@[\w-]+\.[\w-]/ # labels that look like emails

  unless @hyperlink_all then
    # This ensures that words entirely consisting of lowercase letters will
    # not have cross-references generated (to suppress lots of erroneous
    # cross-references to "new" in text, for instance)
    return name if name =~ /\A[a-z]*\z/
  end

  cross_reference name, rdoc_ref: false
end

#handle_TT(code)

[ GitHub ]

  
# File 'lib/rdoc/markup/to_html_crossref.rb', line 209

def handle_TT(code)
  emit_inline(tt_cross_reference(code) || "<code>#{CGI.escapeHTML code}</code>")
end

#tt_cross_reference(code)

[ GitHub ]

  
# File 'lib/rdoc/markup/to_html_crossref.rb', line 224

def tt_cross_reference(code)
  return if in_tidylink_label?

  crossref_regexp = @options.hyperlink_all ? ALL_CROSSREF_REGEXP : CROSSREF_REGEXP
  match = crossref_regexp.match(code)
  return unless match && match.begin(1).zero?
  return unless match.post_match.match?(/\A[[:punct:]\s]*\z/)

  ref = cross_reference(code)
  ref if ref != code
end