Skip to main content

Sphinx extension that rewrites GitHub-style links into proper Sphinx references.

Project description

Python Version License

Sphinx extension that rewrites GitHub-style links into proper Sphinx references.

🎯 Project Description

I like to have links in the README that point to other sections of the documentation, so you can navigate the docs easily from the GitHub repo itself. However, Sphinx does not understand GitHub-style links (e.g., `reference <docs/reference.rst>`_), so links break when building the docs. If you write links using Sphinx syntax instead, they work in the built docs but not on GitHub.

This extension solves this problem by rewriting GitHub-style links into proper Sphinx references during the Sphinx build process. It scans the document for links that point to local files and rewrites them to use Sphinx’s internal referencing system.

You can combine this with a script to removes all of the links in the README during CI before publishing to pypi, so that the README on PyPI does not contain broken links, and keep a single README file for GitHub, Sphinx and PyPI.

🚀 Key Features

  • Transform GitHub-style links: Automatically rewrite links in the documentation to use Sphinx’s internal referencing system.

  • Ignores external links: Only processes local file links, leaving external URLs untouched.

  • Configurable prefixes: Specify path prefixes to strip from links for cleaner references.

  • Support for multiple file extensions: Configure which file extensions to process (e.g., .rst, .md).

  • Easy integration: Simple setup and configuration in conf.py.

🚀 Quick Start Guide

  1. Install the extension using pip:

pip install sphinx-linkfix
  1. Add the extension to your Sphinx conf.py file:

extensions = [
    ...,
    'sphinx_linkfix',
]
  1. (Optional) Configure the extension in conf.py:

# List of path prefixes to strip from links
sphinx_linkfix_strip_prefixes = ('docs/', 'source/')

# List of file extensions to process
sphinx_linkfix_file_extensions = ('.rst', '.md')
  1. Write links in your documentation using GitHub-style syntax, e.g., `Reference <REFERENCE.rst>`_. (You can use the repository README.rst as an examples)

  2. Create files in your sphinx directory with the same names that you used in the links, that include the original file. E.g., docs/REFERENCE.rst with

.. include:: ../REFERENCE.rst
  1. During the Sphinx build process, the extension scans the documents for links that point to local files and rewrites them to use Sphinx’s internal referencing system.

📚 Documentation

Essential Guides:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sphinx_linkfix-0.1.3.tar.gz (40.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sphinx_linkfix-0.1.3-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file sphinx_linkfix-0.1.3.tar.gz.

File metadata

  • Download URL: sphinx_linkfix-0.1.3.tar.gz
  • Upload date:
  • Size: 40.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.23

File hashes

Hashes for sphinx_linkfix-0.1.3.tar.gz
Algorithm Hash digest
SHA256 c5ced1765ad3ea5fe94c74d5b0d254a7fe658d2f35098d6c1a523bdbda78f43d
MD5 2fc0bd1fde68a9cb51dd50ed599d9bea
BLAKE2b-256 309d7879bdd0008cb3ef31f51e9529b475714fd2ef86ae685c5e144790046fbf

See more details on using hashes here.

File details

Details for the file sphinx_linkfix-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: sphinx_linkfix-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.23

File hashes

Hashes for sphinx_linkfix-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4462d461d624059040b6f261eb4e3ac73cc4dae6a18fbf7d2528f90f9200764b
MD5 f82bf1734fe3abc5f62097b77e7698b6
BLAKE2b-256 c18ab2d939632c2146f868539e210052eb308a3d62bd51358d42e25c000bc299

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page