在开源 trac 问题跟踪软件中,当您在 wiki 或工单评论中编写文本时,您可以链接到使用 #1234
获取票证,或者您可以使用 r1234
链接到代码变更集。这是文档:http://trac.edgewall.org/wiki/TracLinks
我想要定义我自己的链接格式。我想做的 3 个示例:
- 我希望
a1234
链接到 acunote 票证(它是对 trac 的补充,但在我们的 trac 安装之外)。
- 我希望
ge2a1b3caadd0986e3e3d316c01965a2495329b87
链接到 github 提交(即 https://github.com/peritor/webistrano/commit/e2a1b3caadd0986e3e3d316c01965a2495329b87)。
- 我希望
CComponent
链接到 Yii 文档(即 http://www.yiiframework.com/doc/api/1.1/CComponent)
有谁知道如何我可以使用以下方法来做到这一点trac v0.12。我应该使用宏吗?一个插件? Genshi 模板?我觉得如果你知道怎么做的话,事情可能会很简单?
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'd 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?
发布评论
评论(2)
如果您想要这种精确的语法,您别无选择,只能创建一个插件并拥有一个实现
IWikiSyntaxProvider
Component 。 edgewall.org/browser//trunk/trac/wiki/api.py?rev=10617&marks=172-196#L170" rel="nofollow">界面。如果您可以接受稍微不同的语法,例如用于 acunote 票证的
[a:1234]
、用于 github 变更集的[g:e2a1b3caadd0986e3e3d316c01965a2495329b87]
和[y:CComponent]
对于 Yii 文档,那么您可以将以下条目添加到 InterMapTxt 页面:If you want this exact syntax, you have no other choice than to create a plugin and have a
Component
that implements theIWikiSyntaxProvider
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:雷米是正确的,因为你的语法可能会使这变得更加困难。链接的标准 Trac 语法是
resource_type:link_specifier
。如果您能够使用该语法,那么使用 Inter-Wiki 链接来完成您想要的任务就相当简单了。如果这不是一个选项,您可以使用自定义插件执行您所描述的操作。这并不像听起来那么困难,您可以使用现有插件的源代码作为示例。我之前已经做过好几次了,您真正需要的只是一个表示您希望使用的语法的正则表达式和一个表示结果链接格式的正则表达式,以及大约一页 Python 代码。
更新:有关如何通过 Trac 插件执行此操作的示例,Trac 官方文档。
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.