Skip to content

Commit 7a4f545

Browse files
committed
HTML preview
1 parent 9846aa7 commit 7a4f545

File tree

8 files changed

+94
-5
lines changed

8 files changed

+94
-5
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,11 @@
241241
"yarn-deduplicate": "^3.1.0"
242242
},
243243
"dependencies": {
244+
"@fortawesome/fontawesome-svg-core": "^1.2.35",
245+
"@fortawesome/free-brands-svg-icons": "^5.15.3",
246+
"@fortawesome/free-regular-svg-icons": "^5.15.3",
247+
"@fortawesome/free-solid-svg-icons": "^5.15.3",
248+
"@fortawesome/react-fontawesome": "^0.1.14",
244249
"@tailwindcss/typography": "^0.4.1",
245250
"caniuse-lite": "^1.0.30001246",
246251
"dayjs": "^1.10.6",

src/App.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
} from 'react-router-dom';
88
import Main from './components/Main';
99
import './App.global.css';
10+
import './helpers/fontAwesome';
1011

1112
export default function App() {
1213
return (

src/components/Main.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
11
import React from 'react';
22
import { NavLink, Route } from 'react-router-dom';
3+
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
34
import MarkdownToHtml from './md-to-html/MarkdownToHtml';
45
import UnixTimestamp from './unix-timestamp/UnixTimestamp';
6+
import HtmlPreview from './html-preview/HtmlPreview';
57

68
const Main = () => {
79
const routes = [
810
{
11+
icon: <FontAwesomeIcon icon="clock" />,
912
path: '/unix',
1013
name: 'Unix Time Converter',
1114
Component: UnixTimestamp,
1215
},
1316
{
17+
icon: <FontAwesomeIcon icon={['fab', 'markdown']} />,
1418
path: '/md-to-html',
1519
name: 'Markdown to HTML',
1620
Component: MarkdownToHtml,
1721
},
22+
{
23+
icon: <FontAwesomeIcon icon={['fab', 'html5']} />,
24+
path: '/html-preview',
25+
name: 'HTML Preview',
26+
Component: HtmlPreview,
27+
},
1828
];
1929

2030
return (
@@ -28,13 +38,14 @@ const Main = () => {
2838
aria-orientation="horizontal"
2939
aria-labelledby="options-menu"
3040
>
31-
{routes.map(({ path, name }) => (
41+
{routes.map(({ path, name, icon }) => (
3242
<NavLink
3343
to={path}
3444
key={path}
35-
className="block rounded-lg px-3 py-1 mb-1"
45+
className="rounded-lg px-3 py-1 mb-1 space-x-1 items-center justify-start flex"
3646
activeClassName="bg-blue-400 text-white"
3747
>
48+
<span className="w-6">{icon}</span>
3849
{name}
3950
</NavLink>
4051
))}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* eslint-disable react/no-danger */
2+
import React, { useState } from 'react';
3+
4+
const HtmlPreview = () => {
5+
const [html, setHtml] = useState(
6+
'<h1>Hello</h1>\n<quote>This is a quote</quote>'
7+
);
8+
9+
const handleChange = (evt: { target: { value: string } }) =>
10+
setHtml(evt.target.value);
11+
12+
return (
13+
<div className="flex min-h-full">
14+
<textarea
15+
onChange={handleChange}
16+
className="flex-1 min-h-full bg-white p-4"
17+
value={html}
18+
/>
19+
<div className="mx-1" />
20+
<section
21+
className="flex-1 min-h-full bg-blue-50 p-4 prose"
22+
dangerouslySetInnerHTML={{ __html: html }}
23+
/>
24+
</div>
25+
);
26+
};
27+
28+
export default HtmlPreview;

src/components/md-to-html/MarkdownToHtml.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable react/no-danger */
21
import React, { useState } from 'react';
32
import marked from 'marked';
43

@@ -12,12 +11,12 @@ const Md2Html = () => {
1211
<div className="flex min-h-full">
1312
<textarea
1413
onChange={handleChange}
15-
className="flex-1 min-h-full bg-white p-4 whitespace-pre"
14+
className="flex-1 min-h-full bg-white p-4"
1615
value={md}
1716
/>
1817
<div className="mx-1" />
1918
<textarea
20-
className="flex-1 min-h-full bg-blue-100 p-4 whitespace-pre"
19+
className="flex-1 min-h-full bg-blue-100 p-4"
2120
value={marked(md)}
2221
disabled
2322
/>

src/components/qrcode/QrCode.tsx

Whitespace-only changes.

src/helpers/fontAwesome.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { library } from '@fortawesome/fontawesome-svg-core';
2+
import { fab, faMarkdown, faHtml5 } from '@fortawesome/free-brands-svg-icons';
3+
import { faClock } from '@fortawesome/free-solid-svg-icons';
4+
5+
library.add(fab, faMarkdown, faClock, faHtml5);

yarn.lock

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,46 @@
11671167
minimatch "^3.0.4"
11681168
strip-json-comments "^3.1.1"
11691169

1170+
"@fortawesome/fontawesome-common-types@^0.2.35":
1171+
version "0.2.35"
1172+
resolved "https://registry.yarnpkg.com/@fortawesome/fontawesome-common-types/-/fontawesome-common-types-0.2.35.tgz#01dd3d054da07a00b764d78748df20daf2b317e9"
1173+
integrity sha512-IHUfxSEDS9dDGqYwIW7wTN6tn/O8E0n5PcAHz9cAaBoZw6UpG20IG/YM3NNLaGPwPqgjBAFjIURzqoQs3rrtuw==
1174+
1175+
"@fortawesome/fontawesome-svg-core@^1.2.35":
1176+
version "1.2.35"
1177+
resolved "https://registry.yarnpkg.com/@fortawesome/fontawesome-svg-core/-/fontawesome-svg-core-1.2.35.tgz#85aea8c25645fcec88d35f2eb1045c38d3e65cff"
1178+
integrity sha512-uLEXifXIL7hnh2sNZQrIJWNol7cTVIzwI+4qcBIq9QWaZqUblm0IDrtSqbNg+3SQf8SMGHkiSigD++rHmCHjBg==
1179+
dependencies:
1180+
"@fortawesome/fontawesome-common-types" "^0.2.35"
1181+
1182+
"@fortawesome/free-brands-svg-icons@^5.15.3":
1183+
version "5.15.3"
1184+
resolved "https://registry.yarnpkg.com/@fortawesome/free-brands-svg-icons/-/free-brands-svg-icons-5.15.3.tgz#bec2821d23b9c667be1d192a6c5bfb2667e588eb"
1185+
integrity sha512-1hirPcbjj72ZJtFvdnXGPbAbpn3Ox6mH3g5STbANFp3vGSiE5u5ingAKV06mK6ZVqNYxUPlh4DlTnaIvLtF2kw==
1186+
dependencies:
1187+
"@fortawesome/fontawesome-common-types" "^0.2.35"
1188+
1189+
"@fortawesome/free-regular-svg-icons@^5.15.3":
1190+
version "5.15.3"
1191+
resolved "https://registry.yarnpkg.com/@fortawesome/free-regular-svg-icons/-/free-regular-svg-icons-5.15.3.tgz#1ec4f2410ff638db549c5c5484fc60b66407dbe6"
1192+
integrity sha512-q4/p8Xehy9qiVTdDWHL4Z+o5PCLRChePGZRTXkl+/Z7erDVL8VcZUuqzJjs6gUz6czss4VIPBRdCz6wP37/zMQ==
1193+
dependencies:
1194+
"@fortawesome/fontawesome-common-types" "^0.2.35"
1195+
1196+
"@fortawesome/free-solid-svg-icons@^5.15.3":
1197+
version "5.15.3"
1198+
resolved "https://registry.yarnpkg.com/@fortawesome/free-solid-svg-icons/-/free-solid-svg-icons-5.15.3.tgz#52eebe354f60dc77e0bde934ffc5c75ffd04f9d8"
1199+
integrity sha512-XPeeu1IlGYqz4VWGRAT5ukNMd4VHUEEJ7ysZ7pSSgaEtNvSo+FLurybGJVmiqkQdK50OkSja2bfZXOeyMGRD8Q==
1200+
dependencies:
1201+
"@fortawesome/fontawesome-common-types" "^0.2.35"
1202+
1203+
"@fortawesome/react-fontawesome@^0.1.14":
1204+
version "0.1.14"
1205+
resolved "https://registry.yarnpkg.com/@fortawesome/react-fontawesome/-/react-fontawesome-0.1.14.tgz#bf28875c3935b69ce2dc620e1060b217a47f64ca"
1206+
integrity sha512-4wqNb0gRLVaBm/h+lGe8UfPPivcbuJ6ecI4hIgW0LjI7kzpYB9FkN0L9apbVzg+lsBdcTf0AlBtODjcSX5mmKA==
1207+
dependencies:
1208+
prop-types "^15.7.2"
1209+
11701210
"@istanbuljs/load-nyc-config@^1.0.0":
11711211
version "1.1.0"
11721212
resolved "https://registry.yarnpkg.com/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz#fd3db1d59ecf7cf121e80650bb86712f9b55eced"

0 commit comments

Comments
 (0)