mirror of
https://github.com/docling-project/docling-core.git
synced 2026-11-18 20:27:00 +00:00
fix(doclang): serialize CVAT empty_value as a fillable field value
empty_value (a fillable blank) was serialized like plain text. Field-group conversion now marks its FieldValueItem kind="fillable" (checkboxes stay "read_only"), and a bare empty_value outside a field value is emitted as <field_value class="fillable">; under a field value the parent carries the tag. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XCtYYAgaYmY4WJQoAYhfmH
This commit is contained in:
1 parent
372c63c332
commit
b9747f1ae0
2 files changed
+14
-2
No files matched your search
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in new issue
Block a user