SIGN IN SIGN UP

fix(format): add MD fallback for .txt files in _guess_from_content (#3311)

fix(format): detect plain-text (.txt/.text/.qmd) as Markdown

Fixes docling-project/docling#3259

Previously, .txt files were rejected with "File format not allowed"
because _mime_from_extension intentionally returns None for .txt
(the extension is ambiguous between XML_USPTO and MD), and the
text/plain branch in _guess_from_content only checked for the USPTO
PATN\r\n marker before giving up.

This change lets _guess_from_content fall back to InputFormat.MD for
text/plain content when the file extension is in the MD format's
extension list (md/txt/text/qmd/rmd/Rmd). Crucially, the fallback is
extension-gated: unknown extensions like .xyz continue to return None
and raise ConversionError as before, preserving the expected behavior
in tests/test_invalid_input.py.

Changes:
- _guess_from_content accepts an optional ext parameter
- _guess_format now captures the extension into obj_ext and passes
  it into _guess_from_content
- test_input_doc.py asserts that .txt streams and files are detected
  as InputFormat.MD (not None)

Signed-off-by: CrepuscularIRIS <serenitygp@qq.com>
Y
Yarizakura committed
3bab6b4d38362f592b7d00f4cf6050bf23a72122
Parent: 8274892
Committed by GitHub <noreply@github.com> on 4/17/2026, 5:29:20 AM