Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docling/backend/msword_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,8 @@ def _walk_linear(
) -> tuple[DoclingDocument, list[RefItem]]:
added_elements = []
for element in body:
if not isinstance(element.tag, str):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have this text in a ContentLayer. I am generally not a fan of omitting text, unless it is format related.

continue
tag_name = etree.QName(element).localname
# Check for Inline Images (blip elements)
_raw_drawing_blip = self.blip_xpath_expr(element)
Expand Down
22 changes: 22 additions & 0 deletions tests/test_backend_msword.py
Original file line number Diff line number Diff line change
Expand Up @@ -1472,6 +1472,28 @@ def test_malformed_hyperlink_does_not_abort_conversion(tmp_path):
assert hyperlinks == []


def test_non_element_nodes_do_not_abort_conversion(tmp_path):
doc = Document()
doc.add_paragraph("Before metadata.")
doc.element.body.insert(1, etree.Comment("synthetic comment"))
doc.element.body.insert(
2, etree.ProcessingInstruction("synthetic", 'value="metadata"')
)
doc.add_paragraph("After metadata.")

docx_path = tmp_path / "non_element_nodes.docx"
doc.save(docx_path)

in_doc = InputDocument(
path_or_stream=docx_path,
format=InputFormat.DOCX,
backend=MsWordDocumentBackend,
)
result = in_doc._backend.convert()

assert result.export_to_markdown() == "Before metadata.\n\nAfter metadata."


def test_trailing_whitespace_run_keeps_paragraph_formatting(tmp_path):
"""A whitespace-only trailing run must not overwrite the paragraph's formatting.

Expand Down
Loading