Class RDoc::Markup::ToHtmlCrossref
In: markup/to_html_crossref.rb
Parent: RDoc::Markup::ToHtml

Subclass of the RDoc::Markup::ToHtml class that supports looking up words in the AllReferences list. Those that are found (like AllReferences in this comment) will be hyperlinked

Methods

Public Class methods

We need to record the html path of our caller so we can generate correct relative paths for any hyperlinks that we find

[Source]

    # File markup/to_html_crossref.rb, line 16
16:   def initialize(from_path, context, show_hash)
17:     super()
18: 
19:     # class names, variable names, or instance variables
20:     @markup.add_special(/(
21:                            # A::B.meth(**) (for operator and assignment in Fortran 90 or 95)
22:                            \b\w+(::\w+)*[\.\#]\w+(\([\.\w+\*\/\+\-\=\<\>]+\))?
23:                            # meth(**) (for operator and assignment in Fortran 90 or 95)
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
29:                          )/x,
30:                         :CROSSREF)
31: 
32:     # file names
33:     @markup.add_special(/(
34:                            ((\/|\.\.\/|\.\/|\w)[\w\#\/\.\-\~\:]*[!?=]?) # file_name
35:                          | ((\/|\.\.\/|\.\/|\w)[\w\#\/\.\-\~\:]*(\([\.\w+\*\/\+\-\=\<\>]+\))?)
36:                          )/x, 
37:                         :CROSSREFFILE)
38: 
39:     @from_path = from_path
40:     @context = context
41:     @show_hash = show_hash
42: 
43:     @seen = {}
44:     @seen_file = {}
45:   end

Public Instance methods

We‘re invoked when any text matches the CROSSREF pattern (defined in MarkUp). If we fine the corresponding reference, generate a hyperlink. If the name we‘re looking for contains no punctuation, we look for it up the module/class chain. For example, HyperlinkHtml is found, even without the Generator:: prefix, because we look for it in module Generator first.

[Source]

    # File markup/to_html_crossref.rb, line 55
55:   def handle_special_CROSSREF(special)
56:     name = special.text
57: 
58:     return @seen[name] if @seen.include? name
59: 
60:     if name[0,1] == '#' then
61:       lookup = name[1..-1]
62:       name = lookup unless @show_hash
63:     else
64:       lookup = name
65:     end
66: 
67:     # Find class, module, or method in class or module.
68:     if /([A-Z]\w*)[.\#](\w+[!?=]?)/ =~ lookup then
69:       container = $1
70:       method = $2
71:       ref = @context.find_symbol container, method
72:     elsif /([A-Za-z]\w*)[.\#](\w+(\([\.\w+\*\/\+\-\=\<\>]+\))?)/ =~ lookup then
73:       container = $1
74:       method = $2
75:       ref = @context.find_symbol container, method
76:     else
77:       ref = @context.find_symbol lookup
78:     end
79: 
80:     out = if lookup =~ /^\\/ then
81:             $'
82:           elsif ref and ref.document_self then
83:             "<a href=\"#{ref.as_href(@from_path)}\">#{name}</a>"
84:           else
85:             name
86:           end
87: 
88:     @seen[name] = out
89: 
90:     out
91:   end

CROSSREFFILE is similar to CROSSREF. But this pattern is hit to filenames or methods in files

[Source]

     # File markup/to_html_crossref.rb, line 97
 97:   def handle_special_CROSSREFFILE(special)
 98:     name = special.text
 99: 
100:     return @seen_file[name] if @seen_file.include? name
101: 
102:     # Find file, or method in file
103:     if /([\w\/\.].*\.\w+)[.\#](.*)/ =~ name
104:       file_name = $1
105:       method = $2
106:       ref = @context.find_file file_name, method
107:     else
108:       ref = @context.find_file name
109:     end
110: 
111:     out = if ref and ref.document_self then
112:             "<a href=\"#{ref.as_href(@from_path)}\">#{name}</a>"
113:           else
114:             name
115:           end
116: 
117:     @seen_file[name] = out
118: 
119:     out
120: 
121:   end

[Validate]