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

Fix React warning for sourcePosition prop #356

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/renderers.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ function TextRenderer(props) {
function Root(props) {
const useFragment = !props.className
const root = useFragment ? React.Fragment || 'div' : 'div'
return createElement(root, useFragment ? null : props, props.children)
const rootProps = Object.assign(
props.className ? {className: props.className} : {},
getCoreProps(props)
)
return createElement(root, useFragment ? null : rootProps, props.children)
}

function SimpleRenderer(tag, props) {
Expand Down
10 changes: 10 additions & 0 deletions test/__snapshots__/react-markdown.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2054,6 +2054,16 @@ Array [
]
`;

exports[`should not pass on non core props to root 1`] = `
<div
className="test"
>
<h1>
Hello World
</h1>
</div>
`;

exports[`should skip html blocks if skipHtml prop is set (with HTML parser plugin) 1`] = `
Array [
<p>
Expand Down
6 changes: 6 additions & 0 deletions test/react-markdown.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,12 @@ test('should set source position attributes if sourcePos option is enabled', ()
expect(component.toJSON()).toMatchSnapshot()
})

test('should not pass on non core props to root', () => {
const input = '# Hello World'
const component = renderer.create(<Markdown className="test" source={input} rawSourcePos />)
expect(component.toJSON()).toMatchSnapshot()
})

test('should pass on raw source position to non-tag renderers if rawSourcePos option is enabled', () => {
const input = '*Foo*\n\n------------\n\n__Bar__'
const emphasis = props => {
Expand Down