Skip to main content

Converting Sitemaps and Raw HTML into Token-Efficient llms-full.txt Context Files

How to prune React/Tailwind DOM boilerplate, convert HTML tables and code blocks to GFM Markdown, and profile context budgets across GPT-4o, Claude 3.7, and DeepSeek R1.

Updated 3 min readMarkdown
Part of seriesKivaroTools: Browser Engineering & Client-Side Architecture

When developers paste a documentation URL into Cursor (@Docs), Claude Code, or a custom Retrieval-Augmented Generation (RAG) pipeline, feeding raw HTML into the context window is extraordinarily wasteful.

A typical documentation page rendered by Docusaurus, Nextra, or Mintlify contains:

  • 120 KB of hydrated React/Next.js <script> payloads and inline JSON state
  • 45 KB of SVG icon paths, top navigation bars, sidebar trees, and footer links
  • Only 12 KB of actual technical prose, tables, and code blocks

If an LLM ingests 20 pages of raw HTML, it burns through a 200,000-token context window mostly reading className="flex items-center justify-between" instead of your API documentation.

Here is how to build a deterministic, in-browser HTML-to-Clean-Markdown compiler and LLM Token Budget Profiler to produce llms.txt, llms-full.txt, and llms-ctx.txt deliverables.


1. Stripping Non-Content DOM Subtrees Before Markdown Serialization

Converting HTML to Markdown for LLM ingestion requires aggressive semantic pruning before converting tags:

  1. Prune Chrome &Executable Nodes: Strip <script>, <style>, <noscript>, <svg>, <canvas>, <iframe>, <nav>, <header>, <footer>, <aside>, and elements matching [role="navigation"], [aria-hidden="true"], or cookie/ad container classes.
  2. Preserve Semantic Structure & Code Blocks:
    • Convert <h1>–<h6> into ATX # headings.
    • Extract <pre><code class="language-ts"> blocks into fenced Markdown code blocks (```ts ... ```) with HTML entity decoding (&lt; \(\rightarrow\) <, &amp; \(\rightarrow\) &).
    • Convert <table><thead><tbody> grids into pipe-delimited GitHub Flavored Markdown (GFM) tables so LLMs preserve row-column relationships.

2. Profiling Context Window Utilization Across 5 Frontier Models

Once your pages are compiled into /llms.txt (the lightweight directory index) and /llms-full.txt (the full corpus), you need to know whether /llms-full.txt fits inside a single model prompt without truncation.

By estimating BPE token counts across code and prose segments, you can map exact context window utilization against current frontier models:

  • DeepSeek R1 / V3: 64,000 token context window
  • Perplexity Sonar: 127,000 token context window
  • OpenAI GPT-4o / o3: 128,000 token context window
  • Anthropic Claude 3.7 Sonnet: 200,000 token context window
  • Google Gemini 2.5 Pro: 1,000,000 token context window

If your llms-full.txt exceeds 64k tokens, generating a middle-tier llms-ctx.txt (which excludes links marked under ## Optional such as legal policies, changelogs, and legacy v1 docs) keeps the context bundle compact enough to fit inside every major model's single-shot window.

You can test this HTML-to-Markdown compiler, 5,000-URL sitemap.xml parser, and multi-model token budget profiler locally in your browser using the KivaroTools llms.txt & AI Crawler robots.txt Studio.

About the author

  • Founder & Lead Software Architect @ KivaroTools | BS Computer Science | Full-Stack & Systems Engineer (TypeScript, Next.js, Python, Java, C++, WebAssembly) | Privacy-First Web & Financial Engines

No comments yet. Be the first to comment.

KivaroTools: Browser Engineering & Client-Side Architecture

Part 5 of 5

A technical series exploring the engineering behind KivaroTools, including browser-based file processing, JavaScript and TypeScript architecture, memory management, application security, data parsing, performance optimization, and financial computation. Each article shares practical implementation insights, engineering decisions, testing approaches, and lessons learned while building reliable web utilities.

Start from the beginningEngineering Browser-Based Utilities: A Deep Dive into KivaroToolsThe engineering behind binary processing, memory management, application security, parsing, and financial calculations in a modern web utility platform.

More from this blog