Skip to content

Commit a8e5d88

Browse files
committed
📺 Added Fullscreen Preview
1 parent 229666e commit a8e5d88

File tree

5 files changed

+75
-27
lines changed

5 files changed

+75
-27
lines changed

package-lock.json

+14-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "markdown-editor",
3-
"version": "1.8.1",
3+
"version": "1.9.0",
44
"description": "A react app to preview and edit Markdown",
55
"private": true,
66
"author": {
@@ -20,6 +20,7 @@
2020
"prismjs": "^1.21.0",
2121
"react": "^16.13.1",
2222
"react-dom": "^16.13.1",
23+
"react-full-screen": "^0.3.1",
2324
"react-scripts": "3.4.1",
2425
"react-split": "^2.0.7"
2526
},

src/App.scss

+19-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ body {
4646
padding: 0.4rem 1rem;
4747
font-weight: 600;
4848
border-radius: 0.2rem;
49+
display: inline-block;
50+
line-height: 1.2rem;
4951
color: var(--nav-item-color);
5052
background-color: var(--primary-color);
5153
transition: color, background-color var(--color-transition);
@@ -238,10 +240,19 @@ body {
238240
.html-div {
239241
background-color: var(--body-color);
240242
transition: background-color var(--color-transition);
241-
margin-top: 2rem;
242243
overflow-y: scroll;
244+
max-height: 100%;
245+
}
246+
.preview-fullscreen {
247+
padding: 1rem;
248+
margin-top: 0;
243249
}
244250
}
251+
.fullscreen {
252+
max-height: 100%;
253+
margin-top: 2rem;
254+
padding-bottom: 1rem;
255+
}
245256

246257
.gutter {
247258
height: 100% !important;
@@ -373,6 +384,13 @@ body {
373384
flex-direction: column;
374385
position: relative;
375386
}
387+
.fullscreen {
388+
margin-top: 0;
389+
padding-bottom: 0;
390+
}
391+
#preview {
392+
padding-top: 2rem;
393+
}
376394
.gutter {
377395
height: 10px !important;
378396
width: 100% !important;

src/components/MarkdownEdit.jsx

+10-13
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
import React, { useEffect, useState,useRef } from "react";
1+
import React, { useEffect, useState, useRef } from "react";
22
import Snackbar from "@material-ui/core/Snackbar";
33
import { Alert, AlertTitle } from "@material-ui/lab";
44
import placeholder from "../data/placeholder";
55

66
function MarkdownEdit({ content, changeContent }) {
77
const [open, setOpen] = useState(false);
8-
const editorRef =useRef(null);
8+
const editorRef = useRef(null);
99

1010
useEffect(() => {
11-
if(content===''){
12-
localStorage.setItem("markdown",placeholder);
11+
if (content === "") {
12+
localStorage.setItem("markdown", placeholder);
13+
} else {
14+
localStorage.setItem("markdown", content);
1315
}
14-
else{
15-
localStorage.setItem("markdown",content);
16-
}
17-
}, [content])
16+
}, [content]);
1817

1918
const handleEditorChange = (event) => {
2019
event.preventDefault();
@@ -41,7 +40,7 @@ function MarkdownEdit({ content, changeContent }) {
4140
<h3>Markdown</h3>
4241
<div className="right-section">
4342
<button onClick={handleCopyButton} className="btn">
44-
Copy
43+
Copy
4544
</button>
4645
<button onClick={handleClearButton} className="btn">
4746
Clear
@@ -53,16 +52,14 @@ function MarkdownEdit({ content, changeContent }) {
5352
value={content}
5453
onChange={handleEditorChange}
5554
id="editor"
56-
ref={editorRef}
57-
></textarea>
55+
ref={editorRef}></textarea>
5856

5957
<Snackbar open={open} autoHideDuration={2000} onClose={handleClose}>
6058
<Alert
6159
onClose={handleClose}
6260
severity="success"
6361
elevation={6}
64-
variant="filled"
65-
>
62+
variant="filled">
6663
<AlertTitle>Copied</AlertTitle>
6764
The markdown is copied to your clipboard
6865
</Alert>

src/components/MarkdownPreview.jsx

+30-11
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,51 @@
11
import React, { useState, useEffect } from "react";
22
import * as marked from "marked";
3-
import Prism from 'prismjs';
4-
import '../utils/prism-imports';
3+
import Prism from "prismjs";
4+
import "../utils/prism-imports";
5+
import { FullScreen, useFullScreenHandle } from "react-full-screen";
56
//css for Prism is imported in ThemeSelector
67

78
function MarkdownPreview({ content }) {
89
const [html, setHtml] = useState(getHtml(content));
10+
const handle = useFullScreenHandle();
911

10-
useEffect(()=>{
12+
useEffect(() => {
1113
Prism.highlightAll();
12-
})
14+
});
1315

1416
useEffect(() => {
1517
setHtml(getHtml(content));
1618
}, [content]);
1719

20+
const handleFullScreen = () =>
21+
handle.active ? handle.exit() : handle.enter();
22+
23+
const handleSaveClick = () => {
24+
let link = document.createElement("a");
25+
link.href=`data:text/html,${html}`;
26+
link.download="export.html";
27+
link.click();
28+
};
29+
1830
return (
1931
<div className="markdown-preview scroll">
2032
<div className="section-title">
2133
<h3>Preview</h3>
22-
<a href={`data:text/html,${html}`} download="export.html" className="btn">
23-
Save
24-
</a>
34+
<div className="right-section">
35+
<button className="btn" onClick={handleSaveClick}>
36+
Save
37+
</button>
38+
<button className="btn" onClick={handleFullScreen}>
39+
Fullscreen
40+
</button>
41+
</div>
2542
</div>
26-
<div
27-
id="preview"
28-
className="html-div"
29-
dangerouslySetInnerHTML={{ __html: html }}></div>
43+
<FullScreen handle={handle}>
44+
<div
45+
id="preview"
46+
className={`html-div ${handle.active ? "preview-fullscreen" : ""}`}
47+
dangerouslySetInnerHTML={{ __html: html }}></div>
48+
</FullScreen>
3049
</div>
3150
);
3251
}

0 commit comments

Comments
 (0)