diff --git a/docling_core/transforms/serializer/doclang.py b/docling_core/transforms/serializer/doclang.py index 02f367b1..8d0266fb 100644 --- a/docling_core/transforms/serializer/doclang.py +++ b/docling_core/transforms/serializer/doclang.py @@ -1311,10 +1311,18 @@ class DocLangTextSerializer(BaseModel, BaseTextSerializer): wrap_open_token = f'<{tok.value} class="{item.kind}">' elif isinstance(item, FieldHeadingItem): wrap_open_token = DocLangVocabulary._create_field_heading_token(level=item.level) + elif isinstance(item, TextItem) and item.label == DocItemLabel.EMPTY_VALUE: + # CVAT empty_value / fillable_field. A parent field_value already + # carries the tag; otherwise emit the fillable value itself. + parent_item = item.parent.resolve(doc) if item.parent else None + if isinstance(parent_item, FieldValueItem): + wrap_open_token = None + else: + tok = DocLangToken.FIELD_VALUE + wrap_open_token = f'<{tok.value} class="fillable">' elif isinstance(item, TextItem) and ( item.label in [ # FIXME: Catch all ... - DocItemLabel.EMPTY_VALUE, # FIXME: this might need to become a FormItem with only a value key! DocItemLabel.HANDWRITTEN_TEXT, DocItemLabel.PARAGRAPH, DocItemLabel.REFERENCE, diff --git a/docling_core/types/doc/document.py b/docling_core/types/doc/document.py index af5d3fa3..caa77622 100644 --- a/docling_core/types/doc/document.py +++ b/docling_core/types/doc/document.py @@ -904,7 +904,11 @@ class DoclingDocument(BaseModel): fi = FieldItem(self_ref="#") self.insert_item_before_sibling(new_item=fi, sibling=vg[0]) for value_item in vg: - fv = FieldValueItem(self_ref="#", orig="", text="") + # CVAT empty_value is a fillable blank. Checkboxes stay read-only wrappers. + kind: typing.Literal["read_only", "fillable"] = ( + "fillable" if value_item.label == DocItemLabel.EMPTY_VALUE else "read_only" + ) + fv = FieldValueItem(self_ref="#", orig="", text="", kind=kind) self._shift_down(old_subroot=value_item, new_subroot=fv) self._move_subtree(old_subroot=fv, new_subroot=fi)