Skip to content

fix(html): give a paragraph its own font, and an empty one a line break - #687

Merged
andiwand merged 1 commit into
mainfrom
fix/paragraph-own-font
Aug 11, 2026
Merged

fix(html): give a paragraph its own font, and an empty one a line break#687
andiwand merged 1 commit into
mainfrom
fix/paragraph-own-font

Conversation

@andiwand

@andiwand andiwand commented Aug 11, 2026

Copy link
Copy Markdown
Member

Stacked on #686. Implements the empty-paragraph rework we measured out, and fixes a live bug it exposed.

The mechanism it replaces

x-p collapsed to font-size:0 and every empty paragraph carried an empty <x-s> to stand in for its height. Removing each piece in turn shows both were load-bearing — a 14pt line is 22px:

markup height
native one line of 14pt (target) 22
<x-p><x-s style="font-size:14pt"></x-s><wbr></x-p> (before) 22
…minus the <wbr> 0
…minus the empty <x-s> 0

The bug it caused

font-size:0 is inherited, so a run naming no size of its own computed to 0px. Walking every run in the corpus for its effective size, then confirming in the browser: 11 pages of pptx/2025-09-11.15_35_15.pptx rendered text that was there but invisible — the reference output blessed eleven blank slides. Now visible.

What this does instead

The paragraph states its own font (translate_block_font_style), which sizes the line it gives an empty paragraph and is inherited by a run that names none. Only the font travels: a background painted on a block covers 756px of line where the run covers 42px, so anything that paints stays on the run.

An empty paragraph ends in <br> rather than <wbr>, because only a break is copied:

empty paragraph visible copied text
before 22px ✓ "Alpha\nBeta" — blank line lost
<wbr> 22px ✓ "Alpha\nBeta" — blank line lost
<br> 22px ✓ "Alpha\n\nBeta"
both together 44px

On real documents: about.odt goes from 1 to 9 blank lines in a select-all copy (10 empty paragraphs), 15KB.docx from 0 to 9 (12), with every empty paragraph still visible at unchanged height.

A bookmark does not count as content, which is what // TODO if element is content (e.g. bookmark does not count) asked for. Both TODO examples are fixed: style-missing+image-1.odt's first paragraph goes 0 → 18px, and the "missing line break" in encrypted-exception-3$aabbcc$.odt was an empty paragraph collapsed to 0, now 16px.

No JS is needed for the <br>: typing into an empty paragraph makes Chrome remove it (<br>X, still 22px), and deleting a paragraph's text makes Chrome insert one — <br> is the filler engines already use for an empty editable line. Verified in Chrome only.

Verification

Note compare-html cannot verify the CSS half of this: it short-circuits byte-identical files without rendering them (see the correction in #685). The pptx fix is exactly such a case — its html is unchanged and only the stylesheet makes the text appear. So both sides were rendered and compared as pixels.

Of 228 public pages, 40 differ. All are the intended change or known noise:

  • pptx (11 pages) — text that was invisible now renders.
  • odt/docx page heights (about.odt 2408 → 2415, file-sample_500kB.odt 3721 → 3952) — empty paragraphs that collapsed to 0 now occupy their line.
  • ods (many) — a sub-pixel baseline shift: dy −0.78px on the header with ink identical to the byte, dy −0.83px and +0.5% ink on data rows. Cells whose runs name no font now take the file's paragraph font, so the strut metrics change; row heights and glyphs do not. Two sheets change height, both overflow.ods-style fixtures whose overlapping text stack is slightly shorter.
  • pdf (4 pages) and 2 xls pages — nondeterministic: rendering the same tree twice reproduces them at the same bounding boxes.

Reference output regenerated and pinned: 1964c34 (185 files over two commits) and the private equivalent 5e5f035 (301 files). Pre-existing resource drift from #679/#682/#683 was left alone rather than swept in, so resources/ moves only in document.css and spreadsheet.css.

translate_block_font_style gets three unit tests next to the existing inline-expectation ones; 864 tests pass.

Worth a second opinion

The sheet baseline shift is the one judgement call. Emitting font-size alone and leaving font-family off would keep sheets pixel-identical, but the strut's height depends on font metrics, so the family is part of getting an empty paragraph's height right. Say the word and I'll narrow it.

Review follow-ups

Both P2 findings from the Codex review are addressed in the amended commit.

  • Emptiness is now read recursively, through the wrappers a file leaves behind — a bookmark, or a span/link holding nothing or only empty text. 52 output files move from <wbr> to <br>; encrypted-exception-3$aabbcc$.odt goes from 91 to 92 blank lines in a select-all copy with every empty paragraph still visible at unchanged height.
  • The sheet font fallback reaches shape text. It is a descendant rule now (.odr-sheet>tbody>tr>td x-p), with height:inherit left child-scoped where it belongs. All 98 shape paragraphs in the corpus name their own font, so no output moved; verified against the emitted stylesheet with a synthetic cell instead — a cell paragraph and a shape paragraph naming no font both resolve to 10pt/13.333px, where the shape one had fallen back to the browser default.

🤖 Generated with Claude Code

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ca4e6ae961

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/odr/internal/html/frontend.cpp Outdated
Comment thread src/odr/internal/html/document_element.cpp Outdated
@andiwand
andiwand force-pushed the fix/paragraph-own-font branch from ca4e6ae to 2b19522 Compare August 11, 2026 20:03
`x-p` collapsed to `font-size:0` and an empty paragraph carried an empty
span to stand in for its height. A run naming no size of its own then
inherited nothing and rendered at zero - one pptx in the corpus reads as
eleven blank slides.

The paragraph states its font instead, which sizes the line it gives an
empty one, and a run without a font of its own inherits it. What paints -
a background, an underline - stays on the run, where it covers the text
and not the line.

An empty paragraph ends in a line break rather than a break opportunity:
only a break is copied, so a blank line survives being pasted elsewhere.
Emptiness is read through the wrappers a file may leave behind - a
bookmark, or a span or link holding nothing - which is what the removed
TODO asked for.

Fixes the two TODO examples: `style-missing+image-1.odt`'s first
paragraph goes from 0 to 18px, and the line break missing from
`encrypted-exception-3$aabbcc$.odt` was a paragraph collapsed to 0.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QVkpzsGS6YASMqm3NwmWib
@andiwand
andiwand changed the base branch from refactor/scope-sheet-css to main August 11, 2026 20:10
@andiwand
andiwand force-pushed the fix/paragraph-own-font branch from 2b19522 to d1d62ac Compare August 11, 2026 20:10
@andiwand
andiwand enabled auto-merge (squash) August 11, 2026 20:12
@andiwand
andiwand merged commit 6cd2815 into main Aug 11, 2026
36 checks passed
@andiwand
andiwand deleted the fix/paragraph-own-font branch August 11, 2026 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant