docling-core 2.44.1__py3-none-any.whl → 2.44.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of docling-core might be problematic. Click here for more details.

@@ -130,11 +130,14 @@ class HTMLTextSerializer(BaseModel, BaseTextSerializer):
130
130
  doc_serializer: BaseDocSerializer,
131
131
  doc: DoclingDocument,
132
132
  is_inline_scope: bool = False,
133
+ visited: Optional[set[str]] = None,
133
134
  **kwargs: Any,
134
135
  ) -> SerializationResult:
135
136
  """Serializes the passed text item to HTML."""
136
137
  params = HTMLParams(**kwargs)
138
+ my_visited: set[str] = visited if visited is not None else set()
137
139
  res_parts: list[SerializationResult] = []
140
+ post_processed = False
138
141
 
139
142
  # Prepare the HTML based on item type
140
143
  if isinstance(item, TitleItem):
@@ -162,7 +165,28 @@ class HTMLTextSerializer(BaseModel, BaseTextSerializer):
162
165
 
163
166
  elif isinstance(item, ListItem):
164
167
  # List items are handled by list serializer
165
- text_inner = self._prepare_content(item.text)
168
+ text_parts: list[str] = []
169
+ if item_text := self._prepare_content(item.text):
170
+ item_text = doc_serializer.post_process(
171
+ text=item_text,
172
+ formatting=item.formatting,
173
+ hyperlink=item.hyperlink,
174
+ )
175
+ post_processed = True
176
+ text_parts.append(item_text)
177
+ nested_parts = [
178
+ r.text
179
+ for r in doc_serializer.get_parts(
180
+ item=item,
181
+ is_inline_scope=is_inline_scope,
182
+ visited=my_visited,
183
+ **kwargs,
184
+ )
185
+ ]
186
+ text_parts.extend(nested_parts)
187
+ text_inner = "\n".join(text_parts)
188
+ if nested_parts:
189
+ text_inner = f"\n{text_inner}\n"
166
190
  text = (
167
191
  get_html_tag_with_text_direction(
168
192
  html_tag="li",
@@ -185,11 +209,12 @@ class HTMLTextSerializer(BaseModel, BaseTextSerializer):
185
209
  text = get_html_tag_with_text_direction(html_tag="p", text=text_inner)
186
210
 
187
211
  # Apply formatting and hyperlinks
188
- text = doc_serializer.post_process(
189
- text=text,
190
- formatting=item.formatting,
191
- hyperlink=item.hyperlink,
192
- )
212
+ if not post_processed:
213
+ text = doc_serializer.post_process(
214
+ text=text,
215
+ formatting=item.formatting,
216
+ hyperlink=item.hyperlink,
217
+ )
193
218
 
194
219
  if text:
195
220
  text_res = create_ser_result(text=text, span_source=item)
@@ -703,7 +728,6 @@ class HTMLListSerializer(BaseModel, BaseListSerializer):
703
728
  ) -> SerializationResult:
704
729
  """Serializes a list to HTML."""
705
730
  my_visited: set[str] = visited if visited is not None else set()
706
- params = HTMLParams(**kwargs)
707
731
  # Get all child parts
708
732
  parts = doc_serializer.get_parts(
709
733
  item=item,
@@ -713,72 +737,8 @@ class HTMLListSerializer(BaseModel, BaseListSerializer):
713
737
  **kwargs,
714
738
  )
715
739
 
716
- # Append nested list to parent list item:
717
- i = 0
718
- while i < len(parts):
719
- prt = parts[i]
720
- if prt.text.startswith(("<ul>", "<ol>")):
721
- for j in range(i - 1, -1, -1):
722
- if parts[j].text.startswith(("<li>", "<li ")) and parts[
723
- j
724
- ].text.endswith("</li>"):
725
- before, _, _ = parts[j].text.rpartition("</li>")
726
- parts[j].text = f"{before}\n{prt.text}\n</li>"
727
- break
728
- if j > -1:
729
- parts.pop(i)
730
- else:
731
- i += 1
732
-
733
740
  # Add all child parts
734
- text_res = "\n".join(
735
- [
736
- (
737
- p.text
738
- if (
739
- (
740
- p.text.startswith(("<li>", "<li "))
741
- and p.text.endswith("</li>")
742
- )
743
- or (
744
- p.text.startswith(("<ol>", "<ol "))
745
- and p.text.endswith("</ol>")
746
- )
747
- or (
748
- p.text.startswith(("<ul>", "<ul "))
749
- and p.text.endswith("</ul>")
750
- )
751
- )
752
- else (
753
- get_html_tag_with_text_direction(
754
- html_tag="li",
755
- text=p.text,
756
- attrs=(
757
- {
758
- "style": f"list-style-type: '{grandparent_item.marker} ';"
759
- }
760
- if params.show_original_list_item_marker
761
- and grandparent_item.marker
762
- else {}
763
- ),
764
- )
765
- if p.spans
766
- and p.spans[0].item.parent
767
- and isinstance(
768
- (parent_item := p.spans[0].item.parent.resolve(doc)),
769
- InlineGroup,
770
- )
771
- and parent_item.parent
772
- and isinstance(
773
- (grandparent_item := parent_item.parent.resolve(doc)),
774
- ListItem,
775
- )
776
- else f"<li>{p.text}</li>"
777
- )
778
- )
779
- for p in parts
780
- ]
781
- )
741
+ text_res = "\n".join(p.text for p in parts if p.text)
782
742
  if text_res:
783
743
  tag = "ol" if item.first_item_is_enumerated(doc) else "ul"
784
744
  text_res = f"<{tag}>\n{text_res}\n</{tag}>"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: docling-core
3
- Version: 2.44.1
3
+ Version: 2.44.2
4
4
  Summary: A python library to define and validate data types in Docling.
5
5
  Author-email: Cesar Berrospi Ramis <ceb@zurich.ibm.com>, Panos Vagenas <pva@zurich.ibm.com>, Michele Dolfi <dol@zurich.ibm.com>, Christoph Auer <cau@zurich.ibm.com>, Peter Staar <taa@zurich.ibm.com>
6
6
  Maintainer-email: Panos Vagenas <pva@zurich.ibm.com>, Michele Dolfi <dol@zurich.ibm.com>, Christoph Auer <cau@zurich.ibm.com>, Peter Staar <taa@zurich.ibm.com>, Cesar Berrospi Ramis <ceb@zurich.ibm.com>
@@ -30,7 +30,7 @@ docling_core/transforms/serializer/__init__.py,sha256=CECQlMoCDUxkg4RAUdC3itA3I3
30
30
  docling_core/transforms/serializer/base.py,sha256=TI8Epj7gyxdTet9j-Rs4o5U09gfACfAIVoirlschviM,7266
31
31
  docling_core/transforms/serializer/common.py,sha256=0TNEGoA_rJ-qkVYp-X8SMUr3jTrbf6TRzPzwufYh5JM,19114
32
32
  docling_core/transforms/serializer/doctags.py,sha256=TD0yAm1qSVy-GsE6svpUAI-Yqjcf2rrTZ3ac9YU3gbE,19858
33
- docling_core/transforms/serializer/html.py,sha256=JswD_tQiQgmOJ29erkn6qEJX0F2N7zaoxJ9TCCSQPLE,39635
33
+ docling_core/transforms/serializer/html.py,sha256=KnSMjtNZlBMfkuhtgB8T70iQSTfG_E8FFDfVRRo9WNs,38087
34
34
  docling_core/transforms/serializer/html_styles.py,sha256=-jBwS4EU7yfKoz0GSoxhwx90OmIKieO6TwPw57IuxcA,4692
35
35
  docling_core/transforms/serializer/markdown.py,sha256=VwonuAkuOPmQM7ibDIGvQBHOqhTcTJ_t187fLQQiNPo,23951
36
36
  docling_core/transforms/visualizer/__init__.py,sha256=gUfF25yiJ_KO46ZIUNqZQOZGy2PLx6gnnr6AZYxKHXI,35
@@ -76,9 +76,9 @@ docling_core/utils/generate_jsonschema.py,sha256=uNX1O5XnjyB5nA66XqZXTt3YbGuR2ty
76
76
  docling_core/utils/legacy.py,sha256=5lghO48OEcV9V51tRnH3YSKgLtdqhr-Q5C_OcJZ8TOs,24392
77
77
  docling_core/utils/validate.py,sha256=aQ11UbFyl8iD_N7yTTZmm_VVeXz8KcCyn3GLXgkfYRM,2049
78
78
  docling_core/utils/validators.py,sha256=azcrndLzhNkTWnbFSu9shJ5D3j_znnLrIFA5R8hzmGU,2798
79
- docling_core-2.44.1.dist-info/licenses/LICENSE,sha256=2M9-6EoQ1sxFztTOkXGAtwUDJvnWaAHdB9BYWVwGkIw,1087
80
- docling_core-2.44.1.dist-info/METADATA,sha256=NtybqGuK3bjSWq_AadW7B-pydco80WLkFYwWaWyaTb0,6453
81
- docling_core-2.44.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
82
- docling_core-2.44.1.dist-info/entry_points.txt,sha256=ER4zROQWkFMHIrY-oqY5E4HeCcCIg8dLkNztYGxdb7c,59
83
- docling_core-2.44.1.dist-info/top_level.txt,sha256=O-tcXpGiurlud-1ZxMq1b-OmrfAVA4sajcgWU32RtfA,13
84
- docling_core-2.44.1.dist-info/RECORD,,
79
+ docling_core-2.44.2.dist-info/licenses/LICENSE,sha256=2M9-6EoQ1sxFztTOkXGAtwUDJvnWaAHdB9BYWVwGkIw,1087
80
+ docling_core-2.44.2.dist-info/METADATA,sha256=IZWVMKuPPpzd3ksiFXTPUu3FSw13zuwa5qyaLWlBEyY,6453
81
+ docling_core-2.44.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
82
+ docling_core-2.44.2.dist-info/entry_points.txt,sha256=ER4zROQWkFMHIrY-oqY5E4HeCcCIg8dLkNztYGxdb7c,59
83
+ docling_core-2.44.2.dist-info/top_level.txt,sha256=O-tcXpGiurlud-1ZxMq1b-OmrfAVA4sajcgWU32RtfA,13
84
+ docling_core-2.44.2.dist-info/RECORD,,