Skip to content

Commit

Permalink
fixed #19 Cheerio Not Properly Handling Self Enclosed Tags
Browse files Browse the repository at this point in the history
  • Loading branch information
John Gruber authored and rkazakov committed Jun 21, 2018
1 parent b149020 commit c3fd7e7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ module.exports = (html, options) => {
const ampElement = Object.assign(element, {
name: `amp-${element.name}`,
});
$(element).replaceWith(ampElement);
$(element).html($(ampElement).html());
});

return $.html();
Expand Down
8 changes: 8 additions & 0 deletions test/images.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,12 @@ describe('amp-img tag', () => {
{ cwd: __dirname.split(path.sep).pop() },
);
});

test('should not change element order or remove next element', () => {
assert(
'<div><p>1</p><img src="image.png" width="300" height="200"><p>2</p></div>',
'<div><p>1</p><amp-img src="image.png" width="300" height="200"></amp-img><p>2</p></div>',
{ cwd: __dirname.split(path.sep).pop() },
);
});
});

0 comments on commit c3fd7e7

Please sign in to comment.