Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I keep all my external links in a separate file with Sphinx?

I have a Sphinx project with a collection of files that contain external links as references at the bottom of each file like this:

Some text with `my link`_, more text
100 lines of text ...

.. _my link: http://example.com

I'd like to reorganize my files, splitting them, merging them and reusing external links. To make this easier, I'd like to keep my links in a separate file, each one with a unique id that I can reference in the text. Is there a way to do this? The rendered output should still create an external link, not a footnote like it was suggested in How do I collect all external links in Sphinx?

like image 779
chiborg Avatar asked Oct 20 '25 07:10

chiborg


1 Answers

This can be solved with the right settings in conf.py:

# Exclude link file
exclude_patterns = ['_build', 'links.rst']

# make rst_epilog a variable, so you can add other epilog parts to it
rst_epilog =""
# Read link all targets from file
with open('links.rst') as f:
     rst_epilog += f.read()

links.rst looks like this:

.. _my link: http://example.com
.. _my other link: http://example2.com

With this setup, I'm flexible to use either the unique ID as the link label or provide a custom link label:

Some text with `my link`_ and a `custom label<my other link>`_
like image 94
chiborg Avatar answered Oct 22 '25 04:10

chiborg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!