feat: add attachment serializer support and exclusion filtering - #713
feat: add attachment serializer support and exclusion filtering#713yonikremer wants to merge 8 commits into
Conversation
|
❌ DCO Check Failed Hi @yonikremer, your pull request has failed the Developer Certificate of Origin (DCO) check. This repository supports remediation commits, so you can fix this without rewriting history — but you must follow the required message format. 🛠 Quick Fix: Add a remediation commitRun this command: git commit --allow-empty -s -m "DCO Remediation Commit for yoni kremer <yoni.kremer@gmail.com>
I, yoni kremer <yoni.kremer@gmail.com>, hereby add my Signed-off-by to this commit: 6378afcb3f9030b56d13f8dbf436fcd81b7f5541
I, yoni kremer <yoni.kremer@gmail.com>, hereby add my Signed-off-by to this commit: b9a54f8a44ca0f5989a5c1d1349092572fa76d3e
I, yoni kremer <yoni.kremer@gmail.com>, hereby add my Signed-off-by to this commit: 4e2bc875cb9da1367e73a3da4191d1d74f596f25
I, yoni kremer <yoni.kremer@gmail.com>, hereby add my Signed-off-by to this commit: afe742577c105ca3199a48de3a285dd8c4955c8f
I, yoni kremer <yoni.kremer@gmail.com>, hereby add my Signed-off-by to this commit: 1f3600570d6e48166b52c902adbf2919c821a1e6"
git push🔧 Advanced: Sign off each commit directlyFor the latest commit: git commit --amend --signoff
git push --force-with-leaseFor multiple commits: git rebase --signoff origin/main
git push --force-with-leaseMore info: DCO check report |
Merge Protections🔴 1 of 2 protections blocking · waiting on 👀 reviews
🔴 Require two reviewer for test updatesWaiting for
This rule is failing.When test data is updated, we require two reviewers
Show 1 satisfied protection🟢 Enforce conventional commitMake sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
I, yoni kremer <yoni.kremer@gmail.com>, hereby add my Signed-off-by to this commit: 6378afc I, yoni kremer <yoni.kremer@gmail.com>, hereby add my Signed-off-by to this commit: b9a54f8 I, yoni kremer <yoni.kremer@gmail.com>, hereby add my Signed-off-by to this commit: 4e2bc87 I, yoni kremer <yoni.kremer@gmail.com>, hereby add my Signed-off-by to this commit: afe7425 Signed-off-by: yoni kremer <yoni.kremer@gmail.com>
|
This PR blocks docling-project/docling-parse#313 and another PR I am writing to docling's main repo. @PeterStaar-IBM can you/another maintainer take a look at it? |
|
@yonikremer looks good in general, but you need to fix the CI |
- fix import order in document.py - collapse multiline fields in attachment.py - reformat markdown serializer and attachment test - add PdfAttachment/FileAttachmentAnnotation models to page.py Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: yoni kremer <yoni.kremer@gmail.com>
Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: yoni kremer <yoni.kremer@gmail.com>
|
@PeterStaar-IBM I fixed it, It now passes CI locally |
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
|
@yonikremer Looking at your PR, we discussed with the team internally, and I think the following course of action would be preferred (since there are also other PR's coming into Docling regarding email attachments):
|
Align with review docling-project#713 (PeterStaar-IBM 2026-08-13): 1. SegmentedPage/PdfAttachment: FileAttachmentAnnotation + PdfAttachment with binary `data` (mimetype/size preserved), wired into both SegmentedPdfPage.attachments and ParsedPdfDocument.attachments — unblocks docling-parse#313. 2. DoclingDocument/AttachmentItem: AttachmentItem with binary `data` (raw payload) and `doc_data` (serialized DCLG/DCLX) stored in DoclingDocument.attachments (+ _DocIndex / _iterate / normalize). Serializers deferred to follow-up PR per review point 2 (reverts base/common/doctags/html/markdown attachment serializers). 3. Recursive parsing: `doc_data` carries a serialized DoclingDocument; when present, `status` is implicitly "converted" and ignored (validator warns if status != converted but doc_data is set). Co-Authored-By: Claude <noreply@anthropic.com>
Summary
This PR adds full attachment serialization support across Doctags, Markdown, and HTML formatters, and integrates
AttachmentIteminto theDoclingDocumentmodel traversal and index structure.Closes #712
Key Changes & Design Decisions
1. Document Model & Index Integration (
DoclingDocument,_DocIndex)attachmentstoDoclingDocument._DocIndex,_iterate_items_with_stack, reference validation, and reference normalization (_normalize_references)._custom_pydantic_serializeto omit theattachmentskey when empty ([]), maintaining clean JSON output.AttachmentItemhandling in_append_itemgenerating proper JSON pointers (#/attachments/N).2. Document Token Mapping (
DocumentToken)ATTACHMENT = "attachment"toDocumentTokenand mappedDocItemLabel.ATTACHMENTincreate_token_name_from_doc_item_label.<attachment>special token during document token generation.3. Serializers & Exclusion Filtering (
doctags,markdown,html,common)DocTagsAttachmentSerializerrendering<attachment>...</attachment>tags with optional location tokens and conversion status details.doc_serializer.get_excluded_refs()inMarkdownAttachmentSerializer,HTMLAttachmentSerializer, andMarkdownDocSerializerto respect label/layer filters.## Attachmentssection in Markdown serializer output.Testing
test/test_attachment_serialization.pywith unit tests:test_attachment_normalize_references)test_add_item_attachment)test_attachment_export_to_doctags)test_attachment_exclusion_filtering)