Skip to content

Commit

Permalink
Previewer working. Implemented Marked library
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonio-Riccelli committed Jan 11, 2022
1 parent 35c2f7d commit 87ccec2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<!-- <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script> -->
<title>React App</title>
</head>
<body>
Expand Down
22 changes: 16 additions & 6 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
import React, { useEffect, useState } from 'react'
import './App.css';
import Editor from './Components/Editor/index';
import Previewer from './Components/Previewer/index';

const initialRendering = {
"h1": '<h1>Hello There</h1>'
}
const initialRendering = '# Hello There'


function App() {
// const []
const [editorText, setEditorText] = useState(initialRendering)
const [previewerText, setPreviewerText] = useState(editorText);

function handleChange(e){
console.log(e.target.value);
setEditorText(e.target.value)
}

useEffect(() => {
setPreviewerText(editorText);
},
[editorText]);


return (
<div className="App">
<Editor value={initialRendering} />
<Previewer />
<Editor value={initialRendering} onChange={handleChange} />
<Previewer text={previewerText} />
</div>
);
}
Expand Down
4 changes: 1 addition & 3 deletions src/Components/Editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import React from 'react';

export default function Editor(props) {

console.log(props)
return (
<div>
<textarea id="editor" value={props.value.h1} name="editor" placeholder={props.initialRendering}>

<textarea id="editor" defaultValue={props.value} name="editor" onChange={props.onChange}>
</textarea>
</div>
)
Expand Down
9 changes: 6 additions & 3 deletions src/Components/Previewer/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import React from 'react';
import { marked } from 'marked';

export default function Previewer(props) {
marked.setOptions({
breaks: true,
})

export default function Previewer(props) {

let finalString = marked.parse(props.text)

return (
<section id="preview-wrapper">
<div id="preview">

<div id="preview" dangerouslySetInnerHTML={{__html: finalString}}>
</div>
</section>
)
Expand Down

0 comments on commit 87ccec2

Please sign in to comment.