30
loading...
This website collects cookies to deliver better user experience
remarkable
and also tailwind
cdn. Remarkable library includes a Markdown component that converts Markdown to HTML. It's very simple, nice and easy so let's get started!!!npx create-react-app react-markdown
remarkable
:npm install remarkable
public/index.html
and add this:<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.15/tailwind.min.css" referrerpolicy="no-referrer">
app.js
, delete everything and paste this:import { useState } from "react";
import { Remarkable } from "remarkable";
const md = new Remarkable();
function App() {
const [text, setText] = useState("");
return (
<>
<main className="p-5 md:max-w-4xl md:mx-auto">
<h1 className="text-gray-900 text-4xl text-center font-bold">
markdown editor
</h1>
<article>
<label htmlFor="markdown" className="mt-5 mb-3 block">
type in some markdown</label>
<textarea
name="textarea"
id="markdown"
cols="30"
rows="10"
required
placeholder="type in some markdown"
className="bg-white p-5 rounded shadow w-full"
></textarea>
<h3>output</h3>
<div></div>
</article>
</main>
</>
);
}
export default App;
app.js
the next thing we want to work on is getting the input and displaying it on the outputtextarea
let's add a value prop:value={text}
onchange
event handler.onChange={(e)=>setText(e.target.value)}
div
in the output part, add this:dangerouslySetInnerHTML={{__html:md.render(text)}}
div
with this:<div dangerouslySetInnerHTML={{__html:md.render(text)}}></div>
render
method is coming from the remarkable package that we imported and initializedindex.css
and paste this into our body
:background-color: #68e0e0;
CSS
codesh1, h2, h3, h4 , h5 , h6 {
font-weight: bold;
}
h1{
font-size: 36px;
}
h2{
font-size: 32px;
}
h3{
font-size:28;
}
h4{
font-size: 24px;
}
h5{
font-size: 20px;
}
h6{
font-size: 16px;
}
a{
color: blue;
text-decoration: underline;
}
npm start