From 77b597fc382bc7674f1e4365825aba70814577f4 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Tue, 7 Jan 2014 22:45:25 +0000 Subject: Read default style map once --- mammoth/__init__.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/mammoth/__init__.py b/mammoth/__init__.py index 3c726d6..84849ce 100644 --- a/mammoth/__init__.py +++ b/mammoth/__init__.py @@ -4,10 +4,16 @@ from . import docx, conversion, style_reader, lists def convert_to_html(fileobj, style_map=None, convert_image=None): if style_map is None: - style_map = _default_styles + style_map = _default_style_map + else: + style_map = _read_style_map(style_map) return docx.read(fileobj).bind(lambda document: - conversion.convert_document_element_to_html(document, styles=_read_style_map(style_map), convert_image=convert_image) + conversion.convert_document_element_to_html( + document, + styles=style_map, + convert_image=convert_image, + ) ) @@ -17,7 +23,7 @@ def _read_style_map(style_text): -_default_styles = """ +_default_style_map = _read_style_map(""" p.Heading1 => h1:fresh p.Heading2 => h2:fresh p.Heading3 => h3:fresh @@ -32,4 +38,4 @@ p:ordered-list(2) => ul|ol > li > ol > li:fresh p:ordered-list(3) => ul|ol > li > ul|ol > li > ol > li:fresh p:ordered-list(4) => ul|ol > li > ul|ol > li > ul|ol > li > ol > li:fresh p:ordered-list(5) => ul|ol > li > ul|ol > li > ul|ol > li > ul|ol > li > ol > li:fresh -""" +""") -- cgit v1.2.3