• 主页
  • 获取
  • 文档
  • 扩展/开发
SPHINX

导航

  • 索引
  • 模块 |
  • 下一页 |
  • 上一页 |
  • Sphinx 主页 |
  • 文档 »
  • 扩展 »

上一个主题

sphinx.ext.todo – 支持待办事项

下一个主题

sphinx.ext.viewcode – 给高亮显示的源代码添加链接

本页

  • 显示源代码

快速搜索

sphinx.ext.extlinks – 标记,以缩短外部链接¶

模块作者:Georg Brandl

1.0 新版功能.

This extension is meant to help with the common pattern of having many external links that point to URLs on one and the same site, e.g. links to bug trackers, version control web interfaces, or simply subpages in other websites. It does so by providing aliases to base URLs, so that you only need to give the subpage name when creating a link.

Let’s assume that you want to include many links to issues at the Sphinx tracker, at http://bitbucket.org/birkenfeld/sphinx/issue/num. Typing this URL again and again is tedious, so you can use extlinks to avoid repeating yourself.

The extension adds one new config value:

extlinks¶

This config value must be a dictionary of external sites, mapping unique short alias names to a base URL and a prefix. For example, to create an alias for the above mentioned issues, you would add

extlinks = {'issue': ('https://bitbucket.org/birkenfeld/sphinx/issue/%s',
                      'issue ')}

Now, you can use the alias name as a new role, e.g. :issue:`123`. This then inserts a link to https://bitbucket.org/birkenfeld/sphinx/issue/123. As you can see, the target given in the role is substituted in the base URL in the place of %s.

The link caption depends on the second item in the tuple, the prefix:

  • If the prefix is None, the link caption is the full URL.
  • If the prefix is the empty string, the link caption is the partial URL given in the role content (123 in this case.)
  • If the prefix is a non-empty string, the link caption is the partial URL, prepended by the prefix – in the above example, the link caption would be issue 123.

You can also use the usual “explicit title” syntax supported by other roles that generate links, i.e. :issue:`this issue <123>`. In this case, the prefix is not relevant.

注解

Since links are generated from the role in the reading stage, they appear as ordinary links to e.g. the linkcheck builder.

评论支持 Disqus

导航

  • 索引
  • 模块 |
  • 下一页 |
  • 上一页 |
  • Sphinx 主页 |
  • 文档 »
  • 扩展 »
© Copyright 2007-2013, Georg Brandl. 由 Sphinx 1.5.3 创建。