Skip to content

Conversation

S1M0N38
Copy link

@S1M0N38 S1M0N38 commented Jul 18, 2025

Summary

This PR adds a new llm_friendly_source configuration option that addresses the compatibility issue between mkdocstrings source code rendering and LLM-focused tools like mkdocs-llmstxt.

Problem

When using show_source: true with mkdocstrings-python, the mkdocs-llmstxt plugin generates suboptimal output in llms-full.txt files. Instead of clean, readable Python code blocks, source code gets converted into confusing table format with line numbers and compressed code.

Solution

Added a new boolean configuration option llm_friendly_source that:

  • Removes line numbers from source code displays
  • Uses simple markdown-style code blocks instead of complex HTML tables
  • Maintains backward compatibility (defaults to False)
  • Works alongside existing show_source option

Changes

  • Config: Add llm_friendly_source: bool = False to PythonInputOptions
  • Templates: Update function and class templates to conditionally render LLM-friendly source
  • Documentation: Add comprehensive documentation with usage examples
  • Tests: Add test coverage for both traditional and LLM-friendly rendering
  • Quality: All linting, type checking, and documentation checks pass

Usage

# mkdocs.yml
plugins:
- mkdocstrings:
    handlers:
      python:
        options:
          show_source: true
          llm_friendly_source: true  # New option\!

Before vs After

Before (Traditional - problematic for LLM tools):

<table class="highlighttable">
  <tr><td class="linenos">1</td><td class="code">def function(): ...</td></tr>
</table>

After (LLM-friendly):

<div class="language-python highlight">
  <pre><code class="language-python">def function(): ...</code></pre>
</div>

Test Plan

  • All existing tests pass
  • New test verifies LLM-friendly rendering works
  • Code quality checks pass (Ruff, MyPy)
  • Documentation builds successfully
  • Feature works for both functions and classes

Fixes #299

🤖 Generated with Claude Code

Add a new configuration option `llm_friendly_source` that renders source code
in a format more compatible with LLM-focused tools like mkdocs-llmstxt.

When enabled along with `show_source`, this option:
- Removes line numbers from source code blocks
- Uses simple markdown-style code blocks instead of complex HTML tables
- Improves compatibility with tools that convert documentation to LLM-friendly formats

Changes:
- Add `llm_friendly_source: bool = False` config option in PythonInputOptions
- Update function and class templates to support LLM-friendly rendering
- Add comprehensive documentation with usage examples
- Add tests to verify both traditional and LLM-friendly rendering work correctly

Fixes #299

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@S1M0N38 S1M0N38 marked this pull request as draft July 18, 2025 23:36
@S1M0N38 S1M0N38 closed this Jul 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feature: mkdocs-llmstxt compatibility issue with mkdocstrings show_source

1 participant