This repository has been archived by the owner on Nov 4, 2019. It is now read-only.
forked from quantizor/markdown-to-jsx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
site.js
272 lines (226 loc) · 5.76 KB
/
site.js
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
import { lighten, rgba } from 'polished';
import styled, { css, injectGlobal } from 'preact-emotion';
import React from 'react';
import ReactDOM from 'react-dom';
import Markdown from './';
class TryItLive extends React.PureComponent {
state = {markdown: document.getElementById('sample-content').textContent.trim()}
updateState = (e) => this.setState({markdown: e.target.value})
render () {
return (
<main>
<Header>
<a
target='_blank'
href='https://github.com/probablyup/markdown-to-jsx'
title='Check out the markdown-to-jsx source code'
rel='noopener noreferrer'>
<img src='./images/logo.svg' alt='markdown-to-jsx logo' />
</a>
<Description>
<h1><code>markdown-to-jsx</code> is an easy-to-use markdown component that takes Github-flavored Markdown (GFM) and makes native JSX without dangerous hacks. </h1><h2>It's lightweight, customizable, and happily supports React-like libraries.</h2>
</Description>
<LearnMore>
See the <a target='_blank' href='https://github.com/probablyup/markdown-to-jsx/blob/master/README.md' rel='noopener noreferrer'>project README</a> for detailed installation & usage instructions.
</LearnMore>
</Header>
<Demo>
<Textarea
onInput={this.updateState}
value={this.state.markdown} />
<Compiled>
<Markdown options={options}>
{this.state.markdown}
</Markdown>
</Compiled>
</Demo>
</main>
);
}
}
const COLOR_ACCENT = 'rgba(0, 0, 0, 0.5)';
const COLOR_BODY = '#444';
const spectrum = [
'253, 128, 129',
'253, 178, 131',
'254, 232, 134',
];
const bands = spectrum.length;
const width = 100 / bands;
const transparent = spectrum.map((band, index) => `rgba(${band}, ${index === 0 ? 0.5 : 0.5 / index}) ${index * width * .8}%`).join(', ') + ', transparent 100%';
injectGlobal`
*,
*::before,
*::after {
box-sizing: border-box;
outline-color: ${COLOR_ACCENT};
}
html,
body,
#root,
main {
margin: 0;
min-height: 100vh;
}
html {
background: linear-gradient(to bottom, ${transparent}) no-repeat;
background-size: 100% 100vh;
color: ${COLOR_BODY};
font-family: 'Source Sans Pro', Helvetica Neue, Helvetica, sans-serif;
font-size: 14px;
line-height: 1.5;
}
h1,
h2,
h3,
h4,
h5,
h6 {
margin: 0 0 1rem;
}
h1 {
font-size: 2rem;
}
h2 {
font-size: 1.8rem;
}
h3 {
font-size: 1.6rem;
}
h4 {
font-size: 1.4rem;
}
h5 {
font-size 1.2rem;
}
h6 {
font-size: 1rem;
}
a {
color: ${COLOR_ACCENT};
transition: color 200ms ease;
&:hover,
&:focus {
color: ${rgba(COLOR_ACCENT, 0.75)};
}
}
code {
background: ${rgba(COLOR_ACCENT, 0.05)};
display: inline-block;
padding: 0 2px;
}
pre code {
background: transparent;
border: 0;
display: block;
padding: 1em;
}
main {
display: flex;
flex-direction: column;
padding: 3rem 1.5rem 0;
margin: 0;
@media all and (min-width: 1024px) {
padding: 3rem;
}
}
`;
const Header = styled.header`
flex-shrink: 0;
margin-bottom: 2em;
text-align: center;
img {
height: 100px;
}
`;
const Description = styled.p`
font-size: 18px;
margin-left: auto;
margin-right: auto;
max-width: 60vw;
h1,
h2 {
font: inherit;
}
@media all and (max-width: 500px) {
max-width: none;
}
@media all and (max-width: 1023px) {
h1,
h2 {
display: block;
margin-bottom: 1.5rem;
}
}
`;
const LearnMore = styled.p`
color: ${lighten(0.2, COLOR_BODY)};
`;
const sharedCss = css`
flex: 0 0 50%;
padding: 1em;
`;
const Demo = styled.section`
display: flex;
flex-grow: 1;
margin-left: -1.5rem;
margin-right: -1.5rem;
@media all and (min-width: 1024px) {
margin-left: 0;
margin-right: 0;
}
@media all and (max-width: 500px) {
flex-direction: column;
}
`;
const Textarea = styled.textarea`
${sharedCss};
background: ${rgba(COLOR_ACCENT, .05)};
border: 0;
position: sticky;
top: 0;
font-family: 'Source Code Pro', Consolas, Monaco, monospace;
font-size: inherit;
max-height: 100vh;
@media all and (max-width: 500px) {
height: 300px;
position: relative;
}
`;
const Compiled = styled.div`
${sharedCss};
padding-left: 2rem;
padding-right: 1rem;
overflow: auto;
overflow-x: hidden;
`;
const ShinyButton = styled.button`
background: #444;
color: #DDD;
cursor: pointer;
font: inherit;
transition: background 200ms ease;
&:hover,
&:focus {
background: #222;
}
&:active {
background: #000;
}
`;
function MyComponent (props) {
return (
<ShinyButton
{...props}
onClick={function () { alert('Look ma, I\'m a real component!'); }}
/>
);
}
const options = {
overrides: {
MyComponent: {
component: MyComponent,
},
},
};
ReactDOM.render(<TryItLive />, document.getElementById('root'));