artemgh
artemgh

Reputation: 103

React parse text to html markup

I use React JS, and I want to make a universal component, to show message for user. Like as at image: enter image description here

I want to send text like as this : "Lorem ipsum ["Link"](url) Lorem ipsum **Strong text**". How I may parse this with JavaScript? I can imagine how to implement this, but I would not like to reinvent my wheel, maybe there are some ready-made and elegant solutions?

Upvotes: 0

Views: 990

Answers (1)

pigrammer
pigrammer

Reputation: 3489

What you need is a Markdown component for React. Try react-markdown:

import React from 'react';
import ReactDom from 'react-dom';
import ReactMarkdown from 'react-markdown';
ReactDom.render(
    <ReactMarkdown>
        Lorem ipsum [link](url) <br />
        Lorem ipsum **Strong text**
    </ReactMarkdown>,
    yourElement
)

Upvotes: 1

Related Questions