sphinx-llms-txt-link ******************** Automatically add a static link to the raw rendered text version (reStructuredText or Markdown format) of every HTML documentation page. **Optimize for LLM Consumption**: * Provides a direct link to the **raw, rendered text markup** for the current page. * Enables developers to quickly copy clean, structured context for feeding into an LLM prompt. [image: PyPI Version][image][image: Supported Python versions][image][image: Build Status][image][image: Documentation Status][image][image: llms.txt - documentation for LLMs][image][image: MIT][image][image: Coverage][image] **TL;DR** sphinx-llms-txt-link is a Sphinx extension that injects a **server- side rendered** link to the *.txt* version of each HTML page, specifically optimized for LLMOps and training consumption. Features ======== * **Server-Side Injection:** Uses the *doctree-resolved* hook to insert a *docutils.nodes.raw* element, ensuring the link is in the static HTML source. * **100% Indexable:** Guarantees visibility for all crawlers (Google, specialized LLM scrapers, RAG indexers). * **Theme Agnostic:** Works reliably across themes (Read the Docs, Alabaster, Furo, etc.) without requiring template overrides. * **Auto-Calculated Relative Path:** Correctly calculates the relative path to the sibling *.txt* file, avoiding common issues with Sphinx's internal link resolution. * **Simple Styling Integration:** Injects a standard CSS class (*sphinx-llms-txt-link*) for easy styling and theme-specific overrides. Prerequisites ============= * Python 3.9+ * Sphinx 6.0+ Your Sphinx documentation must be configured to output *.txt* files (e.g., using *sphinx_markdown_builder* or ensuring the *text* builder runs). Installation ============ pip install sphinx-llms-txt-link Documentation ============= * Documentation is available on the Read the Docs project. * For guidelines on contributing check the Contributor guidelines. Usage example ============= Sphinx configuration -------------------- Essential configuration ~~~~~~~~~~~~~~~~~~~~~~~ Add the extension to your *conf.py*. No other configuration is required. *Filename: docs/conf.py* extensions = [ # ... other extensions "sphinx_llms_txt_link", # ... other extensions ] Custom styling (optional) ~~~~~~~~~~~~~~~~~~~~~~~~~ The extension injects the following minimal HTML structure at the end of the document body:
If you wish to style the link to match your theme (e.g., *Alabaster* or *Read the Docs*), you can create a CSS file (e.g., *_static/custom_sphinx_llms_txt_link.css*) and include it in your *conf.py* settings: *Filename: docs/conf.py* html_css_files = [ "custom_sphinx_llms_txt_link.css", ] Build process ~~~~~~~~~~~~~ Ensure you run the standard HTML build command. If you use a tool like *sphinx-markdown-builder* or a custom extension to generate the *.txt* artifacts, ensure those artifacts exist in the build directory. # Build the .txt files sphinx-build -n -b text docs builddocs # Build the HTML output and inject the link sphinx-build -n -a -b html docs builddocs The link will now appear at the bottom of every generated HTML page, pointing correctly to its *.txt* counterpart. Tests ===== Run the tests with pytest: pytest License ======= MIT Support ======= For security issues contact me at the e-mail given in the Author section. For overall issues, go to GitHub. Author ====== Artur Barseghyan