mirror of
https://github.com/vale981/recommonmark
synced 2025-03-04 17:41:38 -05:00
Merge pull request #150 from dandersson/change-image-transformation
Use image description text as "alt", drop title
This commit is contained in:
commit
e23e30c5cf
4 changed files with 13 additions and 6 deletions
|
@ -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
|
||||
|
|
|
@ -23,7 +23,7 @@ Foo
|
|||
|
||||
Bar
|
||||
|
||||

|
||||

|
||||
|
||||
#!/bin/sh
|
||||
python
|
||||
|
|
|
@ -226,13 +226,13 @@ class TestParsing(unittest.TestCase):
|
|||
def test_image(self):
|
||||
self.assertParses(
|
||||
"""
|
||||

|
||||

|
||||
""",
|
||||
"""
|
||||
<?xml version="1.0" ?>
|
||||
<document source="<string>">
|
||||
<paragraph>
|
||||
<image alt="title" uri="/url">foo</image>
|
||||
<image alt="foo "handle quotes"" uri="/url"></image>
|
||||
</paragraph>
|
||||
</document>
|
||||
"""
|
||||
|
|
|
@ -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 "handle quotes"" src="image.png" /></p>',
|
||||
output
|
||||
)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue