-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.babel
More file actions
187 lines (160 loc) · 5.22 KB
/
Copy pathscript.babel
File metadata and controls
187 lines (160 loc) · 5.22 KB
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
// !! IMPORTANT README:
// You may add additional external JS and CSS as needed to complete the project, however the current external resource MUST remain in place for the tests to work. BABEL must also be left in place.
/***********
INSTRUCTIONS:
- Select the project you would
like to complete from the dropdown
menu.
- Click the "RUN TESTS" button to
run the tests against the blank
pen.
- Click the "TESTS" button to see
the individual test cases.
(should all be failing at first)
- Start coding! As you fulfill each
test case, you will see them go
from red to green.
- As you start to build out your
project, when tests are failing,
you should get helpful errors
along the way!
************/
// PLEASE NOTE: Adding global style rules using the * selector, or by adding rules to body {..} or html {..}, or to all elements within body or html, i.e. h1 {..}, has the potential to pollute the test suite's CSS. Try adding: * { color: red }, for a quick example!
// Once you have read the above messages, you can delete all comments.
/* globals marked, Prism, React, ReactDOM */
/* eslint-disable react/prop-types, no-nested-ternary */
// View a more complex version of this project with custom toolbar here:
// https://codepen.io/no_stack_dub_sack/pen/JbPZvm?editors=0110
// coded by @no-stack-dub-sack (github) / @no_stack_sub_sack (Codepen)
// eslint-disable-next-line no-unused-vars
const projectName = 'markdown-previewer';
// ALLOWS LINE BREAKS WITH RETURN BUTTON
marked.setOptions({
breaks: true,
highlight: function (code) {
return Prism.highlight(code, Prism.languages.javascript, 'javascript');
}
});
// INSERTS target="_blank" INTO HREF TAGS (required for Codepen links)
const renderer = new marked.Renderer();
renderer.link = function (href, title, text) {
return `<a target="_blank" href="${href}">${text}</a>`;
};
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
markdown: placeholder,
editorMaximized: false,
previewMaximized: false
};
this.handleChange = this.handleChange.bind(this);
this.handleEditorMaximize = this.handleEditorMaximize.bind(this);
this.handlePreviewMaximize = this.handlePreviewMaximize.bind(this);
}
handleChange(e) {
this.setState({
markdown: e.target.value
});
}
handleEditorMaximize() {
this.setState({
editorMaximized: !this.state.editorMaximized
});
}
handlePreviewMaximize() {
this.setState({
previewMaximized: !this.state.previewMaximized
});
}
render() {
const classes = this.state.editorMaximized
? ['editorWrap maximized', 'previewWrap hide', 'fa fa-compress']
: this.state.previewMaximized
? ['editorWrap hide', 'previewWrap maximized', 'fa fa-compress']
: ['editorWrap', 'previewWrap', 'fa fa-arrows-alt'];
return (
<div>
<div className={classes[0]}>
<Toolbar
icon={classes[2]}
onClick={this.handleEditorMaximize}
text="Editor"
/>
<Editor markdown={this.state.markdown} onChange={this.handleChange} />
</div>
<div className="converter" />
<div className={classes[1]}>
<Toolbar
icon={classes[2]}
onClick={this.handlePreviewMaximize}
text="Previewer"
/>
<Preview markdown={this.state.markdown} />
</div>
</div>
);
}
}
const Toolbar = (props) => {
return (
<div className="toolbar">
<i className="fa fa-free-code-camp" title="no-stack-dub-sack" />
{props.text}
<i className={props.icon} onClick={props.onClick} />
</div>
);
};
const Editor = (props) => {
return (
<textarea
id="editor"
onChange={props.onChange}
type="text"
value={props.markdown}
/>
);
};
const Preview = (props) => {
return (
<div
dangerouslySetInnerHTML={{
__html: marked(props.markdown, { renderer: renderer })
}}
id="preview"
/>
);
};
const placeholder = `# Welcome to my React Markdown Previewer!
## This is a sub-heading...
### And here's some other cool stuff:
Heres some code, \`<div></div>\`, between 2 backticks.
\`\`\`
// this is multi-line code:
function anotherExample(firstLine, lastLine) {
if (firstLine == '\`\`\`' && lastLine == '\`\`\`') {
return multiLineCode;
}
}
\`\`\`
You can also make text **bold**... whoa!
Or _italic_.
Or... wait for it... **_both!_**
And feel free to go crazy ~~crossing stuff out~~.
There's also [links](https://www.freecodecamp.org), and
> Block Quotes!
And if you want to get really crazy, even tables:
Wild Header | Crazy Header | Another Header?
------------ | ------------- | -------------
Your content can | be here, and it | can be here....
And here. | Okay. | I think we get it.
- And of course there are lists.
- Some are bulleted.
- With different indentation levels.
- That look like this.
1. And there are numbered lists too.
1. Use just 1s if you want!
1. And last but not least, let's not forget embedded images:

`;
ReactDOM.render(<App />, document.getElementById('app'));