Merge pull request #150 from dandersson/change-image-transformation

Use image description text as "alt", drop title
This commit is contained in:
Eric Holscher 2019-06-05 15:59:01 -07:00 committed by GitHub
commit e23e30c5cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 6 deletions

View file

@ -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

View file

@ -23,7 +23,7 @@ Foo
Bar
![foo](/image.png "Example")
![foo "handle quotes"](/image.png "Example")
#!/bin/sh
python

View file

@ -226,13 +226,13 @@ class TestParsing(unittest.TestCase):
def test_image(self):
self.assertParses(
"""
![foo](/url "title")
![foo "handle quotes"](/url "title")
""",
"""
<?xml version="1.0" ?>
<document source="&lt;string&gt;">
<paragraph>
<image alt="title" uri="/url">foo</image>
<image alt="foo &quot;handle quotes&quot;" uri="/url"></image>
</paragraph>
</document>
"""

View file

@ -129,7 +129,7 @@ class GenericTests(SphinxIntegrationTests):
def test_image(self):
output = self.read_file('index.html')
self.assertIn(
'<p><img alt="Example" src="image.png" />foo</p>',
'<p><img alt="foo &quot;handle quotes&quot;" src="image.png" /></p>',
output
)