1 require 'rdoc/markup/to_html'
4 # Subclass of the RDoc::Markup::ToHtml class that supports looking up words in
5 # the AllReferences list. Those that are found (like AllReferences in this
6 # comment) will be hyperlinked
8 class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
10 attr_accessor :context
13 # We need to record the html path of our caller so we can generate
14 # correct relative paths for any hyperlinks that we find
16 def initialize(from_path, context, show_hash)
19 # class names, variable names, or instance variables
20 @markup.add_special(/(
21 # A::B.meth(**) (for operator in Fortran95)
22 \w+(::\w+)*[.\#]\w+(\([\.\w+\*\/\+\-\=\<\>]+\))?
23 # meth(**) (for operator in Fortran95)
24 | \#\w+(\([.\w\*\/\+\-\=\<\>]+\))?
25 | \b([A-Z]\w*(::\w+)*[.\#]\w+) # A::B.meth
26 | \b([A-Z]\w+(::\w+)*) # A::B
27 | \#\w+[!?=]? # #meth_name
28 | \\?\b\w+([_\/\.]+\w+)*[!?=]? # meth_name
32 @from_path = from_path
34 @show_hash = show_hash
40 # We're invoked when any text matches the CROSSREF pattern
41 # (defined in MarkUp). If we fine the corresponding reference,
42 # generate a hyperlink. If the name we're looking for contains
43 # no punctuation, we look for it up the module/class chain. For
44 # example, HyperlinkHtml is found, even without the Generator::
45 # prefix, because we look for it in module Generator first.
47 def handle_special_CROSSREF(special)
50 return @seen[name] if @seen.include? name
52 if name[0,1] == '#' then
54 name = lookup unless @show_hash
59 # Find class, module, or method in class or module.
60 if /([A-Z]\w*)[.\#](\w+[!?=]?)/ =~ lookup then
63 ref = @context.find_symbol container, method
64 elsif /([A-Za-z]\w*)[.\#](\w+(\([\.\w+\*\/\+\-\=\<\>]+\))?)/ =~ lookup then
67 ref = @context.find_symbol container, method
69 ref = @context.find_symbol lookup
72 out = if lookup =~ /^\\/ then
74 elsif ref and ref.document_self then
75 "<a href=\"#{ref.as_href(@from_path)}\">#{name}</a>"