Skip to content

Commit

Permalink
allow to override title property on link parsing (#237)
Browse files Browse the repository at this point in the history
* add test case for overriding title prop while parsing a link

* allow to override title prop while parsing a link
  • Loading branch information
mstruebing authored and quantizor committed Mar 11, 2019
1 parent ac97191 commit bc02b23
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
22 changes: 20 additions & 2 deletions index.compiler.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a title={title}>{children}</a>
}
}

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', () => {
Expand Down Expand Up @@ -2966,8 +2984,8 @@ describe('overrides', () => {
expect($element.outerHTML).toMatchInlineSnapshot(`
<input type="checkbox"
class="foo"
readonly
class="foo"
value="on"
>
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down

0 comments on commit bc02b23

Please sign in to comment.