Skip to content

Commit a003a3d

Browse files
author
- -
committed
update doc
1 parent bf8b680 commit a003a3d

File tree

3 files changed

+255
-226
lines changed

3 files changed

+255
-226
lines changed

README.md

Lines changed: 27 additions & 226 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
[![NPM](https://nodei.co/npm/vue-simplemde.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/vue-simplemde/)
55

6-
# Example
6+
# Demo
77
[Demo Page](https://F-loat.github.io/vue-simplemde/)
88

99
# Use Setup
@@ -41,7 +41,7 @@ export default {
4141
}
4242
```
4343

44-
## Template
44+
## Examples
4545

4646
``` html
4747
<!-- 通过 v-model 控制 value -->
@@ -57,6 +57,18 @@ export default {
5757
``` javascript
5858
// 获取编辑器对象,添加事件绑定
5959
export default {
60+
data () {
61+
return {
62+
content: 'lalala',
63+
configs: {
64+
status: false,
65+
renderingConfig: {
66+
codeSyntaxHighlighting: true, // 开启代码高亮
67+
highlightingTheme: 'atom-one-light' // 自定义代码高亮主题,可选列表(https://github.com/isagalaev/highlight.js/tree/master/src/styles)
68+
}
69+
}
70+
}
71+
},
6072
computed: {
6173
simplemde () {
6274
return this.$refs.markdownEditor.simplemde
@@ -84,240 +96,29 @@ export default {
8496
}
8597
```
8698

87-
## Configuration
88-
89-
- **autoDownloadFontAwesome**: If set to `true`, force downloads Font Awesome (used for icons). If set to `false`, prevents downloading. Defaults to `undefined`, which will intelligently check whether Font Awesome has already been included, then download accordingly.
90-
- **autofocus**: If set to `true`, autofocuses the editor. Defaults to `false`.
91-
- **autosave**: *Saves the text that's being written and will load it back in the future. It will forget the text when the form it's contained in is submitted.*
92-
- **enabled**: If set to `true`, autosave the text. Defaults to `false`.
93-
- **delay**: Delay between saves, in milliseconds. Defaults to `10000` (10s).
94-
- **uniqueId**: You must set a unique string identifier so that SimpleMDE can autosave. Something that separates this from other instances of SimpleMDE elsewhere on your website.
95-
- **blockStyles**: Customize how certain buttons that style blocks of text behave.
96-
- **bold** Can be set to `**` or `__`. Defaults to `**`.
97-
- **code** Can be set to ```` ``` ```` or `~~~`. Defaults to ```` ``` ````.
98-
- **italic** Can be set to `*` or `_`. Defaults to `*`.
99-
- **element**: The DOM element for the textarea to use. Defaults to the first textarea on the page.
100-
- **forceSync**: If set to `true`, force text changes made in SimpleMDE to be immediately stored in original textarea. Defaults to `false`.
101-
- **hideIcons**: An array of icon names to hide. Can be used to hide specific icons shown by default without completely customizing the toolbar.
102-
- **indentWithTabs**: If set to `false`, indent using spaces instead of tabs. Defaults to `true`.
103-
- **initialValue**: If set, will customize the initial value of the editor.
104-
- **insertTexts**: Customize how certain buttons that insert text behave. Takes an array with two elements. The first element will be the text inserted before the cursor or highlight, and the second element will be inserted after. For example, this is the default link value: `["[", "](http://)"]`.
105-
- horizontalRule
106-
- image
107-
- link
108-
- table
109-
- **lineWrapping**: If set to `false`, disable line wrapping. Defaults to `true`.
110-
- **parsingConfig**: Adjust settings for parsing the Markdown during editing (not previewing).
111-
- **allowAtxHeaderWithoutSpace**: If set to `true`, will render headers without a space after the `#`. Defaults to `false`.
112-
- **strikethrough**: If set to `false`, will not process GFM strikethrough syntax. Defaults to `true`.
113-
- **underscoresBreakWords**: If set to `true`, let underscores be a delimiter for separating words. Defaults to `false`.
114-
- **placeholder**: Custom placeholder that should be displayed
115-
- **previewRender**: Custom function for parsing the plaintext Markdown and returning HTML. Used when user previews.
116-
- **promptURLs**: If set to `true`, a JS alert window appears asking for the link or image URL. Defaults to `false`.
117-
- **renderingConfig**: Adjust settings for parsing the Markdown during previewing (not editing).
118-
- **singleLineBreaks**: If set to `false`, disable parsing GFM single line breaks. Defaults to `true`.
119-
- **codeSyntaxHighlighting**: If set to `true`, will highlight using [highlight.js](https://github.com/isagalaev/highlight.js). Defaults to `false`. To use this feature you must include highlight.js on your page. For example, include the script and the CSS files like:<br>`<script src="https://cdn.jsdelivr.net/highlight.js/latest/highlight.min.js"></script>`<br>`<link rel="stylesheet" href="https://cdn.jsdelivr.net/highlight.js/latest/styles/github.min.css">`
120-
- **shortcuts**: Keyboard shortcuts associated with this instance. Defaults to the [array of shortcuts](#keyboard-shortcuts).
121-
- **showIcons**: An array of icon names to show. Can be used to show specific icons hidden by default without completely customizing the toolbar.
122-
- **spellChecker**: If set to `false`, disable the spell checker. Defaults to `true`.
123-
- **status**: If set to `false`, hide the status bar. Defaults to the array of built-in status bar items.
124-
- Optionally, you can set an array of status bar items to include, and in what order. You can even define your own custom status bar items.
125-
- **styleSelectedText**: If set to `false`, remove the `CodeMirror-selectedtext` class from selected lines. Defaults to `true`.
126-
- **tabSize**: If set, customize the tab size. Defaults to `2`.
127-
- **toolbar**: If set to `false`, hide the toolbar. Defaults to the [array of icons](#toolbar-icons).
128-
- **toolbarTips**: If set to `false`, disable toolbar button tips. Defaults to `true`.
129-
130-
```JavaScript
131-
// Most options demonstrate the non-default behavior
132-
var simplemde = new SimpleMDE({
133-
autofocus: true,
134-
autosave: {
135-
enabled: true,
136-
uniqueId: "MyUniqueID",
137-
delay: 1000,
138-
},
139-
blockStyles: {
140-
bold: "__",
141-
italic: "_"
142-
},
143-
element: document.getElementById("MyID"),
144-
forceSync: true,
145-
hideIcons: ["guide", "heading"],
146-
indentWithTabs: false,
147-
initialValue: "Hello world!",
148-
insertTexts: {
149-
horizontalRule: ["", "\n\n-----\n\n"],
150-
image: ["![](http://", ")"],
151-
link: ["[", "](http://)"],
152-
table: ["", "\n\n| Column 1 | Column 2 | Column 3 |\n| -------- | -------- | -------- |\n| Text | Text | Text |\n\n"],
153-
},
154-
lineWrapping: false,
155-
parsingConfig: {
156-
allowAtxHeaderWithoutSpace: true,
157-
strikethrough: false,
158-
underscoresBreakWords: true,
159-
},
160-
placeholder: "Type here...",
161-
previewRender: function(plainText) {
162-
return customMarkdownParser(plainText); // Returns HTML from a custom parser
163-
},
164-
previewRender: function(plainText, preview) { // Async method
165-
setTimeout(function(){
166-
preview.innerHTML = customMarkdownParser(plainText);
167-
}, 250);
168-
169-
return "Loading...";
170-
},
171-
promptURLs: true,
172-
renderingConfig: {
173-
singleLineBreaks: false,
174-
codeSyntaxHighlighting: true,
175-
},
176-
shortcuts: {
177-
drawTable: "Cmd-Alt-T"
178-
},
179-
showIcons: ["code", "table"],
180-
spellChecker: false,
181-
status: false,
182-
status: ["autosave", "lines", "words", "cursor"], // Optional usage
183-
status: ["autosave", "lines", "words", "cursor", {
184-
className: "keystrokes",
185-
defaultValue: function(el) {
186-
this.keystrokes = 0;
187-
el.innerHTML = "0 Keystrokes";
188-
},
189-
onUpdate: function(el) {
190-
el.innerHTML = ++this.keystrokes + " Keystrokes";
191-
}
192-
}], // Another optional usage, with a custom status bar item that counts keystrokes
193-
styleSelectedText: false,
194-
tabSize: 4,
195-
toolbar: false,
196-
toolbarTips: false,
197-
});
198-
```
199-
200-
#### Toolbar icons
201-
202-
Below are the built-in toolbar icons (only some of which are enabled by default), which can be reorganized however you like. "Name" is the name of the icon, referenced in the JS. "Action" is either a function or a URL to open. "Class" is the class given to the icon. "Tooltip" is the small tooltip that appears via the `title=""` attribute. Note that shortcut hints are added automatically and reflect the specified action if it has a keybind assigned to it (i.e. with the value of `action` set to `bold` and that of `tooltip` set to `Bold`, the final text the user will see would be "Bold (Ctrl-B)").
203-
204-
Additionally, you can add a separator between any icons by adding `"|"` to the toolbar array.
99+
## Theme
100+
> e.g. 使用Github的markdown样式
205101
206-
Name | Action | Tooltip<br>Class
207-
:--- | :----- | :--------------
208-
bold | toggleBold | Bold<br>fa fa-bold
209-
italic | toggleItalic | Italic<br>fa fa-italic
210-
strikethrough | toggleStrikethrough | Strikethrough<br>fa fa-strikethrough
211-
heading | toggleHeadingSmaller | Heading<br>fa fa-header
212-
heading-smaller | toggleHeadingSmaller | Smaller Heading<br>fa fa-header
213-
heading-bigger | toggleHeadingBigger | Bigger Heading<br>fa fa-lg fa-header
214-
heading-1 | toggleHeading1 | Big Heading<br>fa fa-header fa-header-x fa-header-1
215-
heading-2 | toggleHeading2 | Medium Heading<br>fa fa-header fa-header-x fa-header-2
216-
heading-3 | toggleHeading3 | Small Heading<br>fa fa-header fa-header-x fa-header-3
217-
code | toggleCodeBlock | Code<br>fa fa-code
218-
quote | toggleBlockquote | Quote<br>fa fa-quote-left
219-
unordered-list | toggleUnorderedList | Generic List<br>fa fa-list-ul
220-
ordered-list | toggleOrderedList | Numbered List<br>fa fa-list-ol
221-
clean-block | cleanBlock | Clean block<br>fa fa-eraser fa-clean-block
222-
link | drawLink | Create Link<br>fa fa-link
223-
image | drawImage | Insert Image<br>fa fa-picture-o
224-
table | drawTable | Insert Table<br>fa fa-table
225-
horizontal-rule | drawHorizontalRule | Insert Horizontal Line<br>fa fa-minus
226-
preview | togglePreview | Toggle Preview<br>fa fa-eye no-disable
227-
side-by-side | toggleSideBySide | Toggle Side by Side<br>fa fa-columns no-disable no-mobile
228-
fullscreen | toggleFullScreen | Toggle Fullscreen<br>fa fa-arrows-alt no-disable no-mobile
229-
guide | [This link](https://simplemde.com/markdown-guide) | Markdown Guide<br>fa fa-question-circle
102+
[github-markdown-css](https://github.com/sindresorhus/github-markdown-css)
230103

231-
Customize the toolbar using the `toolbar` option like:
232-
233-
```JavaScript
234-
// Customize only the order of existing buttons
235-
var simplemde = new SimpleMDE({
236-
toolbar: ["bold", "italic", "heading", "|", "quote"],
237-
});
238-
239-
// Customize all information and/or add your own icons
240-
var simplemde = new SimpleMDE({
241-
toolbar: [{
242-
name: "bold",
243-
action: SimpleMDE.toggleBold,
244-
className: "fa fa-bold",
245-
title: "Bold",
246-
},
247-
{
248-
name: "custom",
249-
action: function customFunction(editor){
250-
// Add your own code
251-
},
252-
className: "fa fa-star",
253-
title: "Custom Button",
254-
},
255-
"|", // Separator
256-
...
257-
],
258-
});
104+
### install
259105
```
260-
261-
#### Keyboard shortcuts
262-
263-
SimpleMDE comes with an array of predefined keyboard shortcuts, but they can be altered with a configuration option. The list of default ones is as follows:
264-
265-
Shortcut | Action
266-
:------- | :-----
267-
*Cmd-'* | "toggleBlockquote"
268-
*Cmd-B* | "toggleBold"
269-
*Cmd-E* | "cleanBlock"
270-
*Cmd-H* | "toggleHeadingSmaller"
271-
*Cmd-I* | "toggleItalic"
272-
*Cmd-K* | "drawLink"
273-
*Cmd-L* | "toggleUnorderedList"
274-
*Cmd-P* | "togglePreview"
275-
*Cmd-Alt-C* | "toggleCodeBlock"
276-
*Cmd-Alt-I* | "drawImage"
277-
*Cmd-Alt-L* | "toggleOrderedList"
278-
*Shift-Cmd-H* | "toggleHeadingBigger"
279-
*F9* | "toggleSideBySide"
280-
*F11* | "toggleFullScreen"
281-
282-
Here is how you can change a few, while leaving others untouched:
283-
284-
```JavaScript
285-
var simplemde = new SimpleMDE({
286-
shortcuts: {
287-
"toggleOrderedList": "Ctrl-Alt-K", // alter the shortcut for toggleOrderedList
288-
"toggleCodeBlock": null, // unbind Ctrl-Alt-C
289-
"drawTable": "Cmd-Alt-T" // bind Cmd-Alt-T to drawTable action, which doesn't come with a default shortcut
290-
}
291-
});
106+
$ npm install --save github-markdown-css
292107
```
293108

294-
Shortcuts are automatically converted between platforms. If you define a shortcut as "Cmd-B", on PC that shortcut will be changed to "Ctrl-B". Conversely, a shortcut defined as "Ctrl-B" will become "Cmd-B" for Mac users.
295-
296-
The list of actions that can be bound is the same as the list of built-in actions available for [toolbar buttons](#toolbar-icons).
297-
298-
#### Height
299-
300-
To change the minimum height (before it starts auto-growing):
301-
302-
```CSS
303-
.CodeMirror, .CodeMirror-scroll {
304-
min-height: 200px;
305-
}
109+
### use
110+
``` html
111+
<markdown-editor preview-class="markdown-body"></markdown-editor>
306112
```
307113

308-
Or, you can keep the height static:
309-
310-
```CSS
311-
.CodeMirror {
312-
height: 300px;
313-
}
114+
``` javascript
115+
import 'github-markdown-css'
314116
```
315117

316-
## How SimpleMDE works
317-
318-
SimpleMDE began as an improvement of [lepture's Editor project](https://github.com/lepture/editor), but has now taken on an identity of its own. It is bundled with [CodeMirror](https://github.com/codemirror/codemirror) and depends on [Font Awesome](http://fontawesome.io).
118+
## Configuration
319119

320-
CodeMirror is the backbone of the project and parses much of the Markdown syntax as it's being written. This allows us to add styles to the Markdown that's being written. Additionally, a toolbar and status bar have been added to the top and bottom, respectively. Previews are rendered by [Marked](https://github.com/chjj/marked) using GFM.
120+
* [中文](doc/configuration_zh.md)
121+
* [English](doc/configuration_en.md)
321122

322123
## Dependencies
323124

0 commit comments

Comments
 (0)