diff options
| -rw-r--r-- | mammoth/writers/markdown.py | 5 | ||||
| -rw-r--r-- | tests/writers/markdown_tests.py | 7 |
2 files changed, 11 insertions, 1 deletions
diff --git a/mammoth/writers/markdown.py b/mammoth/writers/markdown.py index 5e3cf00..0183423 100644 --- a/mammoth/writers/markdown.py +++ b/mammoth/writers/markdown.py @@ -37,7 +37,10 @@ def _hyperlink(attributes): def _image(attributes): src = attributes.get("src", "") alt_text = attributes.get("alt", "") - return _WriterOutput("".format(alt_text, src), "") + if src or alt_text: + return _WriterOutput("".format(alt_text, src), "") + else: + return _default_output def _init_writers(): diff --git a/tests/writers/markdown_tests.py b/tests/writers/markdown_tests.py index f0e4ba0..e013c7c 100644 --- a/tests/writers/markdown_tests.py +++ b/tests/writers/markdown_tests.py @@ -131,6 +131,13 @@ def images_are_written_even_if_they_dont_have_a_src_attribute(): writer = _create_writer() writer.self_closing("img", {"alt": "Alt Text"}) assert_equal("![Alt Text]()", writer.as_string()) + + +@istest +def image_elements_are_ignored_if_they_have_no_src_and_no_alt_text(): + writer = _create_writer() + writer.self_closing("img") + assert_equal("", writer.as_string()) def _create_writer(): |
