Blog

Converting agent HTML to Markdown for an LLM: what survives, what breaks, and the limits I set

On this page
  1. If you need to convert a file right now
  2. What I tested
  3. Results at a glance
  4. What survives
    1. Headings, paragraphs, lists and code
    2. Simple tables
  5. What breaks
    1. pre without code
    2. Tables that aren't simple
    3. Charts
    4. Forms
    5. Meaning carried by style
    6. Images
    7. Embeds
  6. Links: the part I'd get right first
  7. The limits I set in Factrove's converter
  8. Where Factrove fits

Short answer: headings, paragraphs, nested lists, code blocks and simple tables come through fine. Chart data often doesn't. An SVG can leak labels with no values, and a canvas only contributes its fallback text, while a caption survives. Form state and embeds disappear in the post 01 script. v2 keeps values and checkbox selections serialized in the saved HTML, and turns a safe iframe into a link. Colors and complicated tables still break, mostly without any warning. And whether a javascript: link survives depends on whether your converter checks schemes with an allowlist or a denylist. If you convert one thing today, make it the link check, then put the important numbers in text.

I ran twelve small test inputs through three converters and kept every output. All of it is in the test files, so you can check me.

If you need to convert a file right now

Use the updated script, to-md-v2.mjs. It's the one from HTML for humans, Markdown for agents with the fixes from this test:

bash
npm i turndown@7.2.4 turndown-plugin-gfm@1.0.2
node to-md-v2.mjs plans/plan.html > /tmp/plan.md

Then read the Markdown before you hand it to the agent, and check three things:

  1. Every number the reader is meant to act on is in the text. Search for one from each chart.
  2. Tables still have the same number of columns in every row.
  3. Every link is https://, http://, mailto:, a root-relative path or an in-page # anchor. v2 also keeps a target that starts with //. That is a protocol-relative external URL, so don't treat it as root-relative.
text
Read /tmp/plan.md, generated from plans/plan.html.
If a needed document or image is missing, inspect the original HTML and use
its directory to locate the target. List missing context before editing.

What I tested

Twelve inputs, one per problem area: tables, nested lists, code blocks, SVG and canvas charts, details/summary, callouts, forms, inline styles, images, iframes and embeds, unsafe links, and text that looks like Markdown. They're small and made up, written the way agent HTML tends to look.

Three converters, all run on the box I write on with Node.js 20.19.2:

  • Turndown, post 01 script. to-md.mjs from the first post: Turndown 7.2.4 with turndown-plugin-gfm 1.0.2, plus a rule that drops javascript: and data: links.
  • Turndown, v2. The same script with an allowlist for link and image URLs and a few extra rules, described below.
  • Factrove's converter. The HTML to Markdown converter I built for Factrove: a parse5 7.3.0 tree walk that writes Markdown directly, running in a worker with limits. It's in Factrove's private repo at commit ee19eb0 and isn't released. I compiled it with TypeScript 5.9.3 and ran it through its worker wrapper, the same path Factrove's unreleased API uses. The converter isn't in this repository, so the factrove/ files are saved output you can inspect, not something you can reproduce from here.

Results at a glance

Case Turndown (post 01 script) Turndown v2 (recommended) Factrove converter
Simple table Survives Survives Survives
Table with colspan, a pipe in a cell, a list in a cell Breaks: colspan lost, pipe splits a cell, values shift a column Breaks: colspan lost, pipe splits a cell, values shift a column Survives, except list items run together
Table with no header row Left as raw HTML Left as raw HTML Converted, first row used as header
Nested lists, code inside a list item Survives Survives Survives
Code block containing triple backticks Survives Survives Survives
pre without code Becomes a plain paragraph Becomes a plain paragraph Fenced
SVG chart Stray axis labels: Today100% reads Dropped; captions still survive Dropped entirely
Canvas with fallback text, figcaption Text survives Text survives Text survives
details/summary Text survives, collapse lost Text survives; summary becomes bold; collapse lost Text survives, collapse lost
Callout div Text and bold survive, "warning" class lost Text and bold survive, "warning" class lost Same
Form One run-on line, checkbox state lost Serialized values, checkbox selections and selected option retained One run-on line, checkbox state lost
Strikethrough ~old plan~ ~old plan~ Plain text: "old plan"
Color, highlight, display:none Color and highlight lost, hidden text kept Color and highlight lost, hidden text kept Same
data: image Kept, base64 and all URL dropped; alt text kept Dropped, alt text kept
iframe Dropped silently Allowed URL becomes a link Dropped silently
javascript:, data: links Dropped Dropped Dropped
vbscript: link, tab inside javascript: Kept as links in the Markdown URL dropped; text kept Dropped
Escaped &lt;div&gt; in text Comes back as a raw <div> Comes back as a raw <div> Stays escaped

In the details case, v2 also bolds the <summary> text.

What survives

Headings, paragraphs, lists and code

All three converters handled a three-level nested list with a code block inside a list item. This is the saved Factrove output:

markdown
1. Prepare
   - Add the table
   - Add the index
     1. on `expires_at`
     2. on `user_id`
2. Dual-write

   Second paragraph inside the same step.

   ```
   pnpm test src/auth
   ```
3. Flip reads

None of the three kept the second list's start number. The input is <ol start="7">, and the Markdown renders as step 4. The verbatim lines are in the post 01 output, the v2 output and the saved Factrove output.

Language hints on <code class="language-ts"> carried through as a ts label on the fence in all three.

Simple tables

A table with a header row and plain cells came through cleanly in all three. That covers most of what agents put in plans.

What breaks

pre without code

I expected a code block containing a triple-backtick fence to break, and it didn't. Turndown already uses a longer fence when a line inside the code starts with backticks, and backticks in the middle of a line can't close a fence. The real difference was a <pre> with no <code>: Turndown turned it into a normal paragraph and lost the indentation, and Factrove's converter fenced it. The outputs are in the post 01 script file and the saved Factrove file. v2 does the same as the post 01 script here.

Tables that aren't simple

This row has a colspan="2" cell, and the next cell has a | in the text. The post 01 script output still has three cells:

markdown
| Hybrid (both, for now) | Uses a | pipe in the text |

The colspan is gone, the unescaped pipe splits the cell, so "Uses a" lands under Cost, and the list in the last cell breaks the row across lines. A table with no <thead> stayed as raw HTML. Factrove's converter escaped the pipe and padded the colspan with an empty cell, but joined the list items with nothing between them: vendor lock-innew bill.

The Postgres cell is Needs a cleanup job<br>and an index. Both Turndown scripts turn that <br> into a line break, and markdown-it then renders "and an index" as its own row. v2, the script I'd use right now, still does this. The verbatim lines are in the post 01 output and the v2 output. The saved Factrove output joins the two parts with a space: Needs a cleanup job and an index.

If a table cell needs a list, the HTML is already too clever for Markdown. I'd ask the agent for a plain table plus notes underneath.

Charts

This is the same failure as in post 01. All three lost the SVG <title> and aria-label. The post 01 script leaked the axis labels as Today100% reads, which is noise. v2 and Factrove's converter drop the SVG, which is cleaner but just as empty of numbers. The canvas fallback text and the figcaption survived in all three:

markdown
Writes/sec: today 400, 100% reads 1,300. Over the 1,000 budget.

So the fix is upstream: have the agent put the numbers in a caption or a sentence. In post 01, adding a caption is what got the chart's data into the Markdown.

Forms

The post 01 script and Factrove's converter produced the same line:

text
Owner   Cleanup job approved  Load test done randominternal first Ship after the load test. Approve plan

The serialized input value, checked attributes and selected option are missing. v2 adds rules for those saved values. It does not inspect a live browser or capture answers stored only in browser properties or application state. Before using an approval page as context, export its current answers to text or JSON and pass that snapshot alongside the conversion.

text
Owner  infra team  [x]  Cleanup job approved [ ]  Load test done  internal first  Ship after the load test. Approve plan

Still ugly, but now the state is there.

Meaning carried by style

"blocked" in red and "needs review" on a yellow background both became plain words. Text hidden with display:none and a screen-reader-only class were kept, so the agent reads things the person never saw.

The one that changes meaning: Factrove's converter drops <s> and <del> markers, so "old plan" and "removed step" read as current. Turndown with the GFM plugin kept them as ~old plan~. That's a gap in my converter.

Images

Alt text survives, and an image without alt becomes ![](https://...), which tells the agent nothing. The bigger one is data: images. The Claude Code artifacts docs say artifact pages embed images as data URIs, so this case is real. The post 01 script only filters links, so it kept the image with its base64 inline. Factrove's converter and v2 keep the alt text and drop the URL.

Embeds

The post 01 script and Factrove's converter dropped the iframe without a trace, title included. The video's fallback text, "Your browser does not support video.", came through as if it were content. v2 turns an iframe with a safe URL into a link, [Embedded: Dry run recording](https://...), so the agent at least knows something was there. Factrove also drops the <object> fallback, so "Report PDF" is only in the Turndown output.

Eleven links, from a normal https link to a few unsafe ones. The interesting rows, from the post 01 script output:

markdown
*   javascript link
*   javascript with space and caps
*   entity-encoded javascript
*   [percent-encoded javascript](java%73cript:alert\(1\))
*   data link
*   [vbscript link](vbscript:msgbox\(1\))
*   [tab inside the scheme](java	script:alert\(1\))

The post 01 rule matches javascript: and data:, so it caught the obvious ones, and the HTML parser decoded the entity-encoded one before the rule saw it. It also kept the percent-encoded link. That one isn't executable in a browser, because the scheme isn't percent-decoded. It missed vbscript: because the rule doesn't list it. And it missed java<tab>script:, because the regex sees a tab. Those two are written as links in the Markdown, but markdown-it doesn't render the vbscript: or tab-in-scheme links as links at all. The WHATWG URL Standard has URL parsers remove ASCII tabs and newlines from the input, so a browser can read the tab one as javascript:.

That's the argument for an allowlist. v2 keeps a link only if the URL starts with https:, http:, mailto:, / or #. Everything else keeps its text and loses the URL. All three of those rows (the percent-encoded link, the vbscript: link and the tab-in-scheme link) dropped to plain text in v2, and in Factrove's converter, which strips control and zero-width characters and decodes percent-encoding before it checks the scheme. v2 drops document-relative targets such as arch-small.png. Those may be resolvable from the original HTML file's directory or source URL, but the Markdown written to /tmp does not carry that location. Keep the original path or URL with the output, and supply essential linked documents or images separately. A target that starts with // passes the / check, so v2 keeps protocol-relative URLs.

Factrove's converter also escapes Markdown characters in ordinary text, and writes &, < and > as entities. Turndown escaped *, _, # and list markers, but turned the text &lt;div&gt; back into a literal <div>. In a Markdown renderer that allows HTML, that's a tag again.

The limits I set in Factrove's converter

Agent HTML is untrusted input, so the converter has hard limits and fails with an error instead of returning partial Markdown, except deep nesting, which it flattens to plain text. These are the values in the code today. Factrove isn't released and they may change.

  • Input: 10 MiB of HTML (10,485,760 bytes).
  • Output: 16 MiB of Markdown, counted as it writes.
  • Nesting: past 100 levels deep it stops building structure and emits plain text.
  • Time: 5 seconds per conversion, in a worker thread that gets terminated if it runs over.
  • Memory: a 256 MB old-generation heap for the worker.
  • Concurrency: 2 conversions at once and 2 waiting by default, then a "busy" error.
  • Dropped elements: script, style, noscript, iframe, object, embed, template, link, meta, title, base, svg and math.
  • URLs: only http, https, mailto and scheme-less URLs are kept.

What the test showed it doesn't do yet: strikethrough, separators between list items inside table cells, form state, and a marker where an embed was. Those are the next things I'd fix.

Where Factrove fits

The plan for Factrove is one ID per artifact: the HTML page for people, and Markdown on request for agents. The converter above is the part that's built, in a private repo, and none of it is released. The request format and CLI syntax may change. The conversion isn't lossless, and this post is the list of what it loses.

If you're sharing these files today, the Claude Code to Codex handoff and AGENTS.md vs CLAUDE.md posts cover getting the same instructions to every agent, and sharing an artifact when external sharing is off covers getting the HTML to people outside your org.


Factrove is early and not available yet; CLI and file formats aren't final. If you've hit a conversion case I didn't test, follow me on X and send it to me. Read the planned artifact workflow or join the waitlist.