Skip to content

Commit

Permalink
Merge pull request #1044 from sphinx-contrib/linkcode-improvements
Browse files Browse the repository at this point in the history
`sphinx.ext.linkcode` Improvements
  • Loading branch information
jdknight authored Oct 7, 2024
2 parents 624e54c + 8eb708e commit 75b6a66
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 5 deletions.
5 changes: 1 addition & 4 deletions doc/features.rst
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,7 @@ Type Notes

Confluence does not support the injection of
JavaScript into a page in most scenarios.
`sphinx.ext.linkcode`_ Unsupported.

This extension only supports injecting
references for the ``html`` builder.
`sphinx.ext.linkcode`_ Supported (Sphinx v8.1+)
`sphinx.ext.mathjax`_ Unsupported.

Confluence does not support the injection of
Expand Down
2 changes: 1 addition & 1 deletion sphinxcontrib/confluencebuilder/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ConfluenceBuilder(Builder):
name = 'confluence'
format = 'confluence_storage'
supported_image_types = SUPPORTED_IMAGE_TYPES
supported_linkcode = True
supported_linkcode = name
supported_remote_images = True

def __init__(self, app, env=None):
Expand Down
1 change: 1 addition & 0 deletions sphinxcontrib/confluencebuilder/singlebuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

class SingleConfluenceBuilder(ConfluenceBuilder):
name = 'singleconfluence'
supported_linkcode = name

def assemble_doctree(self):
root_doc = self.config.root_doc
Expand Down
10 changes: 10 additions & 0 deletions tests/sample-sets/linkcode/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
extensions = [
'sphinxcontrib.confluencebuilder',
'sphinx.ext.linkcode',
]

def linkcode_resolve(domain, info):
name = info.get('fullname', None)
if not name:
return None
return f'https://example.org/src/{name}'
8 changes: 8 additions & 0 deletions tests/sample-sets/linkcode/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
linkcode
========

.. module:: example

.. class:: ExampleModule

This is an example.
11 changes: 11 additions & 0 deletions tests/sample-sets/linkcode/tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[tox]
package_root={toxinidir}{/}..{/}..{/}..

[testenv]
commands =
{envpython} -m tests.test_sample {posargs}
setenv =
PYTHONDONTWRITEBYTECODE=1
TOX_INI_DIR={toxinidir}
passenv = *
use_develop = true
11 changes: 11 additions & 0 deletions tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def setUpClass(cls):
space_key = os.getenv(SPACE_ENV_KEY, DEFAULT_TEST_SPACE)
cls.config = prepare_conf()
cls.config['extensions'].append('sphinx.ext.ifconfig')
cls.config['extensions'].append('sphinx.ext.linkcode')
cls.config['confluence_api_token'] = os.getenv(AUTH_ENV_KEY)
cls.config['confluence_full_width'] = False
cls.config['confluence_page_generation_notice'] = True
Expand All @@ -59,6 +60,16 @@ def setUpClass(cls):
cls.test_key = os.getenv(TESTKEY_ENV_KEY, DEFAULT_TEST_KEY)
cls.test_version = os.getenv(TESTKEY_ENV_VERSION, DEFAULT_TEST_VERSION)

def linkcode_resolve(domain, info):
module = info.get('module', None)
if module != 'linkcode_example':
return None
name = info.get('fullname', None)
if not name:
return None
return f'https://example.org/src/{name}'
cls.config['linkcode_resolve'] = linkcode_resolve

# overrides from user
try:
from validation_test_overrides import config_overrides
Expand Down
1 change: 1 addition & 0 deletions tests/validation-sets/extensions/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ found inside the internal tree.
autosummary
graphviz
inheritance_diagram
linkcode
todo
43 changes: 43 additions & 0 deletions tests/validation-sets/extensions/linkcode.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
sphinx.ext.linkcode
===================

.. hint::

This requires registering the ``sphinx.ext.linkcode`` extension in the
documentation's configuration file.

This page shows an example of the linkcode_ extension's capabilities. A
project configuration defines a ``linkcode_resolve`` function:

.. code-block:: python
def linkcode_resolve(domain, info):
name = info.get('fullname', None)
if not name:
return None
return "https://example.org/src/%s" % name
When documents include object descriptions such as the following, source
links should be included:

.. code-block:: none
.. class:: ExampleModule
This is an example.
Output
------

The following shows an example of linkcode:

.. module:: linkcode_example

.. class:: ExampleModule

This is an example.


.. references ------------------------------------------------------------------
.. _linkcode: https://www.sphinx-doc.org/en/master/usage/extensions/linkcode.html

0 comments on commit 75b6a66

Please sign in to comment.