diff options
| author | Michael Williamson <mike@zwobble.org> | 2015-02-08 20:24:47 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2015-02-08 20:24:47 +0000 |
| commit | d23efd5811e1ebeae915fdfb2cd8e8ede6b0f0ca (patch) | |
| tree | 4f23a938ff1512a2b8deecfa046077dccc35734a /mammoth | |
| parent | 1236e907e724926dedfac0695b1eedbe0acf226f (diff) | |
Ignore anchor tags with no href attribute
Diffstat (limited to 'mammoth')
| -rw-r--r-- | mammoth/writers/markdown.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/mammoth/writers/markdown.py b/mammoth/writers/markdown.py index 66bc9f2..771874c 100644 --- a/mammoth/writers/markdown.py +++ b/mammoth/writers/markdown.py @@ -18,7 +18,10 @@ class _Wrapped(object): def _hyperlink(attributes): href = attributes.get("href", "") - return "[", "]({0})".format(href) + if href: + return "[", "]({0})".format(href) + else: + return _default_output def _init_writers(): @@ -37,7 +40,8 @@ def _init_writers(): _writers = _init_writers() -_default_writer = lambda attributes: ("", "") +_default_output = ("", "") +_default_writer = lambda attributes: _default_output class MarkdownWriter(object): @@ -49,6 +53,9 @@ class MarkdownWriter(object): self._fragments.append(_escape_markdown(text)) def start(self, name, attributes=None): + if attributes is None: + attributes = {} + start, end = _writers.get(name, _default_writer)(attributes) self._fragments.append(start) self._element_stack.append(end) |
