Skip to content

Commit f8570a9

Browse files
committed
f
1 parent d1b99e5 commit f8570a9

File tree

7 files changed

+17
-37
lines changed

7 files changed

+17
-37
lines changed

docs/src/conf.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
plot_html_show_source_link = False
5858

5959
html_static_path = ["static"]
60+
html_css_files = ["custom.css"]
6061

6162

6263
def setup(app) -> None:
@@ -66,9 +67,3 @@ def setup(app) -> None:
6667
objname="configuration value",
6768
indextemplate="pair: %s; configuration value",
6869
)
69-
app.connect("html-page-context", html_page_context_handler)
70-
71-
72-
def html_page_context_handler(app, pagename, templatename, context, doctree):
73-
if pagename == "index":
74-
app.add_css_file("custom.css")

docs/src/examples.rst

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,24 +300,29 @@ 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 dotted lines 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);
325+
border-bottom-color: #aaa;
321326
border-bottom-style: dotted;
322327
border-bottom-width: 1px;
323328
}

docs/src/index.rst

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
.. _index:
2-
31
sphinx-codeautolink
42
===================
53
|license|
@@ -18,9 +16,6 @@ Click any names in the example below for a demonstration:
1816
print(knight.taunt())
1917
knight.scratch()
2018
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-
2419
A directive to create a table of references from code examples to a single
2520
definition is also provided, which can also be integrated with autodoc entries.
2621
For example, :code:`.. autolink-examples:: lib.Knight` produces:
@@ -61,8 +56,8 @@ Note that the extension name uses an underscore rather than a hyphen.
6156
]
6257
6358
That's it! Now your code examples are linked.
64-
For ways of concatenating multiple examples
65-
and setting default import statements among other things,
59+
For ways of concatenating examples, setting default import statements,
60+
or customising link style among other things,
6661
have a look at the :ref:`reference` documentation.
6762

6863
sphinx-codeautolink elsewhere:

docs/src/reference.rst

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -141,19 +141,9 @@ 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-
}
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.
157147

158148
Cleanup functions
159149
-----------------

docs/src/release_notes.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ sphinx-codeautolink adheres to
1919
and ``highlight_language`` configuration (:issue:`166`)
2020
- Add :confval:`codeautolink_warn_on_default_parse_fail` to warn about
2121
failing to link code blocks without a language parameter (:issue:`166`)
22-
- Improve default link style to unset colors and use an underline (:issue:`171`)
2322

2423
0.16.2 (2025-01-16)
2524
-------------------

docs/src/static/custom.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
.sphinx-codeautolink-a{
2-
color: unset;
32
border-bottom-color: #aaa;
43
border-bottom-style: dotted;
54
border-bottom-width: 1px;

src/sphinx_codeautolink/static/sphinx-codeautolink.css

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
.sphinx-codeautolink-a{
2-
color: unset;
2+
color: inherit;
33
text-decoration: none;
4-
border-bottom-color: #aaa;
5-
border-bottom-style: dotted;
6-
border-bottom-width: 1px;
74
}
85
.sphinx-codeautolink-a:link{
9-
color: unset;
6+
color: inherit;
107
}
118
.sphinx-codeautolink-a:visited{
12-
color: unset;
9+
color: inherit;
1310
}
1411
.sphinx-codeautolink-a:hover{
1512
color: rgb(0, 139, 139);

0 commit comments

Comments
 (0)