Pepijn de Vos avatar Pepijn de Vos committed b8e94d9

format url

Comments (0)

Files changed (1)

pygments/formatters/html.py

 """
 
 import os
+import os.path
 import sys
 import StringIO
 
         Defaults to True. Determines if links to name definitions should
         link to other files.
 
-    'tagurlprefix`
+    'urlformat`
         The URL to the root of your project, where the tag file resides.
         This is prepended to links if `singlepage` is false.
 
     `linkfext`
-        Similar to `tagurlprefix`, but sets the file extension used.
+        Similar to `urlformat`, but sets the file extension used.
         Defaults to .html
 
     **Subclassing the HTML formatter**
         self.cssfile = self._decodeifneeded(options.get('cssfile', ''))
         self.noclobber_cssfile = get_bool_opt(options, 'noclobber_cssfile', False)
         self.tagsfile = self._decodeifneeded(options.get('tagsfile', ''))
-        self.tagurlprefix = self._decodeifneeded(options.get('tagurlprefix', ''))
-        self.linkfext = self._decodeifneeded(options.get('linkfext', '.html'))
-        self.singlepage = get_bool_opt(options, 'singlepage', True)
+        self.urlformat = self._decodeifneeded(options.get('urlformat', ''))
 
         if self.tagsfile:
             try:
         escape_table = _escape_html_table
 
         tagsfile = self.tagsfile
-        singlepage = self.singlepage
-        if not singlepage:
-            tagurlprefix = self.tagurlprefix
-            linkfext = self.linkfext
+        urlformat = self.urlformat
 
         lspan = ''
         line = ''
             parts = value.translate(escape_table).split('\n')
 
             if tagsfile and ttype in Token.Name:
-                filename, lineNumber = self._lookup_ctag(value)
-                if filename:
-                    if singlepage:
-                        parts[0] = "<a href=\"#%s-%s\">%s" % (self.lineanchors, lineNumber, parts[0])
-                    else:
-                        parts[0] = "<a href=\"%s%s%s#%s-%s\">%s" % (tagurlprefix, filename, linkfext, self.lineanchors, lineNumber, parts[0])
-                    parts[-1] = "%s</a>" % parts[-1]
+                filename, linenumber = self._lookup_ctag(value)
+                if linenumber:
+                    base, filename = os.path.split(filename)
+                    filename, extension = os.path.splitext(filename)
+                    url = urlformat.format(path=base, fname=filename, fext=extension)
+                    parts[0] = "<a href=\"%s#%s-%d\">%s" % (url, self.lineanchors, linenumber, value)
+                    parts[-1] = parts[-1] + "</a>"
 
             # for all but the last line
             for part in parts[:-1]:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.