React Markdown doesn't detect links without adding an http/https prefix.
jsximport React from 'react'; import ReactMarkdown from 'react-markdown'; const App = () => { let message = 'Google.com is a link without http/https prefix'; return( // 🔴 Google.com won't be rendered as a link, but as a normal string <ReactMarkdown source = {message}/> ); } export default App;
If you use React Linkify and React Markdown, you'll be able to detect and format links without an http/https prefix.
jsximport React from 'react'; import ReactMarkdown from 'react-markdown'; import Linkify from 'react-linkify'; const App = () => { let message = 'Google.com is a link without http/https prefix'; const linkProperties = {target: '_blank', rel: 'nofollow noopener noreferrer'}; return( // ✅ Now Google will be rendered as a link // ✅ Renderers prop takes each paragraph and places <Linkify></Linkify> <ReactMarkdown source = {message} renderers = {{paragraph: props => <Linkify properties = {linkProperties}> <p>{props.children}</p> </Linkify> }}/> ); } export default App;
Hi, I'm Erik, an engineer from Barcelona. If you like the post or have any comments, say hi.