Modify

Opened 12 years ago

Last modified 12 years ago

#10019 new enhancement

Add support for function/member link targets

Reported by: elb@… Owned by: Andi
Priority: normal Component: JavadocWikiMacro
Severity: normal Keywords:
Cc: Trac Release: 0.11

Description

The attached patch adds support for javadoc macro targets that contain a function or member reference, using class#member syntax. For example, to link to String#equals(Object), you would use [[javadoc(java.util.String#equals(java.lang.Object)]]. (Unfortunately, the type signatures must match exactly.) This would be linkified with the text String#equals(java.lang.Object) by default.

Attachments (2)

javadoc-function-member-link.diff (2.3 KB) - added by elb@… 12 years ago.
Patch to add function/member support to JavadocMacro (change &lt; to <)
javadoc-function-member-link.2.diff (2.3 KB) - added by elb@… 12 years ago.
Patch to add function/member support to JavadocMacro (change &lt; to <)

Download all attachments as: .zip

Change History (3)

Changed 12 years ago by elb@…

Patch to add function/member support to JavadocMacro (change &lt; to <)

Changed 12 years ago by elb@…

Patch to add function/member support to JavadocMacro (change &lt; to <)

comment:1 Changed 12 years ago by anonymous

OK, I can't attach a diff to this ticket. Trac either marks it as spam, or attaches an empty file. Here it is in the most annoying possible format:

diff -r e5467f8f4cf9 javadoc.py
--- a/javadoc.py	Wed May 09 17:41:08 2012 -0400
+++ b/javadoc.py	Wed May 09 18:06:57 2012 -0400
@@ -12,6 +12,7 @@
 
 # Author Matthew Good <trac@matt-good.net>
 # ported to trac 0.11 by <friends.of.neo@gmail.com>
+# Function/member links added by <elb@fiji-systems.com>
 
 # Trac WikiMacro for rendering links to Javadoc urls
 # Accepts one or two arguments separated by a comma.
@@ -65,6 +66,7 @@
 #-------------------------------------------------------------------------------
 from trac.core import *
 from urlparse import urljoin
+from urllib import quote
 from string import ascii_uppercase
 from genshi.builder import tag
 from trac.wiki.macros import WikiMacroBase
@@ -91,28 +93,32 @@
 	def type_path(self, package, clss):
 		return self.package_path(package) + (clss and (clss + '.html') or 'package-summary.html')
     
-	def javadoc_url(self, package, clss):
-		return urljoin(self.base_url(package), self.type_path(package, clss))
+	def javadoc_url(self, package, clss, func):
+		return urljoin(self.base_url(package), self.type_path(package, clss)) + (func and '#'+quote(func) or '')
     
 	def split_at(self, a, index):
 		return (a[:index], a[index + 1:])
     
 	def split_type(self, value):
+		h = value.rfind('#')
+		func = None
+		if h != -1:
+			value, func = self.split_at(value, h)
 		package, clss = self.split_at(value, value.rfind('.'))
 		if clss[0] in ascii_uppercase:
-			return (package, clss)
+			return (package, clss, func)
 		else:
-			return (value, None)
+			return (value, None, None)
     
 	def link(self, href, text):
 		return 'NOTSPAM<NOTSPAMa href="%s" class="javadoc">%s</a>' % (href, text)
     
 	def javadoc_link(self, value, linktext):
-		package, clss = self.split_type(value)
-		return self.link(self.javadoc_url(package, clss), linktext or clss or package)
+		package, clss, func = self.split_type(value)
+		return self.link(self.javadoc_url(package, clss, func), linktext or (func and (clss + '#' + func)) or clss or package)
 
 	def expand_macro(self, formatter, name, args):
 		txt = args.split(',', 1)
 		javatype = txt[0]
 		linktext = len(txt) > 1 and txt[1].strip() or None
-		return self.javadoc_link(javatype, linktext)
\ No newline at end of file
+		return self.javadoc_link(javatype, linktext)

Delete the NOTSPAMs to get the < back.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as new The owner will remain Andi.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.