diff options
| author | Michael Williamson <mike@zwobble.org> | 2015-08-01 19:08:35 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2015-08-01 19:08:35 +0100 |
| commit | 718bb4be605da81893daec32c63987e8a546b30c (patch) | |
| tree | e2454fb59280467ad2e47834ea8ba85e13bcc8d8 /mammoth | |
| parent | 522c3a75bae2b75a1462652c629e5ecee5931a1a (diff) | |
Add ABC for writers
Diffstat (limited to 'mammoth')
| -rw-r--r-- | mammoth/writers/abc.py | 31 | ||||
| -rw-r--r-- | mammoth/writers/html.py | 4 | ||||
| -rw-r--r-- | mammoth/writers/markdown.py | 4 |
3 files changed, 37 insertions, 2 deletions
diff --git a/mammoth/writers/abc.py b/mammoth/writers/abc.py new file mode 100644 index 0000000..a4a648b --- /dev/null +++ b/mammoth/writers/abc.py @@ -0,0 +1,31 @@ +from __future__ import absolute_import + +import abc + + +class Writer(object): + __metaclass__ = abc.ABCMeta + + @abc.abstractmethod + def text(self, text): + pass + + @abc.abstractmethod + def start(self, name, attributes=None): + pass + + @abc.abstractmethod + def end(self, name): + pass + + @abc.abstractmethod + def self_closing(self, name, attributes=None): + pass + + @abc.abstractmethod + def append(self, html): + pass + + @abc.abstractmethod + def as_string(self): + pass diff --git a/mammoth/writers/html.py b/mammoth/writers/html.py index cf936cd..7e6ca95 100644 --- a/mammoth/writers/html.py +++ b/mammoth/writers/html.py @@ -1,9 +1,11 @@ from __future__ import unicode_literals +from .abc import Writer + import cgi -class HtmlWriter(object): +class HtmlWriter(Writer): def __init__(self): self._fragments = [] diff --git a/mammoth/writers/markdown.py b/mammoth/writers/markdown.py index c291479..6cd9cd0 100644 --- a/mammoth/writers/markdown.py +++ b/mammoth/writers/markdown.py @@ -1,5 +1,7 @@ from __future__ import unicode_literals +from .abc import Writer + import re @@ -149,7 +151,7 @@ def _default_writer(attributes, markdown_state): return _default_output -class MarkdownWriter(object): +class MarkdownWriter(Writer): def __init__(self): self._fragments = [] self._element_stack = [] |
