Skip to content

Commit e6279a0

Browse files
authored
Better default link style & highlighted examples (#171)
1 parent 56f1a85 commit e6279a0

File tree

9 files changed

+32
-21
lines changed

9 files changed

+32
-21
lines changed

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
graft docs
22
prune docs/build
33
graft requirements
4+
graft src
45
graft tests
56
include contributing.rst readme_pypi.rst tox.ini
67
global-exclude *.py[cod] __pycache__ *.so

docs/src/conf.py

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

59+
html_static_path = ["static"]
60+
html_css_files = ["custom.css"]
61+
5962

6063
def setup(app) -> None:
6164
app.add_object_type(

docs/src/examples.rst

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,25 +300,30 @@ For example, a transformer could be implemented as follows:
300300
Sometimes links with third-party code blocks are broken.
301301
See :ref:`about` for a potential solution.
302302

303+
.. _examples-css:
304+
303305
Custom link styles
304306
------------------
305307
If you want a specific style to be applied to code block links,
306308
you may add your own CSS file to the Sphinx build.
307-
All code block links use the ``sphinx-codeautolink-a`` class.
308-
For example, you can add dotted lines to all links and change the hover colour:
309309

310310
.. code:: python
311311
312312
# conf.py
313313
html_static_path = ['static']
314314
html_css_files = ['custom.css']
315315
316+
To include only in specific documents, see the ``html-page-context`` event
317+
and the :meth:`Sphinx.add_css_file` function.
318+
For example, you can add similar underlines as this documentation
319+
and change the hover colour:
320+
316321
.. code:: css
317322
318323
/* static/custom.css */
319324
.sphinx-codeautolink-a{
320-
border-bottom-color: rgb(0, 0, 0);
321-
border-bottom-style: dotted;
325+
border-bottom-color: #ccc;
326+
border-bottom-style: solid;
322327
border-bottom-width: 1px;
323328
}
324329
.sphinx-codeautolink-a:hover{

docs/src/index.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ sphinx-codeautolink
55
sphinx-codeautolink makes code examples clickable by inserting links
66
from individual code elements to the corresponding reference documentation.
77
We aim for a minimal setup assuming your examples are already valid Python.
8-
Click any names in the example below for a demonstration:
8+
Click any undelined name in the example below for a demonstration:
99

1010
.. code:: python
1111
@@ -42,7 +42,6 @@ sphinx-codeautolink can be installed from the following sources:
4242
.. code:: sh
4343
4444
$ pip install sphinx-codeautolink
45-
# or, alternatively:
4645
$ conda install -c conda-forge sphinx-codeautolink
4746
4847
To enable sphinx-codeautolink, modify the extension list in ``conf.py``.
@@ -56,8 +55,8 @@ Note that the extension name uses an underscore rather than a hyphen.
5655
]
5756
5857
That's it! Now your code examples are linked.
59-
For ways of concatenating multiple examples
60-
and setting default import statements among other things,
58+
For ways of concatenating examples, setting default import statements,
59+
or customising link style among other things,
6160
have a look at the :ref:`reference` documentation.
6261

6362
sphinx-codeautolink elsewhere:

docs/src/reference.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ Directives
141141
CSS class
142142
---------
143143
The CSS class used in all code block links is ``sphinx-codeautolink-a``.
144+
By default, the links only have a light blue hover colour.
145+
The style has been made more obvious in the documentation for demonstration.
146+
See :ref:`examples-css` for more information.
144147

145148
Cleanup functions
146149
-----------------

docs/src/static/custom.css

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

readme.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ sphinx-codeautolink can be installed from the following sources:
2424
.. code:: sh
2525
2626
$ pip install sphinx-codeautolink
27-
# or, alternatively:
2827
$ conda install -c conda-forge sphinx-codeautolink
2928
3029
To enable sphinx-codeautolink, modify the extension list in ``conf.py``.
@@ -38,9 +37,9 @@ Note that the extension name uses an underscore rather than a hyphen.
3837
]
3938
4039
That's it! Now your code examples are linked.
41-
For ways of concatenating multiple examples
42-
and setting default import statements among other things,
43-
have a look at the online documentation.
40+
For ways of concatenating examples, setting default import statements,
41+
or customising link style among other things,
42+
see the `online documentation <https://sphinx-codeautolink.rtfd.org>`_.
4443

4544
.. |pypi| image:: https://img.shields.io/pypi/v/sphinx-codeautolink.svg
4645
:target: https://pypi.org/project/sphinx-codeautolink

readme_pypi.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ sphinx-codeautolink can be installed from the following sources:
1616
.. code:: sh
1717
1818
$ pip install sphinx-codeautolink
19-
# or, alternatively:
2019
$ conda install -c conda-forge sphinx-codeautolink
2120
2221
Note that the library is in early development, so version pinning is advised.
@@ -31,9 +30,9 @@ Note that the extension name uses an underscore rather than a hyphen.
3130
]
3231
3332
That's it! Now your code examples are linked.
34-
For ways of concatenating multiple examples
35-
and setting default import statements among other things,
36-
have a look at the online documentation.
33+
For ways of concatenating examples, setting default import statements,
34+
or customising link style among other things,
35+
see the `online documentation <https://sphinx-codeautolink.rtfd.org>`_.
3736

3837
.. |pyversions| image:: https://img.shields.io/pypi/pyversions/sphinx-codeautolink
3938
:alt: Python versions
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
.sphinx-codeautolink-a:link{
1+
.sphinx-codeautolink-a{
22
color: inherit;
33
text-decoration: none;
44
}
5-
.sphinx-codeautolink-a:active{
5+
.sphinx-codeautolink-a:link{
66
color: inherit;
7-
text-decoration: none;
87
}
98
.sphinx-codeautolink-a:visited{
109
color: inherit;
11-
text-decoration: none;
1210
}
1311
.sphinx-codeautolink-a:hover{
1412
color: rgb(0, 139, 139);
15-
text-decoration: none;
1613
}

0 commit comments

Comments
 (0)