I am using [email protected]
for syntax highlighting. Below is the code:
import React, { PureComponent } from "react";
import PropTypes from "prop-types";
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
import { docco } from "react-syntax-highlighter/dist/cjs/styles/hljs";
class CodeBlock extends PureComponent {
static propTypes = {
value: PropTypes.string.isRequired,
language: PropTypes.string
};
static defaultProps = {
language: null
};
render() {
const { language, value } = this.props;
return (
<SyntaxHighlighter style={docco}>
{value}
</SyntaxHighlighter>
);
}
}
export default CodeBlock;
<ReactMarkdown source={this.state.post.description} renderers={{CodeBlock}}/>
I expect it to detect the language automatically supplied to it by react-markdown
, but it is not detecting the language and hence the code is not beautified.
What should I do so it starts detecting the language by itself?
I have found the below answer in the documentation of
react-markdown
: