Repository navigation
Conversation
|
✅ DCO Check Passed Thanks @its-amann, all your commits are properly signed off. 🎉 |
Merge Protections🟢 All 2 merge protections satisfied — ready to merge. Show 2 satisfied protections🟢 Enforce conventional commitMake sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
🟢 Require two reviewer for test updatesWhen test data is updated, we require two reviewers
|
AI triage (advisory)Checked commit Warning The AI analysis did not finish. Only the deterministic checks are shown. CI safety: needs maintainer care before you approve CI.
Possibly related pull requests
The |
There was a problem hiding this comment.
AI first review (advisory): no blocker found
This review covers the full diff at ae39a863d9. It read the code and did not run it.
The fix is consistent across Markdown, HTML, DocTags, the outline and the hierarchical chunker. The same defect stays in the LaTeX serializer, which the PR does not touch. Check whether LaTeX is meant to stay out of scope.
A maintainer makes the merge decision. This review never approves the pull request.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
Hi @PeterStaar-IBM and @vagenas, could you take a look when you have a chance? docling-project/docling#5076 is waiting on a release with this fix before it can merge. Thanks! |
ceberam
left a comment
There was a problem hiding this comment.
Thanks @its-amann for the PR, and for splitting the work into a parser PR (docling-project/docling#5076) and a core PR. The core problem is real and the approach is reasonable, but the PR needs a rebase and a few changes before it can be merged. Details below.
Blocking points
1. The branch is stale and the tests fail against current main
The PR is based on 5582916 (v2.105.0). main has since merged #693 (faithful inline whitespace, schema 1.11.0), which changed how inline runs are concatenated. The merge is textually clean, but behavior changes. I merged the PR into current main and ran the new tests: 24 failed, 51 passed. All failures are the same assertion, for example '# Heading eq$y=2$' != '# Heading eq $y=2$' (also Heading eq$y=2$ in the plain-text, outline-JSON and chunk-heading assertions, and in test_rich_heading_with_body_keeps_hybrid_chunk_context).
Please rebase onto main, fix the fixtures, and re-run the tests.
2. LaTeX serializer still has the same defect
docling_core/transforms/serializer/latex.py has the same has_inline_repr check with len(item.children) == 1. The AI reviewer already flagged this and I confirmed it. The PR claims to cover "all exports" of rich headings, but a document with an inline-group heading plus body content still exports in LaTeX with the heading in the wrong place. Please, fix it in this PR, since it is the same change and keeps the exporters consistent.
3. The detection rule is copy-pasted five times; extract it
The same condition now appears (with small variations) in Markdown, HTML and DocTags, plus a differently shaped version in the chunker and in the outline code:
item.text == "" and len(item.children) > 0 and (len(item.children) == 1 or isinstance(item, TitleItem | SectionHeaderItem)) and isinstance(item.children[0].resolve(doc), InlineGroup)This is exactly the kind of rule that will drift (as LaTeX already did, and as the chunker and outline variants are already slightly different). Please factor it into one small helper that returns the leading InlineGroup | None for an item, for example in docling_core/transforms/serializer/common.py, with a Google-style docstring and type annotations, and use it from all serializers, the chunker and the outline. This will also resolve the LaTeX point naturally and removes the long, hard-to-read inline conditions in outline.py (a walrus inside isinstance(...) on a ~120 character line) and hierarchical_chunker.py.
Other points
- Outline title source. In
outline.pythe JSON/ITXT branch buildsMarkdownDocSerializer(doc=doc).serialize(item=child).text. That creates a new serializer with default params and ignores the**kwargs/visitedof the caller, and the result is Markdown ($y=2$,[text](url)for hyperlinks) while ordinary headings use the plainitem.textin the same field. It is acceptable for equations, but a heading with a hyperlink inside the inline group would yield Markdown link syntax in a "title" field and this is unnecessary for outlines. Please, add a test (or amend an existing one) intests/test_serialization_outline.pyshowing that a rich heading with a link does not serialize into an outline with a Markdown standard link syntax. The chunker has the same Markdown-flavoured behavior, but this is fine and consistent with existing chunk headings. - Chunker asymmetry. The chunker accepts
InlineGroupas first child with any number of children, butFormulaItem/CodeItemonly when they are the sole child. That seems intentional, but a short comment saying why would help future maintainers (the existing comment only explains consumption of the children). - Test structure.
test_rich_heading_keeps_its_inline_contentis a single parametrized test with about 25 assertions across five output formats, using string splitting and regexes on HTML and DocTags. When it fails you cannot tell which format broke (this is what happened with the 24 failures above). I suggest one small test per output format, sharing a fixture-building helper. Several assertions also couple to exact whitespace, which is what made them brittle against #693. Asserting on structure (heading text contained in the heading line or tag, body after it, no duplicates) is more robust than asserting exact"Heading eq $y=2$"strings. - Overlapping chunker tests.
test_rich_heading_chunk_context(HierarchicalChunker) and the new test intests/test_hybrid_chunker.pycover similar ground. That is fine since they exercise different public classes, but the hybrid one only covers the "paragraph" variant. - Edge case worth a test. A heading whose children are
[InlineGroup, InlineGroup, text]: the first becomes the heading and the second is body content. This is correct, but it is a visible consequence of the "leading group" rule and should be pinned by a test and mentioned in the description. - PR description. The validation section refers to "six DocLang image fixture failures" reproducing on
main. On currentmainin my environment the full suite passes (1444 passed), so these were probably environment-specific. Consider removing that line to avoid confusion. The description is also quite long. A short problem/fix/scope summary would be easier to review.
What is needed to merge
- Rebase onto current
main; fix the test fixtures ("Heading eq "); confirm that the new tests pass. - Cover the LaTeX serializer.
- Extract the shared "leading inline group of a heading" rule into one helper and use it everywhere.
- Address or comment the remaining points.
Happy to re-review once the above is updated.
ae39a86 to
f06328e
Compare
|
@its-amann Since there has been no movement on this PR since 2 weeks ago and other PRs depend on it, I've just added few commits to address the points of the last review. I have also updated the PR description accordingly. Please, let me know if you see any further issue. |
Signed-off-by: its-amann <[email protected]>
Signed-off-by: its-amann <[email protected]>
Signed-off-by: its-amann <[email protected]>
Inline groups are now concatenated without separators, so the backend is responsible for the whitespace between runs. Signed-off-by: Cesar Berrospi Ramis <[email protected]>
LaTeX still rendered an empty heading command when a title or section header owned a leading inline group together with body children. Treat the leading inline group as the heading content, as the other serializers do. Signed-off-by: Cesar Berrospi Ramis <[email protected]>
Markdown, HTML, DocTags, LaTeX, the outline and the hierarchical chunker each carried their own copy of the check for an item whose content lives in a leading inline group. Move it into get_inline_content_group so the rule cannot drift between them. Signed-off-by: Cesar Berrospi Ramis <[email protected]>
The JSON and ITXT outline titles of a heading whose content lives in an inline group were Markdown, so formatting and hyperlinks leaked into the title field. Use the plain-text serializer, matching headings that carry their text directly. The outline labels select outline entries. Forwarding them to the Markdown text serializer filtered out the runs of a rich heading and left it empty. Signed-off-by: Cesar Berrospi Ramis <[email protected]>
Place the rich heading regression tests next to the serializer and chunker tests they belong to instead of a dedicated file. Split the checks per output format, add a test pinning that only the leading inline group of a rich heading is its title, and give each new test a short docstring. Signed-off-by: Cesar Berrospi Ramis <[email protected]>
Drop the redundant has_inline_repr flag in the HTML and Markdown text serializers and branch on child_group directly. Move the heading content lookup in HierarchicalChunker into a small helper that returns the leading inline group or a sole formula/code child. No behavior change. Signed-off-by: Cesar Berrospi Ramis <[email protected]>
Collapse newlines in the inline content of titles and section headers into a space, as is already done for plain headings, instead of emitting GFM hard line breaks that split the heading line. Signed-off-by: Cesar Berrospi Ramis <[email protected]>
Return only the document from build_rich_heading_doc and assert the exact outline output for the JSON, ITXT and Markdown formats. Signed-off-by: Cesar Berrospi Ramis <[email protected]>
391bf76 to
8adb9db
Compare
Signed-off-by: Cesar Berrospi Ramis <[email protected]>
Description
A title or section header with empty text can keep its content in a leading
InlineGroup(for example a heading that mixes text and an equation). When that heading also owns body content, the serializers only recognised the group if it was the heading's sole child. The heading was then rendered empty, the inline group leaked out as a separate paragraph after it, and chunk and outline metadata carried an empty heading.The leading inline group is now the heading's content, even when body children follow it. The remaining children are serialized as the section body, and the existing
visitedset prevents duplicate output. Only the first inline group is the heading text: a second inline group under the same heading is body content.Ordinary text items and list items keep their existing rule, where the group only counts if it is the sole child. DocLang already treated the leading inline group as content and is unchanged.
This is the core companion for docling#5076, which implements the DOCX representation requested in docling#5034. The parser PR needs a release containing this fix and a raised
docling-coredependency.Before and after
For an empty level 1 section header with the inline group "Heading eq " + formula
y=2, followed by a paragraph "Body.":##thenHeading eq $y=2$thenBody.as separate paragraphs## Heading eq $y=2$thenBody.<h2></h2>followed by a bare<span><h2><section_header_level_1></section_header_level_1>followed by a sibling<inline><inline>sits inside the heading element\section{}followed by the content as a paragraph\section{Heading eq $y=2$}titletitleisHeading eq $y=2$headings == ['']and the inline group emitted as its own chunkBody.withheadings == ['Heading eq $y=2$']Changes
get_inline_content_group()todocling_core/transforms/serializer/common.py. It returns the leading inline group that holds the content of an item with empty text: titles and section headers accept it with any number of children, other items only as the sole child.HierarchicalChunker, replacing the copies of the condition. This also fixes the LaTeX serializer, which had the same defect.## Line1 Line2 $y=2$instead of## Line1followed byLine2 $y=2$.HierarchicalChunker, the leading inline group is consumed as the heading text so it no longer becomes a body chunk. A soleFormulaItemorCodeItemchild keeps working as before. The lookup lives in a small_get_heading_content()helper.build_rich_heading_doc()lives intests/test_serialization.pyand is reused by the DocTags and outline tests.Notes for reviewers
[text](url)for a hyperlink). Only the JSON and ITXT outline titles are plain text."Heading eq ").Validation
mainand pass with this change. The "no body" variants were already correct onmainand are not tested. The test for an inline group that follows a body item passes onmaintoo, and guards against the fix over-matching.ruff checkandruff format --checkpass, andtyreports no new diagnostics in the changed modules.