diff --git a/lib/rdoc/generator/markup.rb b/lib/rdoc/generator/markup.rb
index 206b3c53d4..1c39687040 100644
--- a/lib/rdoc/generator/markup.rb
+++ b/lib/rdoc/generator/markup.rb
@@ -55,6 +55,18 @@ def cvs_url(url, full_path)
end
end
+ ##
+ # The preferred URL for this object.
+
+ def canonical_url
+ options = @store.options
+ if path
+ File.join(options.canonical_root, path.to_s)
+ else
+ options.canonical_root
+ end
+ end
+
end
class RDoc::CodeObject
diff --git a/lib/rdoc/generator/template/darkfish/_head.rhtml b/lib/rdoc/generator/template/darkfish/_head.rhtml
index 9e6fb4f94c..7376fc390e 100644
--- a/lib/rdoc/generator/template/darkfish/_head.rhtml
+++ b/lib/rdoc/generator/template/darkfish/_head.rhtml
@@ -25,6 +25,11 @@
<%- end -%>
<%- end -%>
+<%- if canonical_url = @options.canonical_root -%>
+<% canonical_url = current.canonical_url if defined?(current) %>
+
+<%- end -%>
+