Skip to content

Commit

Permalink
fix(text): remove margin from wrapping elements (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
redgeoff authored Sep 23, 2021
1 parent 4cbe3b8 commit 28f426c
Showing 1 changed file with 6 additions and 16 deletions.
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;

0 comments on commit 28f426c

Please sign in to comment.