Skip to content

Commit 914e3f3

Browse files
committed
Change rdoc: to rdoc-ref: and update documetation. Issue #53
1 parent cf2cdde commit 914e3f3

File tree

5 files changed

+57
-53
lines changed

5 files changed

+57
-53
lines changed

History.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
* Minor enhancements
44
* RDoc::Parser::C now supports :doc: and :nodoc: for class comments
5-
* Added the <tt>rdoc:</tt> link scheme which links to a named reference.
6-
This can be used to create cross-generator named links unlike the
7-
<tt>link:</tt> scheme which is dependent upon the exact file name. Issue
8-
#53 by Simon Chiang
5+
* Added the <tt>rdoc-ref:</tt> link scheme which links to a named reference.
6+
<tt>rdoc-ref:</tt> can resolve references to classes, modules, methods,
7+
files, etc. This can be used to create cross-generator named links unlike
8+
the <tt>link:</tt> scheme which is dependent upon the exact file name.
9+
Issue #53 by Simon Chiang
910
* Bug fixes
1011
* `ri []` and other special methods now work properly. Issue #52 by
1112
ddebernardy.

lib/rdoc/markup.rb

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -269,57 +269,59 @@
269269
# preceding the first character with a backslash (see <i>Escaping
270270
# Text Markup</i>, below).
271271
#
272-
# === Hyperlinks
272+
# === Links
273273
#
274-
# Hyperlinks to the web starting with +http:+, +mailto:+, +ftp:+ or +www.+
274+
# Links to starting with +http:+, +https:+, +mailto:+, +ftp:+ or +www.+
275275
# are recognized. An HTTP url that references an external image file is
276-
# converted into an inline <img...>. Hyperlinks starting with +link:+ are
277-
# assumed to refer to local files whose path is relative to the <tt>--op</tt>
278-
# directory.
276+
# converted into an inline image element.
279277
#
280-
# Hyperlinks can also be of the form _label_[_url_], in which
281-
# case _label_ is used in the displayed text, and _url_ is
282-
# used as the target. If _label_ contains multiple words,
283-
# put it in braces: {<em>multi word label</em>}[url].
278+
# Links starting with <tt>rdoc-ref:</tt> will link to the referenced class,
279+
# module, method, file, etc.
284280
#
285-
# Example hyperlinks:
281+
# Links starting with +link:+ refer to local files whose path is relative to
282+
# the <tt>--op</tt> directory.
286283
#
287-
# link:RDoc.html
288-
# http://rdoc.rubyforge.org
284+
# Links can also be of the form <tt>label[url]</tt>, in which case +label+ is
285+
# used in the displayed text, and +url+ is used as the target. If +label+
286+
# contains multiple words, put it in braces: <tt>{multi word label}[url]<tt>.
287+
#
288+
# Example links:
289+
#
290+
# https://github.com/rdoc/rdoc
289291
290292
# {RDoc Documentation}[http://rdoc.rubyforge.org]
291-
# {RDoc Markup}[link:RDoc/Markup.html]
293+
# {RDoc Markup}[rdoc-ref:RDoc::Markup]
292294
#
293295
# === Escaping Text Markup
294296
#
295297
# Text markup can be escaped with a backslash, as in \<tt>, which was obtained
296-
# with "<tt>\\<tt></tt>". Except in verbatim sections and between \<tt> tags,
297-
# to produce a backslash, you have to double it unless it is followed by a
298+
# with <tt>\\<tt></tt>. Except in verbatim sections and between \<tt> tags,
299+
# to produce a backslash you have to double it unless it is followed by a
298300
# space, tab or newline. Otherwise, the HTML formatter will discard it, as it
299-
# is used to escape potential hyperlinks:
301+
# is used to escape potential links:
300302
#
301303
# * The \ must be doubled if not followed by white space: \\.
302304
# * But not in \<tt> tags: in a Regexp, <tt>\S</tt> matches non-space.
303305
# * This is a link to {ruby-lang}[www.ruby-lang.org].
304306
# * This is not a link, however: \{ruby-lang.org}[www.ruby-lang.org].
305-
# * This will not be hyperlinked to \RDoc::RDoc#document
307+
# * This will not be linked to \RDoc::RDoc#document
306308
#
307309
# generates:
308310
#
309311
# * The \ must be doubled if not followed by white space: \\.
310312
# * But not in \<tt> tags: in a Regexp, <tt>\S</tt> matches non-space.
311313
# * This is a link to {ruby-lang}[www.ruby-lang.org]
312314
# * This is not a link, however: \{ruby-lang.org}[www.ruby-lang.org]
313-
# * This will not be hyperlinked to \RDoc::RDoc#document
315+
# * This will not be linked to \RDoc::RDoc#document
314316
#
315-
# Inside \<tt> tags, more precisely, leading backslashes are removed
316-
# only if followed by a markup character (<tt><*_+</tt>), a backslash,
317-
# or a known hyperlink reference (a known class or method). So in the
318-
# example above, the backslash of <tt>\S</tt> would be removed
319-
# if there was a class or module named +S+ in the current context.
317+
# Inside \<tt> tags, more precisely, leading backslashes are removed only if
318+
# followed by a markup character (<tt><*_+</tt>), a backslash, or a known link
319+
# reference (a known class or method). So in the example above, the backslash
320+
# of <tt>\S</tt> would be removed if there was a class or module named +S+ in
321+
# the current context.
320322
#
321-
# This behavior is inherited from RDoc version 1, and has been kept
322-
# for compatibility with existing RDoc documentation.
323+
# This behavior is inherited from RDoc version 1, and has been kept for
324+
# compatibility with existing RDoc documentation.
323325
#
324326
# === Conversion of characters
325327
#
@@ -378,11 +380,10 @@
378380
# # ...
379381
# end
380382
#
381-
# Names of classes, files, and any method names containing an
382-
# underscore or preceded by a hash character are automatically hyperlinked
383-
# from comment text to their description. This hyperlinking works inside
384-
# the current class or module, and with ancestor methods (in included modules
385-
# or in the superclass).
383+
# Names of classes, files, and any method names containing an underscore or
384+
# preceded by a hash character are automatically linked from comment text to
385+
# their description. This linking works inside the current class or module,
386+
# and with ancestor methods (in included modules or in the superclass).
386387
#
387388
# Method parameter lists are extracted and displayed with the method
388389
# description. If a method calls +yield+, then the parameters passed to yield

lib/rdoc/markup/to_html.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def initialize markup = nil
7070
@list = nil
7171
@from_path = ''
7272

73-
# external hyperlinks
73+
# external links
7474
@markup.add_special(/((link:|https?:|mailto:|ftp:|www\.)\S+\w)/, :HYPERLINK)
7575

7676
# and links of the form <text>[<url>]
@@ -84,7 +84,7 @@ def initialize markup = nil
8484
# These methods handle special markup added by RDoc::Markup#add_special.
8585

8686
##
87-
# +special+ is a potential hyperlink. The following schemes are handled:
87+
# +special+ is a potential link. The following schemes are handled:
8888
#
8989
# <tt>mailto:</tt>::
9090
# Inserted as-is.
@@ -102,8 +102,8 @@ def handle_special_HYPERLINK(special)
102102
end
103103

104104
##
105-
# This +special+ is a hyperlink where the label is different from the URL
106-
# label[url] or {long label}[url]
105+
# This +special+ is a link where the label is different from the URL
106+
# <tt>label[url]</tt> or <tt>{long label}[url]</tt>
107107

108108
def handle_special_TIDYLINK(special)
109109
text = special.text
@@ -233,8 +233,8 @@ def convert_string(text)
233233
end
234234

235235
##
236-
# Generate a hyperlink for +url+, labeled with +text+. Handles the special
237-
# cases for img: and link: described under handle_special_HYPERLINK
236+
# Generate a link for +url+, labeled with +text+. Handles the special cases
237+
# for img: and link: described under handle_special_HYPERLINK
238238

239239
def gen_url(url, text)
240240
if url =~ /([A-Za-z]+):(.*)/ then

lib/rdoc/markup/to_html_crossref.rb

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
##
44
# Subclass of the RDoc::Markup::ToHtml class that supports looking up words
5-
# from a context. Those that are found will be hyperlinked.
5+
# from a context. Those that are found will be linked.
66

77
class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
88

@@ -102,7 +102,7 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
102102
# Creates a new crossref resolver that generates links relative to +context+
103103
# which lives at +from_path+ in the generated files. '#' characters on
104104
# references are removed unless +show_hash+ is true. Only method names
105-
# preceded by '#' or '::' are hyperlinked, unless +hyperlink_all+ is true.
105+
# preceded by '#' or '::' are linked, unless +hyperlink_all+ is true.
106106

107107
def initialize(from_path, context, show_hash, hyperlink_all = false,
108108
markup = nil)
@@ -193,10 +193,10 @@ def cross_reference name, text = nil
193193

194194
##
195195
# We're invoked when any text matches the CROSSREF pattern. If we find the
196-
# corresponding reference, generate a hyperlink. If the name we're looking
197-
# for contains no punctuation, we look for it up the module/class chain.
198-
# For example, ToHtml is found, even without the <tt>RDoc::Markup::</tt>
199-
# prefix, because we look for it in module Markup first.
196+
# corresponding reference, generate a link. If the name we're looking for
197+
# contains no punctuation, we look for it up the module/class chain. For
198+
# example, ToHtml is found, even without the <tt>RDoc::Markup::</tt> prefix,
199+
# because we look for it in module Markup first.
200200

201201
def handle_special_CROSSREF(special)
202202
name = special.text
@@ -212,20 +212,22 @@ def handle_special_CROSSREF(special)
212212
end
213213

214214
##
215-
# Handles <tt>rdoc:</tt> scheme hyperlinks
215+
# Handles <tt>rdoc-ref:</tt> scheme links and allows RDoc::Markup::ToHtml to
216+
# handle other schemes.
216217

217218
def handle_special_HYPERLINK special
218-
return cross_reference $' if special.text =~ /\Ardoc:/
219+
return cross_reference $' if special.text =~ /\Ardoc-ref:/
219220

220221
super
221222
end
222223

223224
##
224-
# Generates links for <tt>rdoc:</tt> scheme URLs
225+
# Generates links for <tt>rdoc-ref:</tt> scheme URLs and allows
226+
# RDoc::Markup::ToHtml to handle other schemes.
225227

226228
def gen_url url, text
227-
super unless url =~ /\Ardoc:/
228-
229+
super unless url =~ /\Ardoc-ref:/
230+
229231
cross_reference $', text
230232
end
231233

test/test_rdoc_markup_to_html_crossref.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,11 @@ def test_handle_special_TIDYLINK_rdoc
200200
end
201201

202202
def hyper reference
203-
RDoc::Markup::Special.new 0, "rdoc:#{reference}"
203+
RDoc::Markup::Special.new 0, "rdoc-ref:#{reference}"
204204
end
205205

206206
def tidy reference
207-
RDoc::Markup::Special.new 0, "{tidy}[rdoc:#{reference}]"
207+
RDoc::Markup::Special.new 0, "{tidy}[rdoc-ref:#{reference}]"
208208
end
209209

210210
end

0 commit comments

Comments
 (0)