aboutsummaryrefslogtreecommitdiff
path: root/mammoth
diff options
context:
space:
mode:
Diffstat (limited to 'mammoth')
-rw-r--r--mammoth/__init__.py10
-rw-r--r--mammoth/zips.py2
2 files changed, 11 insertions, 1 deletions
diff --git a/mammoth/__init__.py b/mammoth/__init__.py
index 297cf24..7735fcf 100644
--- a/mammoth/__init__.py
+++ b/mammoth/__init__.py
@@ -1,5 +1,6 @@
from . import docx, conversion, options, images, underline
from .raw_text import extract_raw_text_from_element
+from .docx.style_map import write_style_map, read_style_map
__all__ = ["convert_to_html", "extract_raw_text", "images", "underline"]
@@ -15,6 +16,8 @@ def convert_to_markdown(*args, **kwargs):
def convert(fileobj, transform_document=None, id_prefix=None, **kwargs):
if transform_document is None:
transform_document = lambda x: x
+ if kwargs.get("style_map") is None:
+ kwargs["style_map"] = read_style_map(fileobj)
return options.read_options(kwargs).bind(lambda convert_options:
docx.read(fileobj).map(transform_document).bind(lambda document:
conversion.convert_document_element_to_html(
@@ -28,3 +31,10 @@ def convert(fileobj, transform_document=None, id_prefix=None, **kwargs):
def extract_raw_text(fileobj):
return docx.read(fileobj).map(extract_raw_text_from_element)
+
+
+def embed_style_map(fileobj, style_map):
+ write_style_map(fileobj, style_map)
+
+def read_embedded_style_map(fileobj):
+ return read_style_map(fileobj)
diff --git a/mammoth/zips.py b/mammoth/zips.py
index 432be5d..4d77acb 100644
--- a/mammoth/zips.py
+++ b/mammoth/zips.py
@@ -42,7 +42,7 @@ def update_zip(fileobj, files):
names = set(source.namelist()) | set(files.keys())
for name in names:
if name in files:
- contents = files[name]
+ contents = files[name].encode("utf8")
else:
contents = source.read(name)
destination.writestr(name, contents)