Skip to content

A heading holding a line break extracts as one line, words beside the marker - #63

Merged
leeovery merged 1 commit into
mainfrom
fix-heading-whitespace
Aug 26, 2026
Merged

A heading holding a line break extracts as one line, words beside the marker#63
leeovery merged 1 commit into
mainfrom
fix-heading-whitespace

Conversation

@leeovery

Copy link
Copy Markdown
Owner

Follow-up to #56, from the second field wave (#62) — filed by an instance still on 0.1.0, but a residue of it survives the merged repair.

What #56 left behind

Hugging Face model cards write headings as <h3><span>Use Case: <br></span></h3>. The <br> — not the anchor — is what breaks extraction: a markdown heading is one line by construction, so trafilatura emits the marker alone and the words land below it, among the span's source-formatting tabs and newlines emitted verbatim:

### 
	
	
		Use Case: 

Measured on the two reported pages against each stage:

page 0.1.0 merged #56 this PR
huggingface.co/tencent/HunyuanOCR 12 broken headings 0 0
huggingface.co/nvidia/gliner-PII 18 4 0

The four survivors all carried a <br> inside the heading — isolated as the root cause by testing each repair separately (br-drop alone cures all four; whitespace collapse is what puts the words beside the marker instead of behind a run of tabs). Both repairs ship.

Every page from the first wave (PocketFlow, llama-cpp, HN) extracts byte-identically to the merged repair — no regressions.

A note on the fixture

The first fixture I wrote — the same heading minus the <br>passed against the unfixed code: the <br> was the load-bearing detail the hand-reduction dropped. The shipped fixture is the verbatim HF shape, confirmed failing on merged main before the fix.

Also in this PR

A backlog entry for the one new fact in #61's local note (the fourth article-defect occurrence, fix already merged in #57): an x article's figures live in article.media_entities, which the driver doesn't read. The reporter recovered them by hand. Backlogged rather than fixed — the prose recovery is whole without it, and mapping figures into the media pool is its own small design.

Four gates green: 2041 passed, ruff, ty, format.

Fixes #62

… marker

The second field wave (#62) found the residue the empty-anchor repair did
not reach: Hugging Face model cards write headings as
`<h3><span>Use Case: <br></span></h3>`, and the `<br>` — not the anchor —
is what breaks extraction. A markdown heading is one line by construction,
so trafilatura emits the marker alone and the words follow below it, among
the span's source-formatting tabs and newlines emitted verbatim. Any
consumer keying on the heading line reads an empty heading. Measured on
the two reported pages: 12 and 18 broken headings under 0.1.0; the merged
anchor repair cured 12 and 14 of them; the four survivors all carried a
`<br>` inside the heading.

So preparation now flattens the inside of every heading: `<br>` elements
drop (isolated as the root cause — dropping them alone cures all four
survivors), and whitespace runs collapse to one space, which is what puts
the words beside the marker cleanly instead of behind a run of tabs.
Both reported pages now extract zero broken headings, and every page from
the first wave is byte-identical to what the merged repair produced.

The fixture is the verbatim Hugging Face heading shape — an earlier
hand-reduced version passed against the unfixed code, because the `<br>`
was the load-bearing detail the reduction dropped.

Also records the one new fact from the fourth article-defect occurrence
(#61, its fix already merged): an x article's figures live in
`article.media_entities`, which the driver does not read — a backlog
entry, not a fix, since the prose recovery is whole without it.

Fixes #62

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant