diff options
| author | Michael Williamson <mike@zwobble.org> | 2017-01-23 20:17:18 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2017-01-23 20:17:34 +0000 |
| commit | de55a714711a27207367bc8c5c8370549a9bd219 (patch) | |
| tree | 61765502ea99e740c2a6d1f7ab1391794e5f0e9d /mammoth | |
| parent | cd52af70959fa7a549f2283a36408e5144c19112 (diff) | |
Handle target URIs relative to the base
Diffstat (limited to 'mammoth')
| -rw-r--r-- | mammoth/docx/body_xml.py | 3 | ||||
| -rw-r--r-- | mammoth/zips.py | 7 |
2 files changed, 9 insertions, 1 deletions
diff --git a/mammoth/docx/body_xml.py b/mammoth/docx/body_xml.py index 1fcd567..433d5a2 100644 --- a/mammoth/docx/body_xml.py +++ b/mammoth/docx/body_xml.py @@ -3,6 +3,7 @@ import contextlib from .. import documents from .. import results from .. import lists +from ..zips import uri_to_zip_entry_name from .xmlparser import node_types, XmlElement from .styles_xml import Styles @@ -317,7 +318,7 @@ def _create_reader(numbering, content_types, relationships, styles, docx_file, f return _find_linked_image(link_relationship_id) def _find_embedded_image(relationship_id): - image_path = "word/" + relationships[relationship_id].target.lstrip("/") + image_path = uri_to_zip_entry_name("word", relationships[relationship_id].target) def open_image(): image_file = docx_file.open(image_path) diff --git a/mammoth/zips.py b/mammoth/zips.py index 432be5d..8e09924 100644 --- a/mammoth/zips.py +++ b/mammoth/zips.py @@ -54,3 +54,10 @@ def update_zip(fileobj, files): fileobj.seek(0) destination_fileobj.seek(0) shutil.copyfileobj(destination_fileobj, fileobj) + + +def uri_to_zip_entry_name(base, uri): + if uri.startswith("/"): + return uri[1:] + else: + return base + "/" + uri |
