Sphinx - 生成对 Trac 票证和变更集的自动引用

发布于 2024-08-18 19:20:27 字数 449 浏览 4 评论 0原文

Sphinx,有没有办法自动链接文本,如#112r1023Trac 中相应的票证/变更集?

例如:

#112  -> http://mytracsite/tickets/112
r1023 -> http://mytracsite/changeset/1023

请参阅 TracLinks 了解更多示例。

Is Sphinx, is there way to automatically link text like #112 or r1023 to the corresponding tickets/changesets in Trac?

For eg:

#112  -> http://mytracsite/tickets/112
r1023 -> http://mytracsite/changeset/1023

See TracLinks for more examples.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

时光磨忆 2024-08-25 19:20:27

如果将其放入 config.py 中


trac_url = 'http://mytratsite/'

from docutils import nodes, utils
from docutils.parsers.rst import roles
import urllib

def trac_role(role, rawtext, text, lineno, inliner, options={}, content=[]):
  ref = trac_url + '/intertrac/' + urllib.quote(text, safe='')
  node = nodes.reference(rawtext, utils.unescape(text), refuri=ref, **options)
  return [node],[]

roles.register_canonical_role('trac', trac_role)

,则可以在文档中使用 :trac:`#123`:trac:`r1023`

这可能是快速链接到 trac 站点的最简单方法。它自动适用于所有类型的 TracLink,因为它对链接使用 intertrac 机制。

If you put this in your config.py


trac_url = 'http://mytratsite/'

from docutils import nodes, utils
from docutils.parsers.rst import roles
import urllib

def trac_role(role, rawtext, text, lineno, inliner, options={}, content=[]):
  ref = trac_url + '/intertrac/' + urllib.quote(text, safe='')
  node = nodes.reference(rawtext, utils.unescape(text), refuri=ref, **options)
  return [node],[]

roles.register_canonical_role('trac', trac_role)

Then you can use :trac:`#123` and :trac:`r1023` in your documents.

This is probably the easiest way to make quick links to a trac site. It automatically works for all kinds of TracLinks because it uses the intertrac mechanism for the links.

流年里的时光 2024-08-25 19:20:27

Sphinx 1.0 现在支持使用 extlinks 扩展的外部链接 。使用可配置的角色名称(例如“问题”),您可以编写如下链接:

:issue:`123`

它将转换为 http://mytracsite/123

Sphinx 1.0 now supports external links using the extlinks extension. Using a configurable role name (e.g. 'issue') you can write your links like:

:issue:`123`

and it will be converted to http://mytracsite/123.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文