fix: retain HTML content when parent metadata contains cycles
AF
13h ago+138+138+012345678901234567890123456789-10-10-01234567890123456789
Summary
HTML export groups elements using metadata.parent_id. If the supplied metadata contains a self-reference or a cycle, that component has no root, so its text and any descendants silently disappear from the exported document.
Resolve parent references first, detect cycles in a linear graph pass, and render one element from each cycle as a root. This changes only the temporary rendering relationships; source elements and their parent metadata remain untouched. Valid hierarchies, missing-parent fallbacks, and the first-match behavior for duplicate IDs are preserved.
Validation
- 13 regression/control cases cover self-cycles, multi-element cycles, descendants, multiple components, both page-grouping modes, valid child-before-parent input, missing parents, duplicate IDs, empty input, and source-object preservation.
- Base revision: 8 failed, 5 passed. After the fix, the new cases and existing HTML sanitizer suite report 84 passed.
- Compared 48 exports of seeded acyclic forests against the base revision, including list grouping, shuffled input order, missing parents, and multiple pages. Complete HTML output matches after normalizing only the random UUIDs of synthetic list containers; original element IDs and all source values remain unchanged. Repeated base exports provide a control for this UUID normalization.
- Local HTML checks load the complete production export module and real sanitizer without the unrelated HTML package initializer. Normal HTML package initialization and the full partition suite were not run.
- Ruff 0.17.5
check,format --check, andgit diff --checkpass.
Checklist
- The PR title is a user-facing release-note entry with a conventional commit prefix.
- Apply a category label (
enhancement,bug, or an appropriate existing label), or ask a maintainer to apply it. Please applybug. - For breaking changes, use
!in the title and explain impact and migration above. No breaking API change.