From d6494f9fe0d2265167295c4d813173945fd505cf Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 8 Feb 2015 20:37:45 +0000 Subject: Handle image elements with no alt text in markdown writer --- mammoth/writers/markdown.py | 2 +- tests/writers/markdown_tests.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/mammoth/writers/markdown.py b/mammoth/writers/markdown.py index 4aa73d5..6db4ea9 100644 --- a/mammoth/writers/markdown.py +++ b/mammoth/writers/markdown.py @@ -36,7 +36,7 @@ def _hyperlink(attributes): def _image(attributes): src = attributes.get("src") - alt_text = attributes.get("alt") + alt_text = attributes.get("alt", "") return _WriterOutput("![{0}]({1})".format(alt_text, src), "") diff --git a/tests/writers/markdown_tests.py b/tests/writers/markdown_tests.py index dd25818..94fcd06 100644 --- a/tests/writers/markdown_tests.py +++ b/tests/writers/markdown_tests.py @@ -117,6 +117,13 @@ def image_elements_are_written_as_markdown_images(): writer = _create_writer() writer.self_closing("img", {"src": "http://example.com/image.jpg", "alt": "Alt Text"}) assert_equal("![Alt Text](http://example.com/image.jpg)", writer.as_string()) + + +@istest +def images_are_written_even_if_they_dont_have_alt_text(): + writer = _create_writer() + writer.self_closing("img", {"src": "http://example.com/image.jpg"}) + assert_equal("![](http://example.com/image.jpg)", writer.as_string()) def _create_writer(): -- cgit v1.2.3