mirror of
https://github.com/vale981/recommonmark
synced 2025-03-05 18:11:39 -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 = nodes.image()
|
||||||
img_node['uri'] = mdnode.destination
|
img_node['uri'] = mdnode.destination
|
||||||
|
|
||||||
if mdnode.title:
|
if mdnode.first_child and mdnode.first_child.literal:
|
||||||
img_node['alt'] = mdnode.title
|
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.append(img_node)
|
||||||
self.current_node = img_node
|
self.current_node = img_node
|
||||||
|
|
|
@ -23,7 +23,7 @@ Foo
|
||||||
|
|
||||||
Bar
|
Bar
|
||||||
|
|
||||||

|

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

|

|
||||||
""",
|
""",
|
||||||
"""
|
"""
|
||||||
<?xml version="1.0" ?>
|
<?xml version="1.0" ?>
|
||||||
<document source="<string>">
|
<document source="<string>">
|
||||||
<paragraph>
|
<paragraph>
|
||||||
<image alt="title" uri="/url">foo</image>
|
<image alt="foo "handle quotes"" uri="/url"></image>
|
||||||
</paragraph>
|
</paragraph>
|
||||||
</document>
|
</document>
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -129,7 +129,7 @@ class GenericTests(SphinxIntegrationTests):
|
||||||
def test_image(self):
|
def test_image(self):
|
||||||
output = self.read_file('index.html')
|
output = self.read_file('index.html')
|
||||||
self.assertIn(
|
self.assertIn(
|
||||||
'<p><img alt="Example" src="image.png" />foo</p>',
|
'<p><img alt="foo "handle quotes"" src="image.png" /></p>',
|
||||||
output
|
output
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue