Repository navigation
Conversation
Content probing maps any content starting with '<?xml' to 'application/xml'. When none of the specialized XML formats matches (no XBRL marker, no recognized DOCTYPE, no doclang root element), _guess_from_content returned None, so a plain-text .txt/.text file whose content merely starts with a generic XML declaration failed conversion with "File format not allowed (format None)" instead of falling back to InputFormat.MD like other .txt files. Fall back to InputFormat.MD in that case, but only for known plain-text extensions; unknown extensions keep failing, and documents with a recognized specialized XML format are unaffected. Fixes docling-project#5709 Signed-off-by: zlg-codes <light131455@gmail.com>
|
✅ DCO Check Passed Thanks @zlg-codes, all your commits are properly signed off. 🎉 |
Merge Protections🟢 Merge protection satisfied — ready to merge. Show 1 satisfied protection🟢 Enforce conventional commitMake sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
AI triage (advisory)Checked commit The PR makes Topic labels added: CI safety: no concern found. A maintainer must still approve CI. 3 related pull request(s) in the same code
The |
There was a problem hiding this comment.
AI first review (advisory): no blocker found
This review covers the full diff at b56f75b4d9. It read the code and did not run it.
I found no defect. The new fallback in docling/datamodel/document.py runs only after the XBRL, USPTO, JATS and doclang checks have all failed. It also runs only for the known Markdown extensions. For a .txt file that starts with <?xml, the old code returned None at that point.
A maintainer makes the merge decision. This review never approves the pull request.
MohammadHijjawi97
left a comment
There was a problem hiding this comment.
I ran this against main with three .txt streams and one .txt path:
| input | main | this PR |
|---|---|---|
sample.txt = <?xml version='1.0' encoding='UTF-8'?><root><item>Hello</item></root> (repro from #5709) |
skipped, format None |
success, MD, text 'Hello' |
notes.txt = <?xml version='1.0'?>\nThe config below sets the timeout.\n<timeout>30</timeout>\nDone.\n |
skipped |
success, text 'The config below sets the timeout. 30 Done.' |
same sample.txt as a Path |
skipped |
success, 'Hello' |
So the detection part works, and tests/test_input_doc.py passes (84 passed) with ruff clean. The JATS-in-.txt and .xyz cases in the new test also look right to me.
One thing to be aware of: the fallback sends the file to the Markdown backend, which drops every HTML/XML tag except <br>. So the conversion now reports success, but the XML declaration and every element name are gone from the text (<timeout>30</timeout> becomes 30). That is the same problem as #5688. I merged this branch with #5689 locally, and then the text is kept literally (<?xml version='1.0'?> The config below sets the timeout. <timeout>30</timeout> Done.).
Two suggestions:
- Note in the PR (or in a comment) that the output only keeps the markup once #5689 is in, so the two land together or in that order.
- The new test only checks
_guess_format. One end-to-end assertion on the converted text (for example thatHelloandrootboth appear) would catch the tag loss and would start to pass when #5689 merges.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Description
Content probing maps any content starting with
<?xmltoapplication/xml. When none of the specialized XML formats matches (no XBRL marker, no recognized DOCTYPE, no doclang root element),_guess_from_contentreturnedNone, so a plain-text.txt/.textfile whose content merely starts with a generic XML declaration failed conversion withConversionError: File format not allowed (format None)instead of falling back toInputFormat.MDlike other.txtfiles (per the fallback added in #3311).The fix falls back to
InputFormat.MDin that case, but only for known plain-text extensions (md/markdown/txt/text/qmd/rmd). Unknown extensions keep failing instead of silently becoming Markdown, and documents with a recognized specialized XML format (JATS, USPTO, XBRL, doclang) are unaffected — the fallback only runs when the XML branch matched nothing.Known limitation: the Markdown export flattens XML structure —
<root><item>Hello</item></root>exports asHellowithout the element tags. Together with #5689 the text content is preserved, but structural markup is not retained. Mentioned per the review discussion.Issue resolved by this Pull Request:
Resolves #5709
New Package?
Version Bump?
Type of Change
How Has This Been Tested?
Added
test_guess_format_txt_with_generic_xml_declarationcovering bothPathandDocumentStreaminputs:.txt/.textwith a generic declaration →InputFormat.MD;.txt/.xmlwith a JATS DOCTYPE →InputFormat.XML_JATS; unknown extension → stillNone. The new test fails before the change (assert None is InputFormat.MD) and passes after. End-to-end check with the issue's reproducer (DocumentConverter().convert(DocumentStream(name="sample.txt", ...))) now succeeds and exports the text.Review evidence:
Before:
converter.convert(DocumentStream(name="sample.txt", stream=BytesIO(b"<?xml version='1.0' encoding='UTF-8'?>...")))→ConversionError: File format not allowed(format None), reproduced on main via_guess_formatreturningNonefor both path and stream.After: conversion succeeds (
ConversionStatus.SUCCESS), markdown export contains the plain text.tests/test_input_doc.py: 84 passed (full file).make checkpasses (ruff format/check, dprint, uv lock, skill routes).Checklist: