Repository: DS4SD/docling
Issue category: Bug Report

Issue:
Image location in Word Document is wrong
### Bug
The image placeholder in parsed docx documents is wrong. An incorrect index is used resulting in a wrong location for images in downstream export formats like markdown.


### Steps to reproduce
Parsing a simple .docx with docling
[image_within_text.docx](https://github.com/user-attachments/files/17919742/image_within_text.docx)


### Docling version
Docling version: 2.7.0
Docling Core version: 2.4.1
Docling IBM Models version: 2.0.6
Docling Parse version: 2.1.2


### Python version
3.12.4


<!-- ⚠️ ATTENTION: When sharing screenshots, attachments, or other data make sure not to include any sensitive information. -->



Hints:

Patch:
diff --git a/docling/backend/msword_backend.py b/docling/backend/msword_backend.py
index 496bdb7b..05508712 100644
--- a/docling/backend/msword_backend.py
+++ b/docling/backend/msword_backend.py
@@ -507,18 +507,19 @@ def get_docx_image(element, drawing_blip):
 
         image_data = get_docx_image(element, drawing_blip)
         image_bytes = BytesIO(image_data)
+        level = self.get_level()
         # Open the BytesIO object with PIL to create an Image
         try:
             pil_image = Image.open(image_bytes)
             doc.add_picture(
-                parent=self.parents[self.level],
+                parent=self.parents[level - 1],
                 image=ImageRef.from_pil(image=pil_image, dpi=72),
                 caption=None,
             )
         except (UnidentifiedImageError, OSError) as e:
             _log.warning("Warning: image cannot be loaded by Pillow")
             doc.add_picture(
-                parent=self.parents[self.level],
+                parent=self.parents[level - 1],
                 caption=None,
             )
         return


Test patch: