From c998bde2f4a72e5f49ed3a70f5bba077af757643 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20Str=C3=BCbing?= Date: Thu, 28 Feb 2019 10:05:03 +0100 Subject: [PATCH 1/2] add test case for overriding title prop while parsing a link --- index.compiler.spec.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/index.compiler.spec.js b/index.compiler.spec.js index efad811e..080f9371 100644 --- a/index.compiler.spec.js +++ b/index.compiler.spec.js @@ -2833,12 +2833,30 @@ describe('overrides', () => { it('should add props to the appropriate JSX tag if supplied', () => { render( compiler('Hello.\n\n', { - overrides: { p: { props: { className: 'abc' } } }, + overrides: { p: { props: { className: 'abc', title: 'foo' } } }, }) ); expect(root.children[0].className).toBe('abc'); expect(root.children[0].textContent).toBe('Hello.'); + expect(root.children[0].title).toBe('foo'); + }); + + it('should override the title property when parsing a link', () => { + class FakeLink extends React.Component { + render() { + const {title, children} = this.props + return {children} + } + } + + render( + compiler('[link](https://example.org)', { + overrides: { a: {component: FakeLink, props: { title: 'foo' } } }, + }) + ); + + expect(root.children[0].title).toBe('foo'); }); it('should add props to pre & code tags if supplied', () => { From 8eaa5d573711f4ea2ab551c7ddbb2385a0764df3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20Str=C3=BCbing?= Date: Thu, 28 Feb 2019 11:54:12 +0100 Subject: [PATCH 2/2] allow to override title prop while parsing a link --- index.compiler.spec.js | 2 +- index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/index.compiler.spec.js b/index.compiler.spec.js index 080f9371..339c7df7 100644 --- a/index.compiler.spec.js +++ b/index.compiler.spec.js @@ -2984,8 +2984,8 @@ describe('overrides', () => { expect($element.outerHTML).toMatchInlineSnapshot(` diff --git a/index.js b/index.js index 7f95486a..14398ac3 100644 --- a/index.js +++ b/index.js @@ -727,8 +727,8 @@ export function compiler(markdown, options) { return createElementFn( getTag(tag, options.overrides), { - ...overrideProps, ...props, + ...overrideProps, className: cx(props && props.className, overrideProps.className) || undefined, },