From d0e31a206af169a8d9b23d1e74ff4f947b1c3ce8 Mon Sep 17 00:00:00 2001 From: Emily Kuo Date: Tue, 4 Aug 2020 15:17:51 -0700 Subject: [PATCH] feat: allow download attr in a-tags --- __tests__/__snapshots__/index.test.js.snap | 2 ++ __tests__/index.test.js | 6 ++++++ components/Anchor.jsx | 1 + index.js | 2 +- 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/__tests__/__snapshots__/index.test.js.snap b/__tests__/__snapshots__/index.test.js.snap index 7136bec91..a1d26265b 100644 --- a/__tests__/__snapshots__/index.test.js.snap +++ b/__tests__/__snapshots__/index.test.js.snap @@ -2,6 +2,8 @@ exports[`anchor target: should allow _blank if using HTML 1`] = `"

test

"`; +exports[`anchor target: should allow download if using HTML 1`] = `"

test

"`; + exports[`anchor target: should default to _self 1`] = `"

test

"`; exports[`anchors 1`] = ` diff --git a/__tests__/index.test.js b/__tests__/index.test.js index 98c063598..ec9a6652f 100644 --- a/__tests__/index.test.js +++ b/__tests__/index.test.js @@ -105,6 +105,12 @@ test('anchor target: should allow _blank if using HTML', () => { expect(mount(markdown.default('test')).html()).toMatchSnapshot(); }); +test('anchor target: should allow download if using HTML', () => { + expect( + mount(markdown.default('test')).html() + ).toMatchSnapshot(); +}); + test('anchors with baseUrl', () => { const wrapper = mount( React.createElement( diff --git a/components/Anchor.jsx b/components/Anchor.jsx index 7eef91046..3ceda52cb 100644 --- a/components/Anchor.jsx +++ b/components/Anchor.jsx @@ -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, diff --git a/index.js b/index.js index 42eab4cef..5fcb1f3ed 100644 --- a/index.js +++ b/index.js @@ -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');