-
-
Notifications
You must be signed in to change notification settings - Fork 7
Description
Problem Description
When generating llms.txt
or llms-full.txt
files, markdown tables are incorrectly formatted as single lines instead of preserving their tabular structure. This makes tables unreadable in the generated output.
Expected Output
| Code | Category | Error |
| ------ | ---------- | ------------------------------------------ |
| `E002` | Protocol | Message missing required 'arguments' field |
| `E004` | Protocol | Unknown function |
| `E006` | Network | Socket bind failed |
Actual Output
| Code | Category | Error | | --- | --- | --- | | `E001` | Protocol | Invalid JSON in request | | `E002` | Protocol | Message missing required 'arguments' field | | `E004` | Protocol | Unknown function | | `E006` | Network | Socket creation failed |
Root Cause
The issue is located in src/mkdocs_llmstxt/_internal/plugin.py
at line 240:
return mdformat.text(_converter.convert_soup(soup), options={"wrap": "no"})
The options={"wrap": "no"}
parameter causes mdformat to remove newlines between table rows, collapsing them into a single line.
Technical Analysis
I tested this with a simple reproduction:
import mdformat
from markdownify import MarkdownConverter
html_table = '''
<table>
<tr><th>Code</th><th>Category</th><th>Error</th></tr>
<tr><td>E002</td><td>Protocol</td><td>Message missing required field</td></tr>
<tr><td>E004</td><td>Protocol</td><td>Unknown function</td></tr>
</table>
'''
converter = MarkdownConverter()
markdown = converter.convert(html_table)
# With wrap="no" - BROKEN
formatted_nowrap = mdformat.text(markdown, options={'wrap': 'no'})
# Result: '| Code | Category | Error | | --- | --- | --- | | E002 | Protocol | Message missing required field | | E004 | Protocol | Unknown function |\n'
# With default options - WORKS
formatted_default = mdformat.text(markdown)
# Result: '| Code | Category | Error |\n| --- | --- | --- |\n| E002 | Protocol | Message missing required field |\n| E004 | Protocol | Unknown function |\n'
Solution
Remove the wrap: "no"
option from the mdformat call:
# Before
return mdformat.text(_converter.convert_soup(soup), options={"wrap": "no"})
# After
return mdformat.text(_converter.convert_soup(soup))
This preserves table structure while still benefiting from mdformat's other formatting capabilities.
Impact
This bug affects any documentation site using this plugin that contains markdown tables, making the generated LLM-friendly content less useful since tables become unreadable.
Environment
- mkdocs-llmstxt: latest
- Python: 3.x
- Dependencies: markdownify, mdformat, BeautifulSoup4