Skip to content

Commit

Permalink
feat: allow download attr in a-tags (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
emilyskuo authored Aug 4, 2020
1 parent bcfd936 commit 87d8099
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions __tests__/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

exports[`anchor target: should allow _blank if using HTML 1`] = `"<p><a href=\\"https://example.com\\" target=\\"_blank\\" title=\\"\\">test</a></p>"`;
exports[`anchor target: should allow download if using HTML 1`] = `"<p><a download=\\"example.png\\" href=\\"\\" target=\\"_blank\\" title=\\"\\">test</a></p>"`;
exports[`anchor target: should default to _self 1`] = `"<p><a href=\\"https://example.com\\" target=\\"_self\\" title=\\"\\">test</a></p>"`;
exports[`anchors 1`] = `
Expand Down
6 changes: 6 additions & 0 deletions __tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ test('anchor target: should allow _blank if using HTML', () => {
expect(mount(markdown.default('<a href="https://example.com" target="_blank">test</a>')).html()).toMatchSnapshot();
});

test('anchor target: should allow download if using HTML', () => {
expect(
mount(markdown.default('<a download="example.png" href="" target="_blank">test</a>')).html()
).toMatchSnapshot();
});

test('anchors with baseUrl', () => {
const wrapper = mount(
React.createElement(
Expand Down
1 change: 1 addition & 0 deletions components/Anchor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ function Anchor(props) {
Anchor.propTypes = {
baseUrl: PropTypes.string,
children: PropTypes.node.isRequired,
download: PropTypes.string,
href: PropTypes.string,
target: PropTypes.string,
title: PropTypes.string,
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ sanitize.attributes['rdme-embed'] = [
'favicon',
];

sanitize.attributes.a = ['href', 'title', 'class', 'className'];
sanitize.attributes.a = ['href', 'title', 'class', 'className', 'download'];

sanitize.tagNames.push('figure');
sanitize.tagNames.push('figcaption');
Expand Down

0 comments on commit 87d8099

Please sign in to comment.