aboutsummaryrefslogtreecommitdiff
path: root/mammoth/cli.py
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-08-09 14:45:32 +0100
committerMichael Williamson <mike@zwobble.org>2026-08-09 14:45:32 +0100
commit32f3d9fae7ad0a4ad7cc9c74d81a6fd670912fbe (patch)
tree42e0fd73b717c05c4ef69e6a64013fdde2fbfe88 /mammoth/cli.py
parent1cac2458ea3c0a68754f1cc86df3aee50b02782b (diff)
Check image content type for backslashes
Diffstat (limited to 'mammoth/cli.py')
-rw-r--r--mammoth/cli.py20
1 files changed, 10 insertions, 10 deletions
diff --git a/mammoth/cli.py b/mammoth/cli.py
index b759412..08b67c6 100644
--- a/mammoth/cli.py
+++ b/mammoth/cli.py
@@ -10,13 +10,13 @@ from . import writers
def main():
args = _parse_args()
-
+
if args.style_map is None:
style_map = None
else:
with open(args.style_map) as style_map_fileobj:
style_map = style_map_fileobj.read()
-
+
with open(args.path, "rb") as docx_fileobj:
if args.output_dir is None:
convert_image = None
@@ -25,7 +25,7 @@ def main():
convert_image = mammoth.images.img_element(ImageWriter(args.output_dir))
output_filename = "{0}.html".format(os.path.basename(args.path).rpartition(".")[0])
output_path = os.path.join(args.output_dir, output_filename)
-
+
result = mammoth.convert(
docx_fileobj,
style_map=style_map,
@@ -35,7 +35,7 @@ def main():
for message in result.messages:
sys.stderr.write(message.message)
sys.stderr.write("\n")
-
+
_write_output(output_path, result.value)
@@ -43,16 +43,16 @@ class ImageWriter(object):
def __init__(self, output_dir):
self._output_dir = output_dir
self._image_number = 1
-
+
def __call__(self, element):
- extension = element.content_type.partition("/")[2]
+ extension = mammoth.images.image_filename_extension(element)
image_filename = "{0}.{1}".format(self._image_number, extension)
with open(os.path.join(self._output_dir, image_filename), "wb") as image_dest:
with element.open() as image_source:
shutil.copyfileobj(image_source, image_dest)
-
+
self._image_number += 1
-
+
return {"src": image_filename}
@@ -76,7 +76,7 @@ def _parse_args():
"path",
metavar="docx-path",
help="Path to the .docx file to convert.")
-
+
output_group = parser.add_mutually_exclusive_group()
output_group.add_argument(
"output",
@@ -86,7 +86,7 @@ def _parse_args():
output_group.add_argument(
"--output-dir",
help="Output directory for generated HTML and images. Images will be stored in separate files. Mutually exclusive with output-path.")
-
+
parser.add_argument(
"--output-format",
required=False,