From d23efd5811e1ebeae915fdfb2cd8e8ede6b0f0ca Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 8 Feb 2015 20:24:47 +0000 Subject: Ignore anchor tags with no href attribute --- mammoth/writers/markdown.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'mammoth') 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) -- cgit v1.2.3