Skip to main content

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

Project description

Python Version License

Render your links both in GitHub and in the built documentation seamlessly!

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

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.

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.

Before Building Documentation

Documentation before applying sphinx-linkfix

After Building Documentation

Documentation after applying sphinx-linkfix

Links working both on GitHub and Sphinx

Links working on GitHub Links working in Sphinx

Images working both on GitHub and Sphinx

Images working in GitHub Images working in Sphinx

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
# If the file you are referencing lives in the docs/ directory of your project,
# when the link is processed it should point to the root of the docs/ directory,
# thus, we strip the 'docs/' prefix from the link.
# E.g., `Reference </docs/REFERENCE.rst>`_ becomes href="REFERENCE.html"
docs_relative_path = 'docs/'

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

  2. If the referenced files live in the root directory of the project, make sure to include a file with the same name in the docs folder, referencing 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.2.0.tar.gz (3.7 MB 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.2.0-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for sphinx_linkfix-0.2.0.tar.gz
Algorithm Hash digest
SHA256 6c2c330bed9adf891ac09707760a3b3c5936f1138c4311105a56ab00c5e8394f
MD5 bde61a7d1eb355aa6e8f527f656e3d39
BLAKE2b-256 2ddc9c58b5a165c767cbf0fa58305aa51093854658647bf08885e13d6b29f13b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sphinx_linkfix-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.7 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 23c4f56508eb02a48981208cf0093045389dd2939ef1c2747bd545d8ed7c62e1
MD5 dd86dfe0a8508df5010247370ef15f2b
BLAKE2b-256 3038796d118ca609c4d616e855d8215e260d11f55ea1e1c2d707b73ff5720c5f

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