Skip to content

Commit 515706f

Browse files
committed
Better link style for documentation index
1 parent 56f1a85 commit 515706f

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

docs/src/conf.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
plot_html_show_formats = False
5757
plot_html_show_source_link = False
5858

59+
html_static_path = ['static']
5960

6061
def setup(app) -> None:
6162
app.add_object_type(
@@ -64,3 +65,8 @@ def setup(app) -> None:
6465
objname="configuration value",
6566
indextemplate="pair: %s; configuration value",
6667
)
68+
app.connect('html-page-context', html_page_context_handler)
69+
70+
def html_page_context_handler(app, pagename, templatename, context, doctree):
71+
if pagename == 'index':
72+
app.add_css_file('custom.css')

docs/src/index.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. _index:
2+
13
sphinx-codeautolink
24
===================
35
|license|
@@ -16,6 +18,9 @@ Click any names in the example below for a demonstration:
1618
print(knight.taunt())
1719
knight.scratch()
1820
21+
The link styles in this document have been modified to be obvious.
22+
The rest of this documentation uses the more subtle default style.
23+
1924
A directive to create a table of references from code examples to a single
2025
definition is also provided, which can also be integrated with autodoc entries.
2126
For example, :code:`.. autolink-examples:: lib.Knight` produces:

docs/src/reference.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,19 @@ Directives
141141
CSS class
142142
---------
143143
The CSS class used in all code block links is ``sphinx-codeautolink-a``.
144+
An example of more obvious links is on the :ref:`landing page <index>`.
145+
The styles can be configured for all pages by defining ``html_static_path``
146+
and ``html_css_files`` to include in the documentation.
147+
To include only in specific documents, see the ``html-page-context`` event
148+
and the :meth:`Sphinx.add_css_file` function.
149+
150+
.. code:: css
151+
152+
.sphinx-codeautolink-a{
153+
border-bottom-color: #aaa;
154+
border-bottom-style: dotted;
155+
border-bottom-width: 2px;
156+
}
144157
145158
Cleanup functions
146159
-----------------

docs/src/static/custom.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.sphinx-codeautolink-a{
2+
color: unset;
3+
border-bottom-color: #aaa;
4+
border-bottom-style: dotted;
5+
border-bottom-width: 2px;
6+
}

0 commit comments

Comments
 (0)