This repository has been archived by the owner on Mar 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
App.js
63 lines (54 loc) · 1.59 KB
/
App.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
import React, { Component } from 'react';
import { Editor as $Editor, Plain } from 'slate';
import styled from 'styled-components';
let MarkdownPlugin;
if (process.env.NODE === 'production') {
MarkdownPlugin = require('slate-markdown').default;
} else {
MarkdownPlugin = require('../../dist/index.js').default;
}
const Wrapper = styled.div`
max-width: 35em;
margin: 0 auto;
`;
const Editor = styled($Editor)`
background-color: #FFF;
padding: 1em;
width: 100%;
height: 100%;
line-height: 1.5em;
`;
class App extends Component {
constructor(props) {
super(props);
// Create markdown plugin
const markdown = MarkdownPlugin();
this.state = {
state: Plain.deserialize(
'# slate-markdown\nAdd **live markdown preview** to your Slate editor.\n## Usage\n### Installation\n`npm install slate-markdown`\n### Demo\nThis is a [Slate editor](https://slatejs.org) with the plugin enabled, try typing some markdown in here!\n## Links\n- Contribute on [GitHub](https://github.com/withspectrum/slate-markdown)\n- Made by the folks at [Spectrum](https://spectrum.chat)'
),
plugins: [markdown],
};
}
onChange = state => {
this.setState({
state,
});
};
render() {
const { state, plugins } = this.state;
return (
<Wrapper>
<Editor
state={state}
plugins={plugins}
onChange={this.onChange}
sizes={['2em', '1.5874em', '1.2599em', '1em', '1em']}
placeholder={'You can write markdown here! (try "## Hello")'}
autoFocus
/>
</Wrapper>
);
}
}
export default App;