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(text): remove margin from wrapping elements #293

Merged
merged 1 commit into from
Sep 23, 2021
Merged
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
22 changes: 6 additions & 16 deletions src/text.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
import React from 'react';
import attach from './attach';
import Typography from '@material-ui/core/Typography';
import useComponent from './use-component';
import ReactMarkdown from 'react-markdown';

class Text extends React.PureComponent {
render() {
const { text } = this.props;
export default function Text(props) {
const { text } = useComponent(props.component, ['text']);

// We use component=div to force usage of a div, instead of a p, as properly formatted HTML
// cannot nest tags like h1 under a <p>.
return (
<Typography component="div">
<ReactMarkdown source={text} />
</Typography>
);
}
// As per https://github.com/remarkjs/react-markdown/issues/42, `renderers={{paragraph: 'span'}}`
// substitutes the p tag with a span so that there is no margin
return <ReactMarkdown renderers={{ paragraph: 'span' }} source={text} />;
}

Text = attach(['text'])(Text);
export default Text;