docling
docling copied to clipboard
DOCX conversion fails when styles.xml declares a style with w:type="list"
Bug
A DOCX fails to convert when its word/styles.xml declares a style with w:type="list":
ValueError: WD_STYLE_TYPE has no XML mapping for 'list'
ST_StyleType has no list value. The numbering style type is numbering (WD_STYLE_TYPE.LIST in python-docx). Real files still contain list: we found one in a press release from an investor-relations site.
python-docx raises when it reads the type of such a style. Styles.default() reads the type of every style, and two paths call it:
- Since 2.115.0,
MsWordDocumentBackend.__init__callsstyles.default(WD_STYLE_TYPE.PARAGRAPH)when it opens the file. So every file with such a style now fails. 2.114.0 converted it when every paragraph had aw:pStyle. paragraph.styleon a paragraph withoutw:pStylealso calls it. These files already failed on 2.114.0.
Steps to reproduce
import io
import docx
from docx.oxml import OxmlElement
from docx.oxml.ns import qn
from docling.datamodel.base_models import DocumentStream
from docling.document_converter import DocumentConverter
d = docx.Document()
d.add_paragraph("Quarterly results", style="Heading 1")
d.add_paragraph("Revenue grew 3%.", style="Body Text") # style=None: the paragraph has no w:pStyle
style = OxmlElement("w:style")
style.set(qn("w:type"), "list")
style.set(qn("w:styleId"), "OutlineList")
d.styles.element.append(style)
buf = io.BytesIO()
d.save(buf)
buf.seek(0)
DocumentConverter().convert(DocumentStream(name="x.docx", stream=buf))
# ValueError: WD_STYLE_TYPE has no XML mapping for 'list'
| docling | every paragraph has a w:pStyle |
a paragraph without w:pStyle |
|---|---|---|
| 2.114.0 | converts | fails (RuntimeError, caused by the same ValueError) |
| 2.115.0, 2.138.0, main (6fadbae) | fails | fails |
Docling version
2.115.0 to 2.138.0, and main at 6fadbae.
Python version
Python 3.12.0 (releases) and 3.14.7 (main).
I can take a look at this and open a PR with a test.