GitHub Expand
logo Sphinx

ナビゲーション

  • Documentation »
  • Sphinxを使う »
  • 拡張 »
  • sphinx.ext.extlinks -- 外部リンクを短縮表記させるマークアップ

On this page

  • sphinx.ext.extlinks -- 外部リンクを短縮表記させるマークアップ
    • extlinks
    • extlinks_detect_hardcoded_links

The Basics

  • Sphinxのインストール
  • Getting started
  • Build your first project

User guide

  • Sphinxを使う
    • reStructuredText
    • Markdown
    • Cross-references
    • 設定
    • Builders
    • Domains
    • 拡張
      • sphinx.ext.apidoc -- Generate API documentation from Python packages
      • sphinx.ext.autodoc -- docstringからのドキュメントの取り込み
      • sphinx.ext.autosectionlabel -- Allow referencing sections by their title
      • sphinx.ext.autosummary -- autodocのサマリーの生成
      • sphinx.ext.coverage -- ドキュメントのカバレッジの状況を収集します
      • sphinx.ext.doctest -- ドキュメント内の簡易テスト
      • sphinx.ext.duration -- Sphinx処理の処理時間を測定します。
      • sphinx.ext.extlinks -- 外部リンクを短縮表記させるマークアップ
      • sphinx.ext.githubpages -- GitHub PagesへHTMLドキュメントを公開します
      • sphinx.ext.graphviz -- Graphvizのグラフを追加
      • sphinx.ext.ifconfig -- 設定にしたがってコンテンツをON/OFFする
      • sphinx.ext.imgconverter -- A reference image converter using Imagemagick
      • sphinx.ext.inheritance_diagram -- 継承関係図の追加
      • sphinx.ext.intersphinx -- 他のプロジェクトのドキュメントへのリンク
      • sphinx.ext.linkcode -- ソースコードへの外部リンクを追加
      • SphinxにおけるHTML出力での数式サポート
      • sphinx.ext.napoleon -- NumPy および Google スタイルの docstring をドキュメントに取り込む
      • sphinx.ext.todo -- Todoアイテムのサポート
      • sphinx.ext.viewcode -- ハイライト済みのソースコードへのリンクを追加
    • HTML theming
    • 国際化
    • Sphinxウェブサポート
  • Sphinxの拡張
  • Sphinx API
  • LaTeX のカスタマイズ

コミュニティ

  • Get support
  • Contribute to Sphinx
  • Sphinx FAQ
  • Sphinx 作成者

Reference

  • Command-line tools
  • 設定
  • 拡張
    • sphinx.ext.apidoc -- Generate API documentation from Python packages
    • sphinx.ext.autodoc -- docstringからのドキュメントの取り込み
    • sphinx.ext.autosectionlabel -- Allow referencing sections by their title
    • sphinx.ext.autosummary -- autodocのサマリーの生成
    • sphinx.ext.coverage -- ドキュメントのカバレッジの状況を収集します
    • sphinx.ext.doctest -- ドキュメント内の簡易テスト
    • sphinx.ext.duration -- Sphinx処理の処理時間を測定します。
    • sphinx.ext.extlinks -- 外部リンクを短縮表記させるマークアップ
    • sphinx.ext.githubpages -- GitHub PagesへHTMLドキュメントを公開します
    • sphinx.ext.graphviz -- Graphvizのグラフを追加
    • sphinx.ext.ifconfig -- 設定にしたがってコンテンツをON/OFFする
    • sphinx.ext.imgconverter -- A reference image converter using Imagemagick
    • sphinx.ext.inheritance_diagram -- 継承関係図の追加
    • sphinx.ext.intersphinx -- 他のプロジェクトのドキュメントへのリンク
    • sphinx.ext.linkcode -- ソースコードへの外部リンクを追加
    • SphinxにおけるHTML出力での数式サポート
    • sphinx.ext.napoleon -- NumPy および Google スタイルの docstring をドキュメントに取り込む
    • sphinx.ext.todo -- Todoアイテムのサポート
    • sphinx.ext.viewcode -- ハイライト済みのソースコードへのリンクを追加
  • reStructuredText
  • 用語集
  • Changelog
  • Sphinxを使用しているプロジェクト

sphinx.ext.extlinks -- 外部リンクを短縮表記させるマークアップ¶

モジュールの作者: Georg Brandl

Added in version 1.0.

この拡張を利用すると、同一のウェブサイト内にある多くの外部参照リンクを利用する際に、共通部分をパターン化できます。例えば、バグトラッカーや、バージョン管理システムのウェブインタフェース、他のウェブサイトの中のサブページなどです。この拡張機能は、ベースとなるURLのエイリアスを提供します。サブのページの名前をつけるだけで、リンクを作成できるようになります。

Sphinxのissueトラッカー上の項目に対して、多くのリンクを作成したいとしましょう。各ページのURLは、 https://github.com/sphinx-doc/sphinx/issues/num です。このURLを何度も何度もタイプするのは疲れますが、 extlinks を使うと、この繰り返し作業から解法されます。

この拡張は新しい設定値を追加します:

extlinks¶
タイプ:
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.

注釈

読み込み段階でロールからリンクが生成されるため、 linkcheck ビルダーなどでは通常のリンクとして扱われます。

extlinks_detect_hardcoded_links¶
タイプ:
bool
デフォルト:
False

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

Added in version 4.5.

Previous
sphinx.ext.duration -- Sphinx処理の処理時間を測定します。
Next
sphinx.ext.githubpages -- GitHub PagesへHTMLドキュメントを公開します
© 著作権 2007-2026, the Sphinx developers. Created using Sphinx 9.1.1+/c1b618c55.