Skip to content

Commit 305bb2c

Browse files
committed
Add markdown-editor
1 parent 2037008 commit 305bb2c

File tree

8 files changed

+16987
-0
lines changed

8 files changed

+16987
-0
lines changed

markdown-editor/package-lock.json

Lines changed: 10218 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

markdown-editor/package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "react-markdown-editor",
3+
"version": "0.1.0",
4+
"private": true,
5+
"dependencies": {
6+
"react": "^16.2.0",
7+
"react-dom": "^16.2.0",
8+
"react-scripts": "1.0.17",
9+
"remarkable": "^1.7.1"
10+
},
11+
"scripts": {
12+
"start": "react-scripts start",
13+
"build": "react-scripts build",
14+
"test": "react-scripts test --env=jsdom",
15+
"eject": "react-scripts eject"
16+
}
17+
}

markdown-editor/public/favicon.ico

3.78 KB
Binary file not shown.

markdown-editor/public/index.html

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
6+
<meta name="theme-color" content="#000000">
7+
<!--
8+
manifest.json provides metadata used when your web app is added to the
9+
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
10+
-->
11+
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
12+
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
13+
<!--
14+
Notice the use of %PUBLIC_URL% in the tags above.
15+
It will be replaced with the URL of the `public` folder during the build.
16+
Only files inside the `public` folder can be referenced from the HTML.
17+
18+
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
19+
work correctly both with client-side routing and a non-root public URL.
20+
Learn how to configure a non-root public URL by running `npm run build`.
21+
-->
22+
<title>React App</title>
23+
</head>
24+
<body>
25+
<noscript>
26+
You need to enable JavaScript to run this app.
27+
</noscript>
28+
<div id="root"></div>
29+
<!--
30+
This HTML file is a template.
31+
If you open it directly in the browser, you will see an empty page.
32+
33+
You can add webfonts, meta tags, or analytics to this file.
34+
The build step will place the bundled scripts into the <body> tag.
35+
36+
To begin the development, run `npm start` or `yarn start`.
37+
To create a production bundle, use `npm run build` or `yarn build`.
38+
-->
39+
</body>
40+
</html>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"short_name": "React App",
3+
"name": "Create React App Sample",
4+
"icons": [
5+
{
6+
"src": "favicon.ico",
7+
"sizes": "64x64 32x32 24x24 16x16",
8+
"type": "image/x-icon"
9+
}
10+
],
11+
"start_url": "./index.html",
12+
"display": "standalone",
13+
"theme_color": "#000000",
14+
"background_color": "#ffffff"
15+
}

markdown-editor/src/index.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
body {
2+
font: 14px "Century Gothic", Futura, sans-serif;
3+
margin: 20px;
4+
}

markdown-editor/src/index.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
import './index.css';
4+
import Remarkable from 'remarkable';
5+
6+
class MarkdownEditor extends React.Component {
7+
constructor(props) {
8+
super(props);
9+
this.handleChange = this.handleChange.bind(this);
10+
this.state = {
11+
value: 'Type some *markdown* here!'
12+
};
13+
}
14+
15+
16+
handleChange(e) {
17+
this.setState({
18+
value: e.target.value
19+
});
20+
}
21+
22+
getRawMarkup() {
23+
const md = new Remarkable();
24+
return {__html: md.render(this.state.value)};
25+
}
26+
27+
render() {
28+
return (
29+
<div>
30+
<h3>Input</h3>
31+
<textarea
32+
onChange={this.handleChange}
33+
defaultValue={this.state.value}
34+
/>
35+
<br />
36+
<h3>Output</h3>
37+
<div dangerouslySetInnerHTML={this.getRawMarkup()}></div>
38+
</div>
39+
)
40+
}
41+
}
42+
43+
// ========================================
44+
45+
ReactDOM.render(
46+
<MarkdownEditor />,
47+
document.getElementById('root')
48+
);

0 commit comments

Comments
 (0)