diff --git a/recommonmark/parser.py b/recommonmark/parser.py index 857aded..e2f4ee9 100644 --- a/recommonmark/parser.py +++ b/recommonmark/parser.py @@ -178,8 +178,9 @@ 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: + img_node['alt'] = mdnode.first_child.literal + mdnode.first_child.literal = '' self.current_node.append(img_node) self.current_node = img_node diff --git a/tests/test_basic.py b/tests/test_basic.py index 545c097..31860c4 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -232,7 +232,7 @@ class TestParsing(unittest.TestCase): - titlefoo + foo """ diff --git a/tests/test_sphinx.py b/tests/test_sphinx.py index 00e2e03..feb4fe7 100644 --- a/tests/test_sphinx.py +++ b/tests/test_sphinx.py @@ -129,7 +129,7 @@ class GenericTests(SphinxIntegrationTests): def test_image(self): output = self.read_file('index.html') self.assertIn( - '

Examplefoo

', + '

foo

', output )