PDF to Markdown: a font-size rule, written first, run second
The headline number of today's run: 7 spans in, 7 spans mapped, 0 lost. Before touching the machine we wrote the rule: spans at size ≥ 20 become # H1, size ≥ 14 become ## H2, lines starting with "- " stay list items, everything else stays a paragraph.
The executed run
- Built a structured PDF: page 1 with H1 (24pt), H2 (16pt), two list items and one paragraph; page 2 with a second H1 and one list item.
- Extracted with
page.get_text("dict"), walked every span, applied the rule by font size. - Read back: 2 × H1, 1 × H2, 3 × list, 1 paragraph — 7/7 correct. No span dropped, no heading inflated, no list item flattened.
The rule, verbatim
- Heading
size ≥ 20 → "# " + text;size ≥ 14 → "## " + text- List
- text starts with "- " → keep as-is
- Paragraph
- everything else passes through unchanged
What we could NOT test — the list stays honest
Tables, multi-column layouts, and nested lists were not in today's PDF — the rule above says nothing about them and we will not claim it does. Images are not text spans and were not extracted. A scanned page has no text layer at all; that failure mode is documented on the split run and stays out of scope here.
Decision rule this run supports
For single-column, text-layer PDFs: the font-size mapping is enough to get heading/list/paragraph structure into Markdown with nothing guessed. For anything beyond that, the number will come from execution.