fix(editor-component-image): fix null on empty markdown image alt (#1778)

This commit is contained in:
Leonardo Dino 2018-10-26 14:00:11 -04:00 committed by Shawn Erquhart
parent 87768ee2c8
commit 9b72419096
3 changed files with 6 additions and 3 deletions

View File

@ -71,7 +71,8 @@ exports[`Markdown Preview renderer Markdown rendering General should render mark
<p><a href=\\"http://google.com\\">link title</a></p>
<h5>H5</h5>
<p>![alt text](https://pbs.twimg.com/profile_images/678903331176214528/TQTdqGwD.jpg)</p>
<h6>H6</h6>",
<h6>H6</h6>
<p>![](https://pbs.twimg.com/profile_images/678903331176214528/TQTdqGwD.jpg)</p>",
}
}
/>

View File

@ -33,6 +33,8 @@ Text with **bold** & _em_ elements
![alt text](https://pbs.twimg.com/profile_images/678903331176214528/TQTdqGwD.jpg)
###### H6
![](https://pbs.twimg.com/profile_images/678903331176214528/TQTdqGwD.jpg)
`;
expect(
renderer.create(<MarkdownPreview value={markdownToHtml(value)} />).toJSON(),

View File

@ -15,8 +15,8 @@ export default function remarkImagesToText() {
child.children.length === 1 &&
child.children[0].type === 'image'
) {
const { alt = '', url = '', title = '' } = child.children[0];
const value = `![${alt}](${url}${title ? ' title' : ''})`;
const { alt, url } = child.children[0];
const value = `![${alt || ''}](${url || ''})`;
child.children = [{ type: 'text', value }];
}
return child;