Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow to override title property on link parsing #237

Merged
merged 2 commits into from
Mar 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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