The formatter module converts crawled page data into the llms.txt markdown format. It handles URL cleaning, markdown file detection, content organization by sections, and automatic tagging.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Anwitht21/llmstxt/llms.txt
Use this file to discover all available pages before exploring further.
Overview
The formatter takes a list ofPageInfo objects and generates a structured markdown file following the llms.txt specification:
- Site title and summary from homepage
- Pages organized by URL path sections
- Optional markdown file linking (
.mdvariants) - Automatic content tagging
- Primary/secondary content separation
Core Functions
format_llms_txt()
Generates the complete llms.txt formatted output.The base URL of the crawled site
List of crawled pages (first page should be homepage)
Optional mapping from HTML URLs to markdown URLs
Formatted llms.txt content as a string
URL Processing
clean_url()
Removes query parameters and fragments from URLs.URL to clean
URL with only scheme, netloc, and path
get_md_url()
Converts an HTML URL to its potential markdown equivalent.Original URL
Converted markdown URL path
page.html→page.html.md/docs/→/docs/index.html.md/about→/about.md
check_md_exists()
Checks if a markdown version of a URL exists.URL to check
Request timeout in seconds
True if markdown version returns 200
get_md_url_map()
Builds a mapping of HTML to markdown URLs for all pages.List of pages to check
Mapping from clean HTML URLs to markdown URLs (or original if no .md found)
- Sends HEAD requests concurrently for all pages
- Checks for markdown content types
- Falls back to original URL if no markdown exists
- Uses asyncio.gather for parallel requests
Text Processing
truncate()
Truncates text to specified length with ellipsis.Text to truncate
Maximum character length
Text truncated with ”…” if exceeded length, otherwise original
get_site_title()
Extracts site title from homepage, with fallback to domain name.Homepage page info
Site base URL
Site title (max 80 chars)
- Uses homepage title if meaningful
- Falls back to cleaned domain name for generic titles (“Home”, “Welcome”, “Index”)
- Truncated to 80 characters
get_summary()
Extracts site summary from homepage.Homepage page info
Site summary (max 200 chars)
- Homepage description
- Homepage snippet
- “No description available”
Section Processing
clean_section_name()
Cleanlifies section names for display.Raw section name from URL path
Capitalized, human-readable section name
- Replaces hyphens and underscores with spaces
- Capitalizes words
- Uppercases known abbreviations (API, REST, GraphQL, SDK, CLI, UI, UX, FAQ, RSS)
- Defaults to “Main” for empty names
is_secondary_section()
Determines if a section is secondary/optional content.Section name to check
True if section matches secondary patterns
- Legal: privacy, terms, legal, cookie, disclaimer
- Meta: sitemap, changelog, release
- Community: contributing, code-of-conduct, governance, license
- Company: about, team, career, job, contact, company
- Social: twitter, github, linkedin, facebook, social
- Archive: archive, old, legacy, deprecated
Usage Examples
Basic Formatting
With Markdown URL Mapping
Section Organization
Content Tagging
The formatter integrates with thetagger module:
Related Modules
- crawler - Provides
PageInfoobjects - tagger - Assigns and formats content tags
- storage - Saves formatted output to R2