GitHub Expand
logo Sphinx

瀏覽

  • Documentation »
  • 使用 Sphinx »
  • 擴充套件 »
  • sphinx.ext.extlinks -- Markup to shorten external links

On this page

  • sphinx.ext.extlinks -- Markup to shorten external links
    • extlinks
    • extlinks_detect_hardcoded_links

基礎知識

  • 安裝 Sphinx
  • 開始使用
  • 建置您的第一個專案

使用者指南

  • 使用 Sphinx
    • reStructuredText
    • Markdown
    • 交叉參照
    • 組態
    • 建置器
    • 領域
    • 擴充套件
      • sphinx.ext.apidoc -- 從 Python 軟體包生成 API 文件
      • sphinx.ext.autodoc -- Include documentation from docstrings
      • sphinx.ext.autosectionlabel -- Allow referencing sections by their title
      • sphinx.ext.autosummary -- Generate autodoc summaries
      • sphinx.ext.coverage -- Collect doc coverage stats
      • sphinx.ext.doctest -- Test snippets in the documentation
      • sphinx.ext.duration -- Measure durations of Sphinx processing
      • sphinx.ext.extlinks -- Markup to shorten external links
      • sphinx.ext.githubpages -- Publish HTML docs in GitHub Pages
      • sphinx.ext.graphviz -- Add Graphviz graphs
      • sphinx.ext.ifconfig -- Include content based on configuration
      • sphinx.ext.imgconverter -- A reference image converter using Imagemagick
      • sphinx.ext.inheritance_diagram -- Include inheritance diagrams
      • sphinx.ext.intersphinx -- Link to other projects' documentation
      • sphinx.ext.linkcode -- Add external links to source code
      • Math support for HTML outputs in Sphinx
      • sphinx.ext.napoleon -- Support for NumPy and Google style docstrings
      • sphinx.ext.todo -- Support for todo items
      • sphinx.ext.viewcode -- Add links to highlighted source code
    • HTML 主題
    • 國際化
    • Sphinx Web Support
  • 擴充 Sphinx
  • Sphinx API
  • LaTeX customization

社群

  • 獲取支援
  • Contribute to Sphinx
  • Sphinx 常見問題集
  • Sphinx 作者群

參考手冊

  • 命令行工具
  • 組態
  • 擴充套件
    • sphinx.ext.apidoc -- 從 Python 軟體包生成 API 文件
    • sphinx.ext.autodoc -- Include documentation from docstrings
    • sphinx.ext.autosectionlabel -- Allow referencing sections by their title
    • sphinx.ext.autosummary -- Generate autodoc summaries
    • sphinx.ext.coverage -- Collect doc coverage stats
    • sphinx.ext.doctest -- Test snippets in the documentation
    • sphinx.ext.duration -- Measure durations of Sphinx processing
    • sphinx.ext.extlinks -- Markup to shorten external links
    • sphinx.ext.githubpages -- Publish HTML docs in GitHub Pages
    • sphinx.ext.graphviz -- Add Graphviz graphs
    • sphinx.ext.ifconfig -- Include content based on configuration
    • sphinx.ext.imgconverter -- A reference image converter using Imagemagick
    • sphinx.ext.inheritance_diagram -- Include inheritance diagrams
    • sphinx.ext.intersphinx -- Link to other projects' documentation
    • sphinx.ext.linkcode -- Add external links to source code
    • Math support for HTML outputs in Sphinx
    • sphinx.ext.napoleon -- Support for NumPy and Google style docstrings
    • sphinx.ext.todo -- Support for todo items
    • sphinx.ext.viewcode -- Add links to highlighted source code
  • reStructuredText
  • 詞彙表
  • 變更日誌
  • 使用 Sphinx 的專案

sphinx.ext.extlinks -- Markup to shorten external links¶

模組作者: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 https://github.com/sphinx-doc/sphinx/issues/num. Typing this URL again and again is tedious, so you can use extlinks to avoid repeating yourself.

The extension adds a config value:

extlinks¶
Type:
dict[str, tuple[str, str | None]]
預設值:
{}

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

extlinks = {'issue': ('https://github.com/sphinx-doc/sphinx/issues/%s',
                      'issue %s')}

Now, you can use the alias name as a new role, e.g. :issue:`123`. This then inserts a link to https://github.com/sphinx-doc/sphinx/issues/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 caption:

  • If caption is None, the link caption is the full URL.

  • If caption is a string, then it must contain %s exactly once. In this case the link caption is caption with the partial URL substituted for %s -- in the above example, the link caption would be issue 123.

To produce a literal % in either base URL or caption, use %%:

extlinks = {'KnR': ('https://example.org/K%%26R/page/%s',
                      '[K&R; page %s]')}

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 caption is not relevant.

在 4.0 版的變更: Support to substitute by '%s' in the caption.

備註

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

extlinks_detect_hardcoded_links¶
Type:
bool
預設值:
False

If enabled, extlinks emits a warning if a hardcoded link is replaceable by an extlink, and suggests a replacement via warning.

在 4.5 版被加入.

Previous
sphinx.ext.duration -- Measure durations of Sphinx processing
Next
sphinx.ext.githubpages -- Publish HTML docs in GitHub Pages
© 版權所有 2007-2025, the Sphinx developers. 使用 Sphinx 8.3.0+/67f1331 建立。