Skip to content

Commit

Permalink
Recognize json as plain text (if no other handlers are present).
Browse files Browse the repository at this point in the history
  • Loading branch information
afourney committed Jan 4, 2025
1 parent 4364072 commit d7b47ae
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/markitdown/_markitdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,10 @@ def convert(
# Only accept text files
if content_type is None:
return None
elif "text/" not in content_type.lower():
elif all(
not content_type.lower().startswith(type_prefix)
for type_prefix in ["text/", "application/json"]
):
return None

text_content = str(from_path(local_path).best())
Expand Down
9 changes: 9 additions & 0 deletions tests/test_markitdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@
"5bda1dd6",
]

JSON_TEST_STRINGS = [
"5b64c88c-b3c3-4510-bcb8-da0b200602d8",
"9700dc99-6685-40b4-9a3a-5e406dcb37f3",
]


# --- Helper Functions ---
def validate_strings(result, expected_strings, exclude_strings=None):
Expand Down Expand Up @@ -257,6 +262,10 @@ def test_markitdown_local() -> None:
result = markitdown.convert(os.path.join(TEST_FILES_DIR, "test_outlook_msg.msg"))
validate_strings(result, MSG_TEST_STRINGS)

# Test JSON processing
result = markitdown.convert(os.path.join(TEST_FILES_DIR, "test.json"))
validate_strings(result, JSON_TEST_STRINGS)

# Test input with leading blank characters
input_data = b" \n\n\n<html><body><h1>Test</h1></body></html>"
result = markitdown.convert_stream(io.BytesIO(input_data))
Expand Down

0 comments on commit d7b47ae

Please sign in to comment.