sphinx_linkfix.extension ======================== .. py:module:: sphinx_linkfix.extension .. autoapi-nested-parse:: Sphinx extension to rewrite internal links in reStructuredText files. Classes ------- .. autoapisummary:: sphinx_linkfix.extension.RstImageRewriter sphinx_linkfix.extension.RstLinkRewriter Functions --------- .. autoapisummary:: sphinx_linkfix.extension._is_external sphinx_linkfix.extension._strip_docs_prefix sphinx_linkfix.extension.setup Module Contents --------------- .. py:class:: RstImageRewriter(document, startnode=None) Bases: :py:obj:`sphinx.transforms.SphinxTransform` Transform to rewrite image paths early in the process. .. py:method:: apply() -> None Rewrite image paths in the document. .. py:attribute:: default_priority :value: 210 Numerical priority of this transform, 0 through 999 (override). .. py:class:: RstLinkRewriter(document, startnode=None) Bases: :py:obj:`sphinx.transforms.post_transforms.SphinxPostTransform` Post-transform to rewrite internal links in reStructuredText files. .. py:method:: _process_references(docs_relative_path: str, exts: tuple[str, Ellipsis]) -> int Process and rewrite reference nodes. .. py:method:: _sanitize_fragment_for_latex(fragment: str) -> str Sanitize a fragment for LaTeX compatibility. :param fragment: The fragment to sanitize. :type fragment: str :returns: The sanitized fragment. :rtype: str .. py:method:: run() -> None Rewrite internal links in the document. .. py:attribute:: default_priority :value: 999 Numerical priority of this transform, 0 through 999 (override). .. py:function:: _is_external(href: str) -> bool Check if a given href is an external link. :param href: The URL to check. :type href: str :returns: True if the URL is external, False otherwise. :rtype: bool .. py:function:: _strip_docs_prefix(path_str: str, docs_relative_path: str) -> str Remove the leading docs folder prefix from a path string. This function handles both relative and absolute paths and normalizes different prefix formats: - Prefix "docs", "docs/", "/docs", "/docs/" all work consistently - For relative paths like "docs/something", it removes the docs prefix - For absolute paths like "/docs/something", it removes the docs prefix :param path_str: The path string to modify. :type path_str: str :param docs_relative_path: The prefix to remove (can be in various formats). :type docs_relative_path: str :returns: The modified path string with the prefix removed. :rtype: str .. py:function:: setup(app: Any) -> dict[str, str | bool] Set up the Sphinx extension. :param app: The Sphinx application object. :type app: Any :returns: A dictionary with extension metadata. :rtype: dict[str, str | bool]