diff options
| author | Michael Williamson <mike@zwobble.org> | 2015-02-07 18:42:15 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2015-02-07 18:42:15 +0000 |
| commit | e0b022e52d720758023bb0248ea0a17a4cbbb822 (patch) | |
| tree | 17f8f979fc59b8375cf4d0a07ff65ab4997dd15f /mammoth | |
| parent | c58934d6e0a9062e5b982a3942d7a034d7ead7f7 (diff) | |
Pass function to create writer into HtmlGenerator
Diffstat (limited to 'mammoth')
| -rw-r--r-- | mammoth/conversion.py | 6 | ||||
| -rw-r--r-- | mammoth/html_generation.py | 9 | ||||
| -rw-r--r-- | mammoth/writers/__init__.py | 4 |
3 files changed, 11 insertions, 8 deletions
diff --git a/mammoth/conversion.py b/mammoth/conversion.py index 61ce17b..3c217e0 100644 --- a/mammoth/conversion.py +++ b/mammoth/conversion.py @@ -5,7 +5,7 @@ from __future__ import unicode_literals import base64 import random -from . import documents, results, html_paths, images +from . import documents, results, html_paths, images, writers from .html_generation import HtmlGenerator, satisfy_html_path @@ -20,8 +20,8 @@ def convert_document_element_to_html(element, if id_prefix is None: id_prefix = str(random.randint(0, 1000000000000000)) - - html_generator = HtmlGenerator() + + html_generator = HtmlGenerator(writers.writer) converter = DocumentConverter(style_map, convert_image=convert_image, convert_underline=convert_underline, diff --git a/mammoth/html_generation.py b/mammoth/html_generation.py index 6dd0b33..a0c35b7 100644 --- a/mammoth/html_generation.py +++ b/mammoth/html_generation.py @@ -1,12 +1,11 @@ from __future__ import unicode_literals -from .writers.html import HtmlWriter - class HtmlGenerator(object): - def __init__(self): + def __init__(self, create_writer): self._stack = [] - self._writer = HtmlWriter() + self._create_writer = create_writer + self._writer = create_writer() def text(self, text): if text: @@ -50,7 +49,7 @@ class HtmlGenerator(object): return self._writer.as_string() def child(self): - return HtmlGenerator() + return HtmlGenerator(self._create_writer) class _Element(object): diff --git a/mammoth/writers/__init__.py b/mammoth/writers/__init__.py index 8b13789..04a64d7 100644 --- a/mammoth/writers/__init__.py +++ b/mammoth/writers/__init__.py @@ -1 +1,5 @@ +from .html import HtmlWriter + +def writer(): + return HtmlWriter() |
