Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom link texts for permalinks and links to source code. #6550

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions doc/usage/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,12 @@ that use Sphinx's HTMLWriter class.
This can now be a string to select the actual text of the link.
Previously, only boolean values were accepted.

.. confval:: html_add_permalinks_html

The text for the permalink can also be specified as an HTML string. If both
``html_add_permalinks`` and ``html_add_permalinks_html`` are specified,
``html_add_permalinks_html`` wins.

.. confval:: html_sidebars

Custom sidebar templates, must be a dictionary that maps document names to
Expand Down
1 change: 1 addition & 0 deletions sphinx/builders/html/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,7 @@ def setup(app: Sphinx) -> Dict[str, Any]:
app.add_config_value('html_additional_pages', {}, 'html')
app.add_config_value('html_domain_indices', True, 'html', [list])
app.add_config_value('html_add_permalinks', '¶', 'html')
app.add_config_value('html_add_permalinks_html', None, 'html')
app.add_config_value('html_use_index', True, 'html')
app.add_config_value('html_split_index', False, 'html')
app.add_config_value('html_copy_source', True, 'html')
Expand Down
2 changes: 2 additions & 0 deletions sphinx/writers/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ def __init__(self, document: nodes.document, builder: Builder) -> None:
if not isinstance(self.permalink_text, str):
self.permalink_text = '¶' if self.permalink_text else ''
self.permalink_text = self.encode(self.permalink_text)
if self.config.html_add_permalinks_html:
self.permalink_text = self.config.html_add_permalinks_html
self.secnumber_suffix = self.config.html_secnumber_suffix
self.param_separator = ''
self.optional_param_level = 0
Expand Down
2 changes: 2 additions & 0 deletions sphinx/writers/html5.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ def __init__(self, document: nodes.document, builder: Builder) -> None:
if not isinstance(self.permalink_text, str):
self.permalink_text = '¶' if self.permalink_text else ''
self.permalink_text = self.encode(self.permalink_text)
if self.config.html_add_permalinks_html:
self.permalink_text = self.config.html_add_permalinks_html
self.secnumber_suffix = self.config.html_secnumber_suffix
self.param_separator = ''
self.optional_param_level = 0
Expand Down