77
88class RDoc ::Markup ::ToHtmlCrossref < RDoc ::Markup ::ToHtml
99
10- attr_accessor :context
11-
10+ ##
1211 # Regular expressions to match class and method references.
1312 #
14- # 1.) There can be a '\' in front of text to suppress
15- # any cross-references (note, however, that the single '\'
16- # is written as '\\\\' in order to escape it twice, once
17- # in the Ruby String literal and once in the regexp).
18- # 2.) There can be a '::' in front of class names to reference
19- # from the top-level namespace.
20- # 3.) The method can be followed by parenthesis,
21- # which may or may not have things inside (this
22- # apparently is allowed for Fortran 95, but I also think that this
23- # is a good idea for Ruby, as it is very reasonable to want to
24- # reference a call with arguments).
13+ # 1) There can be a '\' in front of text to suppress any cross-references
14+ # 2) There can be a '::' in front of class names to reference from the
15+ # top-level namespace.
16+ # 3) The method can be followed by parenthesis which may
2517 #
2618 # NOTE: In order to support Fortran 95 properly, the [A-Z] below
2719 # should be changed to [A-Za-z]. This slows down rdoc significantly,
2820 # however, and the Fortran 95 support is broken in any case due to
2921 # the return in handle_special_CROSSREF if the token consists
3022 # entirely of lowercase letters.
31- #
32- # The markup/cross-referencing engine needs a rewrite for
33- # Fortran 95 to be supported properly.
23+
3424 CLASS_REGEXP_STR = '\\\\?((?:\:{2})?[A-Z]\w*(?:\:\:\w+)*)'
3525 METHOD_REGEXP_STR = '(\w+[!?=]?)(?:\([\.\w+\*\/\+\-\=\<\>]*\))?'
3626
27+ ##
3728 # Regular expressions matching text that should potentially have
38- # cross-reference links generated are passed to add_special.
39- # Note that these expressions are meant to pick up text for which
40- # cross-references have been suppressed, since the suppression
41- # characters are removed by the code that is triggered.
29+ # cross-reference links generated are passed to add_special. Note that
30+ # these expressions are meant to pick up text for which cross-references
31+ # have been suppressed, since the suppression characters are removed by the
32+ # code that is triggered.
33+
4234 CROSSREF_REGEXP = /(
4335 # A::B::C.meth
4436 #{ CLASS_REGEXP_STR } [\. \# ]#{ METHOD_REGEXP_STR }
@@ -72,8 +64,14 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
7264 )/x
7365
7466 ##
75- # We need to record the html path of our caller so we can generate
76- # correct relative paths for any hyperlinks that we find
67+ # RDoc::Generator::Context for generating references
68+
69+ attr_accessor :context
70+
71+ ##
72+ # Creates a new crossref resolver that generates links relative to +context+
73+ # which lives at +from_path+ in the generated files. '#' characters on
74+ # references are removed unless +show_hash+ is true.
7775
7876 def initialize ( from_path , context , show_hash )
7977 raise ArgumentError , 'from_path cannot be nil' if from_path . nil?
@@ -89,19 +87,18 @@ def initialize(from_path, context, show_hash)
8987 end
9088
9189 ##
92- # We're invoked when any text matches the CROSSREF pattern
93- # (defined in MarkUp). If we fine the corresponding reference,
94- # generate a hyperlink. If the name we're looking for contains
95- # no punctuation, we look for it up the module/class chain. For
96- # example, HyperlinkHtml is found, even without the Generator::
97- # prefix, because we look for it in module Generator first.
90+ # We're invoked when any text matches the CROSSREF pattern (defined in
91+ # MarkUp). If we find the corresponding reference, generate a hyperlink.
92+ # If the name we're looking for contains no punctuation, we look for it up
93+ # the module/class chain. For example, HyperlinkHtml is found, even without
94+ # the Generator:: prefix, because we look for it in module Generator first.
9895
9996 def handle_special_CROSSREF ( special )
10097 name = special . text
10198
10299 # This ensures that words entirely consisting of lowercase letters will
103- # not have cross-references generated (to suppress lots of
104- # erroneous cross-references to "new" in text, for instance)
100+ # not have cross-references generated (to suppress lots of erroneous
101+ # cross-references to "new" in text, for instance)
105102 return name if name =~ /\A [a-z]*\z /
106103
107104 return @seen [ name ] if @seen . include? name
0 commit comments