How to modify trac to create own custom Link format (TracLinks)
In the open-source trac issue tracking software, when you write text in the wiki or ticket comments, you can link to a ticket using #1234
or you can link to a code changeset using r1234
. This is the documentation: http://trac.edgewall.org/wiki/TracLinks
I would like to define my own link format. 3 examples of what I'd like to do:
- I'd like
a1234
to link to a acunote ticket (which complements trac but is external to our trac installation). - I'开发者_StackOverflowd like
ge2a1b3caadd0986e3e3d316c01965a2495329b87
to link to a github commit (i.e. https://github.com/peritor/webistrano/commit/e2a1b3caadd0986e3e3d316c01965a2495329b87). - I'd like
CComponent
to link to the Yii documentation (i.e. http://www.yiiframework.com/doc/api/1.1/CComponent)
Does anyone know how I can do this using trac v0.12. Should I use a Macro? a plugin? a Genshi template? It strikes me as something that could be quite simple if you have the know how?
If you want this exact syntax, you have no other choice than to create a plugin and have a Component
that implements the IWikiSyntaxProvider
interface.
If you can live with a slightly different syntax, for example [a:1234]
for the acunote ticket, [g:e2a1b3caadd0986e3e3d316c01965a2495329b87]
for the github changeset, and [y:CComponent]
for the Yii documentation, then you could add the following entries to the InterMapTxt page of your Trac installation:
a http://my.acunote.site/ticket/$1 # Acunote ticket $1
g https://github.com/peritor/webistrano/commit/$1 # Changeset $1 on Github
y http://www.yiiframework.com/doc/api/1.1/$1 # Yii documentation for $1
Remy is correct in that your syntax is potentially making this more difficult. The standard Trac syntax for links is resource_type:link_specifier
. If you are able to use that syntax instead, then it's fairly straightforward to use Inter-Wiki links to accomplish what you want.
If that's not an option, you can do what you describe with a custom-built plugin. It's not as difficult as it might sound, you can use the source from an existing plugin as an example. I have done this several times before, all you really need is a regular expression that represents the syntax you wish to use and one that represents the format of the resulting link, as well as about one page of Python code.
Update: For an example of how to do this via a Trac plugin, there is sample code and a description in the official Trac documentation.
精彩评论