-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
119 lines (111 loc) · 5.49 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>React Markup</title>
<link rel="stylesheet" href="styles.css" />
<!-- font awesome -->
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css"
integrity="sha512-9usAa10IRO0HhonpyAIVpjrylPvoDwiPUiKdWk5t3PyolY1cOd4DSE0Ga+ri4AuTroPR5aQvXU9xC6qOPnzFeg=="
crossorigin="anonymous"
referrerpolicy="no-referrer"
/>
<!-- React -->
<script
crossorigin
src="https://unpkg.com/react@17/umd/react.development.js"
></script>
<script
crossorigin
src="https://unpkg.com/react-dom@17/umd/react-dom.development.js"
></script>
<!-- Babel -->
<script
src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"
integrity="sha512-kp7YHLxuJDJcOzStgd6vtpxr4ZU9kjn77e6dBsivSz+pUuAuMlE2UTdKB7jjsWT84qbS8kdCWHPETnP/ctrFsA=="
crossorigin="anonymous"
referrerpolicy="no-referrer"
></script>
<!-- Marked -->
<script
src="https://cdnjs.cloudflare.com/ajax/libs/marked/4.0.2/marked.min.js"
integrity="sha512-hzyXu3u+VDu/7vpPjRKFp9w33Idx7pWWNazPm+aCMRu26yZXFCby1gn1JxevVv3LDwnSbyKrvLo3JNdi4Qx1ww=="
crossorigin="anonymous"
referrerpolicy="no-referrer"
></script>
</head>
<body>
<!-- body -->
<div id="app"></div>
<!-- create a react script -->
<script type="text/babel">
var basic = `
body{word-break: break-all; padding: 10px 20px; font-family: system-ui;}
h1{border-bottom: 2px solid;}
h2,h3{border-bottom: 1px solid;}
h4,h5,h6{border-bottom: 1px dotted;}
pre{background: bisque;padding: 10px;border-radius: 5px;}
pre code{background: transparent;padding: 0;}
code{background: wheat;padding: 3px;}
img{max-width: 100%;}
`,
table = `
table{border:1px solid; border-collapse: collapse;border-spacing: 0;}
th{font-weight: 600;padding: 6px 13px;border: 1px solid;text-align: left;}
td{padding: 6px 13px; border: 1px solid;}
`,
blockquote = `
blockquote {border-left: 3px solid;padding: 0px 15px;}
`;
// for staters
// let iframe = document.getElementById("output-frame");
// iframe.src =
// "data:text/html;charset=utf-8,%3Ch1%20id=%22welcome-to-my-react-markdown-previewer%22%3EWelcome%20to%20my%20React%20Markdown%20Previewer!%3C/h1%3E%0A%3Ch2%20id=%22this-is-a-sub-heading%22%3EThis%20is%20a%20sub-heading...%3C/h2%3E%0A%3Ch3%20id=%22and-heres%22%3EAnd%20heres%3C/h3%3E%0A%3Cstyle%3E%0A%20%20%20%20%20%20%20%20body%7Bword-break:%20break-all;%7D%0A%20%20%20%20%20%20%20%20h1%7Bborder-bottom:%202px%20solid;%7D%0A%20%20%20%20%20%20%20%20h2,h3%7Bborder-bottom:%201px%20solid;%7D%0A%20%20%20%20%20%20%20%20h4,h5,h6%7Bborder-bottom:%201px%20dotted;%7D%0A%20%20%20%20%20%20%20%20%3C/style%3E";
function previewData() {
var editor = document
.getElementById("editor")
.value.replaceAll("'", "'"),
iframe = document.getElementById("output-frame"),
parse = marked.parse(editor);
iframe.src =
"data:text/html;charset=utf-8," +
encodeURI(
parse + "<style>" + basic + table + blockquote + "</style>"
);
}
// create a react component
function App() {
return (
<div id="container" className="row">
<div id="markdown_editor">
<textarea
name="editor"
id="editor"
onChange={previewData}
className="editor"
></textarea>
</div>
<div id="preview">
{/* preview data using iframe */}
<iframe
id="output-frame"
src="data:text/html;charset=utf-8,%3Cstyle%3E%0A%20%20%20%20%20%20%20%20body%7Bword-break:%20break-all;%20padding:%2010px%2020px;%20font-family:%20system-ui;%7D%0A%20%20%20%20%20%20%20%20h1%7Bborder-bottom:%202px%20solid;%7D%0A%20%20%20%20%20%20%20%20h2,h3%7Bborder-bottom:%201px%20solid;%7D%0A%20%20%20%20%20%20%20%20h4,h5,h6%7Bborder-bottom:%201px%20dotted;%7D%0A%20%20%20%20%20%20%20%20pre%7Bbackground:%20bisque;padding:%2010px;border-radius:%205px;%7D%0A%20%20%20%20%20%20%20%20pre%20code%7Bbackground:%20transparent;padding:%200;%7D%0A%20%20%20%20%20%20%20%20code%7Bbackground:%20wheat;padding:%203px;%7D%0A%20%20%20%20%20%20%20%20img%7Bmax-width:%20100%25;%7D%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20table%7Bborder:1px%20solid;%20border-collapse:%20collapse;border-spacing:%200;%7D%0A%20%20%20%20%20%20%20%20%20%20th%7Bfont-weight:%20600;padding:%206px%2013px;border:%201px%20solid;text-align:%20left;%7D%0A%20%20%20%20%20%20%20%20%20%20td%7Bpadding:%206px%2013px;%20border:%201px%20solid;%7D%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20blockquote%20%7Bborder-left:%203px%20solid;padding:%200px%2015px;%7D%0A%20%20%20%20%20%20%20%20%3C/style%3E"
></iframe>
</div>
</div>
);
}
// render the react component
ReactDOM.render(<App />, document.querySelector("#app"));
</script>
<script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>
</body>
</html>
<!--
<div class="markup"></div>
<div class="show-result"></div>
-->