feat: Add llm_friendly_source option for LLM-compatible source rendering
## 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
```yaml
# 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):**
```html
<table class="highlighttable">
<tr><td class="linenos">1</td><td class="code">def function(): ...</td></tr>
</table>
```
**After (LLM-friendly):**
```html
<div class="language-python highlight">
<pre><code class="language-python">def function(): ...</code></pre>
</div>
```
## Test Plan
- [x] All existing tests pass
- [x] New test verifies LLM-friendly rendering works
- [x] Code quality checks pass (Ruff, MyPy)
- [x] Documentation builds successfully
- [x] Feature works for both functions and classes
Fixes #299
🤖 Generated with [Claude Code](https://claude.ai/code)
合并状态:未合并 关闭于 2025-07-19 0 条评论