sphinx_linkfix.extension

Sphinx extension to rewrite internal links in reStructuredText files.

Classes

RstLinkRewriter

Post- transform to rewrite internal links in reStructuredText files.

Functions

_is_external(→ bool)

Check if a given href is an external link.

_strip_prefixes(→ str)

Remove leading folder prefixes from a path string.

setup(→ dict[str, str | bool])

Set up the Sphinx extension.

Module Contents

class sphinx_linkfix.extension.RstLinkRewriter(document, startnode=None)[source]

Bases: sphinx.transforms.post_transforms.SphinxPostTransform

Post- transform to rewrite internal links in reStructuredText files.

_sanitize_fragment_for_latex(fragment: str) str[source]

Sanitize a fragment for LaTeX compatibility.

Parameters:

fragment (str) – The fragment to sanitize.

Returns:

The sanitized fragment.

Return type:

str

run() None[source]

Rewrite internal links in the document.

default_priority = 999

Numerical priority of this transform, 0 through 999 (override).

sphinx_linkfix.extension._is_external(href: str) bool[source]

Check if a given href is an external link.

Parameters:

href (str) – The URL to check.

Returns:

True if the URL is external, False otherwise.

Return type:

bool

sphinx_linkfix.extension._strip_prefixes(path_str: str, prefixes: tuple[str, Ellipsis]) str[source]

Remove leading folder prefixes from a path string.

Parameters:
  • path_str (str) – The path string to modify.

  • prefixes (tuple[str, ...]) – A tuple of prefixes to remove.

Returns:

The modified path string with the prefixes removed.

Return type:

str

sphinx_linkfix.extension.setup(app: Any) dict[str, str | bool][source]

Set up the Sphinx extension.

Parameters:

app (Any) – The Sphinx application object.

Returns:

A dictionary with extension metadata.

Return type:

dict[str, str | bool]