Skip to content

Commit 3efac36

Browse files
authored
Merge pull request #1002 from sphinx-contrib/improve-doc-cfg-references
Improve styled configuration references for extension's documentation
2 parents 8a6038d + 53df80b commit 3efac36

10 files changed

+99
-55
lines changed

doc/advanced-publish-permissions.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ following permissions_ when attempting to publish to a configured space:
99
- Attachments -- Add, Delete
1010

1111
Delete permissions are only required for environments using the
12-
``confluence_cleanup_purge`` (:ref:`ref<confluence_cleanup_purge>`)
13-
capabilitity.
12+
:lref:`confluence_cleanup_purge` capabilitity.
1413

1514
For environments using an OAuth connector, the following scopes are required:
1615

doc/conf.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
# Copyright Sphinx Confluence Builder Contributors (AUTHORS)
33

44
from docutils import nodes
5+
from sphinx.domains.std import StandardDomain
56
from sphinx.ext.autodoc import cut_lines
7+
from sphinx.roles import XRefRole
68
from sphinx.transforms.post_transforms import SphinxPostTransform
79
import sphinxcontrib.confluencebuilder
810

@@ -125,6 +127,46 @@ def run(self, **kwargs):
125127
classes.append('literal-link')
126128

127129

130+
class LiteralReferenceRole(XRefRole):
131+
def __init__(self):
132+
super().__init__(
133+
# mimic options for standard domain's xref
134+
lowercase=True, innernodeclass=nodes.inline, warn_dangling=True)
135+
136+
def result_nodes(self, document, env, node, is_ref):
137+
# force custom domain so we can manipulate resolved nodes
138+
node['refdomain'] = 'cb-doc-modifiers'
139+
140+
# force our custom reference role to be a `ref` type to resolve
141+
# it as any other standard reference
142+
node['reftype'] = 'ref'
143+
144+
# force explicit -- for some reason non-explicit references are
145+
# not resolved (limitations of this hack)
146+
node['refexplicit'] = True
147+
148+
return [node], []
149+
150+
151+
class ConfluenceBuilderModifiersDomain(StandardDomain):
152+
name = 'cb-doc-modifiers'
153+
label = 'confluencebuilder (modifiers)'
154+
155+
def resolve_xref(self,
156+
env, fromdocname, builder, typ, target, node, contnode):
157+
resolved = super().resolve_xref(
158+
env, fromdocname, builder, typ, target, node, contnode)
159+
160+
if resolved:
161+
# build a literal node and wrap the inner node before returning
162+
# the resolved reference
163+
inner_node = resolved.next_node()
164+
container_node = nodes.literal('', '', inner_node)
165+
resolved.replace(inner_node, container_node)
166+
167+
return resolved
168+
169+
128170
def setup(app):
129171
app.require_sphinx('6.0')
130172

@@ -136,6 +178,11 @@ def setup(app):
136178
# remove first line description docstrings in documentation
137179
app.connect('autodoc-process-docstring', cut_lines(1))
138180

181+
# add a custom "literal reference" which allow us to create page-to-page
182+
# references that are styled in literal tags
183+
app.add_domain(ConfluenceBuilderModifiersDomain)
184+
app.add_role('lref', LiteralReferenceRole())
185+
139186
# custom directives/roles for documentation
140187
app.add_object_type('builderval', 'builderval', objname='builders',
141188
indextemplate='pair: %s; builder')

doc/configuration.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ when preparing documents.
2323
.. versionadded:: 1.9
2424

2525
All options provided by this extension may be set from the running
26-
environment. For example, if ``confluence_publish`` is not explicitly set
26+
environment. For example, if |confluence_publish|_ is not explicitly set
2727
inside ``conf.py`` or provided via `Sphinx's command line`_, this extension
2828
may check the ``CONFLUENCE_PUBLISH`` environment option as a fallback. Note
2929
that this only applies options provided below and will not work for other
@@ -43,6 +43,9 @@ Essential configuration
4343
configuration options, where there is a stronger desire to present key
4444
configurations in a specific order (publish, URL, space and authentication).
4545
46+
.. |confluence_publish| replace:: ``confluence_publish``
47+
.. _confluence_publish:
48+
4649
.. confval:: confluence_publish
4750

4851
A boolean that decides whether or not to allow publishing. This option must

doc/directives.rst

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -187,21 +187,21 @@ Common
187187
:type: v1, v2
188188
189189
Pages are publish with the editor type configured through the
190-
``confluence_editor`` option. However, users can override the editor
191-
for a specific page using the ``editor`` metadata option.
190+
:lref:`confluence_editor` option. However, users can override the
191+
editor for a specific page using the ``editor`` metadata option.
192192
193193
.. code-block:: rst
194194
195195
.. confluence_metadata::
196196
:editor: v2
197197
198-
See also ``confluence_editor`` (:ref:`ref<confluence_editor>`).
198+
See also :lref:`confluence_editor`.
199199
200200
.. rst:directive:option:: full-width: flag
201201
:type: boolean
202202
203203
Pages are publish with the full-width appearance configured through the
204-
``confluence_full_width`` option. However, users can override the
204+
:lref:`confluence_full_width` option. However, users can override the
205205
appearance for a specific page using the ``full-width`` metadata
206206
option.
207207
@@ -210,7 +210,7 @@ Common
210210
.. confluence_metadata::
211211
:full-width: false
212212
213-
See also ``confluence_full_width`` (:ref:`ref<confluence_full_width>`).
213+
See also :lref:`confluence_full_width`.
214214
215215
.. rst:directive:option:: labels: value
216216
:type: space separated strings
@@ -224,8 +224,7 @@ Common
224224
.. confluence_metadata::
225225
:labels: label-a label-b
226226
227-
See also ``confluence_global_labels``
228-
(:ref:`ref<confluence_global_labels>`).
227+
See also :lref:`confluence_global_labels`.
229228
230229
.. rst:directive:: confluence_newline
231230
@@ -426,8 +425,8 @@ Confluence documents.
426425
.. rst:directive:option:: server: instance
427426
:type: string
428427
429-
Indicates a named Jira server provided via ``confluence_jira_servers``
430-
(:ref:`ref<confluence_jira_servers>`). When set, options ``server-id``
428+
Indicates a named Jira server provided via
429+
:lref:`confluence_jira_servers`. When set, options ``server-id``
431430
and ``server-name`` cannot be set.
432431
433432
.. code-block:: rst
@@ -480,8 +479,8 @@ Confluence documents.
480479
.. rst:directive:option:: server: instance
481480
:type: string
482481
483-
Indicates a named Jira server provided via ``confluence_jira_servers``
484-
(:ref:`ref<confluence_jira_servers>`). When set, options ``server-id``
482+
Indicates a named Jira server provided via
483+
:lref:`confluence_jira_servers`. When set, options ``server-id``
485484
and ``server-name`` cannot be set.
486485
487486
.. code-block:: rst
@@ -528,8 +527,8 @@ LaTeX
528527

529528
LaTeX support requires dvipng/dvisvgm to be installed on system; however,
530529
if a Confluence instance supports a LaTeX macro, the
531-
``confluence_latex_macro`` (:ref:`ref<confluence_latex_macro>`) option can
532-
be used instead. For more information, please read :doc:`guide-math`.
530+
:lref:`confluence_latex_macro` option can be used instead. For more
531+
information, please read :doc:`guide-math`.
533532

534533
The following directive can be used to help add LaTeX content into a
535534
Confluence page.
@@ -573,7 +572,7 @@ Smart links
573572
.. note::
574573

575574
Smart links will only render when using the v2 editor
576-
(see ``confluence_editor``; :ref:`ref<confluence_editor>`).
575+
(see :lref:`confluence_editor`).
577576

578577
.. rst:directive:: confluence_doc
579578

doc/guide-ci.rst

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,10 @@ publish token:
4747
Before demonstrating these methods, please note which type of authentication
4848
is required for the target Confluence instance. For example, if
4949
authenticating with an API key (Confluence Cloud; see `API tokens`_), users
50-
will need to configure both ``confluence_server_user``
51-
(:ref:`ref<confluence_server_user>`) and ``confluence_api_token``
52-
(:ref:`ref<confluence_api_token>`) options. However, if using a personal
50+
will need to configure both :lref:`confluence_server_user` and
51+
:lref:`confluence_api_token` options. However, if using a personal
5352
access token (see `Using Personal Access Tokens`_), users will need to
54-
configure only the ``confluence_publish_token``
55-
(:ref:`ref<confluence_publish_token>`) option.
53+
configure only the :lref:`confluence_publish_token` option.
5654

5755
Confluence environment variables
5856
--------------------------------
@@ -68,13 +66,13 @@ Confluence Cloud API Key
6866
If using a Confluence Cloud API key, ensure the following variables are
6967
*not set* inside ``conf.py``:
7068

71-
- ``confluence_api_token``
72-
- ``confluence_publish_token``
73-
- ``confluence_server_pass``
69+
- :lref:`confluence_api_token`
70+
- :lref:`confluence_publish_token`
71+
- :lref:`confluence_server_pass`
7472

75-
The option ``confluence_server_user`` may be set if a user will only ever be
76-
published with a single API token. If the environment plans to use multiple
77-
tokens, ensure ``confluence_server_user`` is not set as well.
73+
The option :lref:`confluence_server_user` may be set if a user will only ever
74+
be published with a single API token. If the environment plans to use multiple
75+
tokens, ensure :lref:`confluence_server_user` is not set as well.
7876

7977
Next, if the CI environment supports defining custom CI variables, create a
8078
new entry for ``CONFLUENCE_API_TOKEN``, holding the API token value to use
@@ -108,10 +106,10 @@ Confluence Data Center PAT
108106
If using a PAT, ensure the following variables are *not set* inside
109107
``conf.py``:
110108

111-
- ``confluence_api_token``
112-
- ``confluence_publish_token``
113-
- ``confluence_server_pass``
114-
- ``confluence_server_user``
109+
- :lref:`confluence_api_token`
110+
- :lref:`confluence_publish_token`
111+
- :lref:`confluence_server_pass`
112+
- :lref:`confluence_server_user`
115113

116114
Next, if the CI environment supports defining custom CI variables, create a
117115
new entry for ``CONFLUENCE_PUBLISH_TOKEN``, holding the PAT value to use

doc/guide-class-hints.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ For example:
3333
if __name__ == '__main__':
3434
main()
3535
36-
See also :ref:`confluence_code_block_theme <confluence_code_block_theme>`.
36+
See also :lref:`confluence_code_block_theme`.
3737

3838
``strike``
3939
----------

doc/guide-math.rst

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,12 @@ reason why the Confluence builder extension promotes the use of
113113
marketplace add-on which provides LaTeX macro support, math content can instead
114114
be injected into these macros instead.
115115

116-
To use a LaTeX macro, the ``confluence_latex_macro``
117-
(:ref:`ref<confluence_latex_macro>`) configuration option can be used. This
118-
option accepts either the name of a macro to use or a dictionary of macro
119-
options to consider (the dictionary is for more complex configurations such as
120-
when attempting to support block-specific and inlined-specific macros). For
121-
example, to specify the macro to use for any LaTeX content, the following
122-
can be used:
116+
To use a LaTeX macro, the :lref:`confluence_latex_macro` configuration option
117+
can be used. This option accepts either the name of a macro to use or a
118+
dictionary of macro options to consider (the dictionary is for more complex
119+
configurations such as when attempting to support block-specific and
120+
inlined-specific macros). For example, to specify the macro to use for any
121+
LaTeX content, the following can be used:
123122

124123
.. code-block:: python
125124

doc/roles.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ LaTeX
6060

6161
LaTeX support requires dvipng/dvisvgm to be installed on system; however,
6262
if a Confluence instance supports a LaTeX macro, the
63-
``confluence_latex_macro`` (:ref:`ref<confluence_latex_macro>`) option can
64-
be used instead. For more information, please read :doc:`guide-math`.
63+
:lref:`confluence_latex_macro` option can be used instead. For more
64+
information, please read :doc:`guide-math`.
6565

6666
The following role can be used to help include LaTeX content into generated
6767
Confluence documents.
@@ -119,7 +119,7 @@ generated Confluence documents.
119119
Contact :confluence_mention:`b9aaf35e80441f415c3a3d3c53695d0e` for help.
120120
121121
A user mapping table can also be configured using the
122-
``confluence_mentions`` (:ref:`ref<confluence_mentions>`) option.
122+
:lref:`confluence_mentions` option.
123123

124124
.. index:: Smart links; Roles
125125
.. _smart-link-roles:
@@ -130,7 +130,7 @@ Smart links
130130
.. note::
131131

132132
Smart links will only render when using the v2 editor
133-
(see ``confluence_editor``; :ref:`ref<confluence_editor>`).
133+
(see :lref:`confluence_editor`).
134134

135135
Support for inlined smart links can be created using the following roles.
136136

doc/tips.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,8 @@ is moved as a child of the container page:
6363
- See Also
6464

6565
Users needing to restrict the extension from possibly mangling manually prepared
66-
content can use the ``confluence_publish_prefix``
67-
(:ref:`ref<confluence_publish_prefix>`) or ``confluence_publish_postfix``
68-
(:ref:`ref<confluence_publish_postfix>`) options.
66+
content can use the :lref:`confluence_publish_prefix` or
67+
:lref:`confluence_publish_postfix` options.
6968

7069
See also the :ref:`dry run capability <confluence_publish_dryrun>` and the
7170
:ref:`title overrides capability <confluence_title_overrides>`.
@@ -75,7 +74,7 @@ Setting a publishing timeout
7574

7675
By default, this extension does not define any timeouts for a publish event. It
7776
is recommended to provide a timeout value based on the environment being used
78-
(see ``confluence_timeout``; :ref:`ref<confluence_timeout>`).
77+
(see :lref:`confluence_timeout`).
7978

8079
Connection troubleshooting
8180
--------------------------

doc/tutorial.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ targeted.
9797

9898
.. note::
9999

100-
The configuration of the space key (``confluence_space_key``) is
100+
The configuration of the space key (:lref:`confluence_space_key`) is
101101
case-sensitive. Ensure the value matches the case found on the Confluence
102102
instances (typically, uppercase).
103103

@@ -107,8 +107,8 @@ Recommended configurations
107107
By default, this extension will publish any documents to the root of a
108108
configured space. It can be common for most users to want to publish a
109109
documentation set as children of an already existing page. To take advantage of
110-
this feature, a user will want to define a ``confluence_parent_page`` option in
111-
their configuration file. For example:
110+
this feature, a user will want to define a :lref:`confluence_parent_page`
111+
option in their configuration file. For example:
112112

113113
.. code-block:: python
114114
@@ -119,8 +119,8 @@ extension to publish all documents under the ``MyDocumentation`` page.
119119

120120
For first time users, they may wish to sanity check what content will be
121121
published before publishing for the first time to a Confluence instance. A user
122-
can perform a dryrun by configuring the ``confluence_publish_dryrun`` option in
123-
the project's configuration file. For example:
122+
can perform a dryrun by configuring the :lref:`confluence_publish_dryrun`
123+
option in the project's configuration file. For example:
124124

125125
.. code-block:: python
126126
@@ -146,8 +146,8 @@ building/publishing:
146146
147147
Documentation of the project should now be published to the Confluence site.
148148

149-
For users who set the dryrun option above (``confluence_publish_dryrun``), they
150-
may inspect the output of the run to confirm what the publish event will
149+
For users who set the dryrun option above (:lref:`confluence_publish_dryrun`),
150+
they may inspect the output of the run to confirm what the publish event will
151151
perform. If the desired result is observed, a user can remove the dryrun option
152152
and re-invoke the build/publish command to publish onto the configured
153153
Confluence instance.

0 commit comments

Comments
 (0)