Resolved an issue with linked images in docx [mammoth] (#1405)

This commit is contained in:
afourney
2025-08-26 14:20:29 -07:00
committed by GitHub
parent da7bcea527
commit 9278119bb3
3 changed files with 12 additions and 2 deletions

View File

@@ -36,7 +36,7 @@ dependencies = [
[project.optional-dependencies] [project.optional-dependencies]
all = [ all = [
"python-pptx", "python-pptx",
"mammoth", "mammoth~=1.10.0",
"pandas", "pandas",
"openpyxl", "openpyxl",
"xlrd", "xlrd",

View File

@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2024-present Adam Fourney <adamfo@microsoft.com> # SPDX-FileCopyrightText: 2024-present Adam Fourney <adamfo@microsoft.com>
# #
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
__version__ = "0.1.2" __version__ = "0.1.3"

View File

@@ -1,4 +1,6 @@
import sys import sys
import io
from warnings import warn
from typing import BinaryIO, Any from typing import BinaryIO, Any
@@ -13,6 +15,14 @@ from .._exceptions import MissingDependencyException, MISSING_DEPENDENCY_MESSAGE
_dependency_exc_info = None _dependency_exc_info = None
try: try:
import mammoth import mammoth
import mammoth.docx.files
def mammoth_files_open(self, uri):
warn("DOCX: processing of r:link resources (e.g., linked images) is disabled.")
return io.BytesIO(b"")
mammoth.docx.files.Files.open = mammoth_files_open
except ImportError: except ImportError:
# Preserve the error and stack trace for later # Preserve the error and stack trace for later
_dependency_exc_info = sys.exc_info() _dependency_exc_info = sys.exc_info()