Repository navigation
Conversation
The email backend exported each text/html part to Markdown and stored the result as text items. Every export of the email then escaped that Markdown again, so a code span showed `a < b` and a table cell showed 1 & 2. Headings, lists and tables reached the JSON and text exports as Markdown text. Concatenate the HTML conversion into the email document instead, so the body keeps its items, labels and content layers. concatenate() also remaps caption, footnote and rich table cell references, which add_document() does not. When the email has a subject, turn a body <h1> into a level 1 section header and move the other body headings down one level, so the subject stays the only title and leads the chunk heading context. Make the attachments heading level 1, so it ranks directly under the subject. Signed-off-by: Krish Garg <181051779+krishhgg@users.noreply.github.com>
|
✅ DCO Check Passed Thanks @krishhgg, all your commits are properly signed off. 🎉 |
Merge Protections🟢 Merge protection satisfied — ready to merge. Show 1 satisfied protection🟢 Enforce conventional commitMake sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
AI triage (advisory)Checked commit Warning The AI analysis did not finish. Only the deterministic checks are shown. Topic labels added: CI safety: not assessed. 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 9fb37b747b. It read the code and did not run it.
I found no blocker. DoclingDocument.concatenate() remaps caption, footnote and rich-cell refs, and the new tests cover this. The one point to check is the heading-level rule in _nest_headings_under_subject(). It does not match what the docs say.
A maintainer makes the merge decision. This review never approves the pull request.
|
|
||
| Email conversion prefers non-empty plain-text bodies. When it uses an HTML body, | ||
| text in `<footer>` elements is retained in the furniture content layer. Default | ||
| the email holds the items of the HTML conversion of that body, such as headings, |
There was a problem hiding this comment.
suggestion: Docs say all body headings move down one level, but the code only does so when the body has an <h1>
_nest_headings_under_subject() in docling/backend/email_backend.py returns early when the HTML part has no TitleItem, so only a body with an <h1> gets shifted. An email with a subject and a body that has only <h2> or <h3> keeps those levels unchanged: <h2> stays level 1. The docs say "the other headings move one level down" without this condition. Add the condition to the docs, for example "If the body has an <h1>, ...". The behavior itself is consistent: the <h2> headings still sit directly under the subject, at the same level as the attachments heading.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Follow-up to #5219 after #4828 and #5228. Those fixed the sample in the issue, but an HTML body is still exported to Markdown and stored as text items. Every export of the email escapes that Markdown again, so a code span shows
a < band a table cell shows1 & 2. Headings, lists and tables reach the JSON and text exports as Markdown text.The email document now takes the items of the HTML conversion through
DoclingDocument.concatenate(), as the XBRL backend does for its HTML text blocks.concatenate()remaps caption, footnote and rich table cell refs.add_document()does not. When the email has a subject, a body<h1>becomes a level 1 section header and the other body headings move down one level, so the subject stays the only title and comes first in chunk headings.One change also reaches plain-text emails. The attachments heading moves from level 2 to level 1, so it sits directly under the subject instead of under the last body heading. In Markdown,
### Attachmentsbecomes## Attachmentsfor every email that lists attachments.This overlaps with two open PRs:
export_to_markdown()call that this change removes. It drops picture placeholders. Here an<img>becomes a picture item and the Markdown keeps the usual<!-- image -->comment._add_attachments(), keeps "Attachments" at level 2 and adds a level 3 heading per attachment. Whichever merges second needs to line up those levels.Checklist:
Review evidence:
Source: the HTML-only message from #5219 with a code span and a table added. On main the body items hold Markdown text, and the export shows
Run `a < b` first.and| a\_b | 1 & 2 |. Now the tree has text, code and table items, the footer is a furniture item, and the export showsRun `a < b` first.and| a_b | 1 & 2 |.Source: subject "Quarterly report", body
<h1>Revenue</h1>and<h2>Details</h2>, one attachment listed. On main the body headings are text items such as# Revenue, so every body chunk only gets the subject as its heading. NowHierarchicalChunkergives["Quarterly report", "Revenue", "Details"]for the body and["Quarterly report", "Attachments"]for the attachment list.The new tests cover escaping, heading levels and chunk headings, the attachments level, inline group parents, caption and rich table cell refs across two HTML parts, a JSON round trip and the text export.
uv run pytest tests/test_backend_email.py -q: 38 passed. The three new tests fail on main.uv run pytest tests/test_backend_email.py tests/test_input_doc.py tests/test_backend_optional_dependencies.py -q: 147 passed.make validateandmake check: passed.make checkprints only existing warnings.