From bc02b233b7df4b2c907e4cfd29ec372cf4f30a5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20Str=C3=BCbing?= Date: Mon, 11 Mar 2019 19:46:51 +0100 Subject: [PATCH] allow to override title property on link parsing (#237) * add test case for overriding title prop while parsing a link * allow to override title prop while parsing a link --- index.compiler.spec.js | 22 ++++++++++++++++++++-- index.js | 2 +- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/index.compiler.spec.js b/index.compiler.spec.js index efad811e..339c7df7 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', () => { @@ -2966,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, },