diff --git a/recommonmark/parser.py b/recommonmark/parser.py
index 857aded..0046ea6 100644
--- a/recommonmark/parser.py
+++ b/recommonmark/parser.py
@@ -178,8 +178,15 @@ class CommonMarkParser(parsers.Parser):
img_node = nodes.image()
img_node['uri'] = mdnode.destination
- if mdnode.title:
- img_node['alt'] = mdnode.title
+ if mdnode.first_child and mdnode.first_child.literal:
+ content = [mdnode.first_child.literal]
+ n = mdnode.first_child
+ mdnode.first_child.literal = ''
+ mdnode.first_child = mdnode.last_child = None
+ while getattr(n, 'nxt'):
+ n.nxt, n = None, n.nxt
+ content.append(n.literal)
+ img_node['alt'] = ''.join(content)
self.current_node.append(img_node)
self.current_node = img_node
diff --git a/tests/sphinx_generic/index.md b/tests/sphinx_generic/index.md
index 64f21f9..d699b79 100644
--- a/tests/sphinx_generic/index.md
+++ b/tests/sphinx_generic/index.md
@@ -23,7 +23,7 @@ Foo
Bar
-
+
#!/bin/sh
python
diff --git a/tests/test_basic.py b/tests/test_basic.py
index 545c097..798c395 100644
--- a/tests/test_basic.py
+++ b/tests/test_basic.py
@@ -226,13 +226,13 @@ class TestParsing(unittest.TestCase):
def test_image(self):
self.assertParses(
"""
- 
+ 
""",
"""
foo