Skip to content

Commit da8a264

Browse files
committed
Add autocomlete with mention support
1 parent 6abda7a commit da8a264

File tree

9 files changed

+113
-35056
lines changed

9 files changed

+113
-35056
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
localtesting/
22
node_modules/
33
bower_components/
4+
debug/
45

56
#For IDE
67
*.iml

README.md

Lines changed: 28 additions & 327 deletions
Original file line numberDiff line numberDiff line change
@@ -1,331 +1,32 @@
1-
# SimpleMDE - Markdown Editor
2-
A drop-in JavaScript textarea replacement for writing beautiful and understandable Markdown. The WYSIWYG-esque editor allows users who may be less experienced with Markdown to use familiar toolbar buttons and shortcuts. In addition, the syntax is rendered while editing to clearly show the expected result. Headings are larger, emphasized words are italicized, links are underlined, etc. SimpleMDE is one of the first editors to feature both built-in autosaving and spell checking.
1+
# SimpleMDE - Markdown Editor (With Mentions)
32

4-
[**Demo**](https://simplemde.com)
5-
6-
[![Preview](http://i.imgur.com/zqWfJwO.png)](https://simplemde.com)
7-
8-
## Why not a WYSIWYG editor or pure Markdown?
9-
WYSIWYG editors that produce HTML are often complex and buggy. Markdown solves this problem in many ways, plus Markdown can be rendered natively on more platforms than HTML. However, Markdown is not a syntax that an average user will be familiar with, nor is it visually clear while editing. In otherwords, for an unfamiliar user, the syntax they write will make little sense until they click the preview button. SimpleMDE has been designed to bridge this gap for non-technical users who are less familiar with or just learning Markdown syntax.
10-
11-
## Install
12-
13-
Via [npm](https://www.npmjs.com/package/simplemde).
14-
```
15-
npm install simplemde --save
16-
```
17-
18-
Via [bower](https://www.bower.io).
19-
```
20-
bower install simplemde --save
21-
```
22-
23-
Via [jsDelivr](https://www.jsdelivr.com/#!simplemde). *Please note, jsDelivr may take a few days to update to the latest release.*
24-
25-
```HTML
26-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.css">
27-
<script src="https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.js"></script>
28-
```
29-
30-
## Quick start
31-
32-
After installing, load SimpleMDE on the first textarea on a page
33-
34-
```HTML
35-
<script>
36-
var simplemde = new SimpleMDE();
37-
</script>
38-
```
39-
40-
#### Using a specific textarea
41-
42-
Pure JavaScript method
43-
44-
```HTML
45-
<script>
46-
var simplemde = new SimpleMDE({ element: document.getElementById("MyID") });
47-
</script>
48-
```
49-
50-
jQuery method
51-
52-
```HTML
53-
<script>
54-
var simplemde = new SimpleMDE({ element: $("#MyID")[0] });
55-
</script>
56-
```
57-
58-
## Get/set the content
59-
60-
```JavaScript
61-
simplemde.value();
62-
```
63-
64-
```JavaScript
65-
simplemde.value("This text will appear in the editor");
66-
```
67-
68-
## Configuration
69-
70-
- **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.
71-
- **autofocus**: If set to `true`, autofocuses the editor. Defaults to `false`.
72-
- **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.*
73-
- **enabled**: If set to `true`, autosave the text. Defaults to `false`.
74-
- **delay**: Delay between saves, in milliseconds. Defaults to `10000` (10s).
75-
- **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.
76-
- **blockStyles**: Customize how certain buttons that style blocks of text behave.
77-
- **bold** Can be set to `**` or `__`. Defaults to `**`.
78-
- **code** Can be set to ```` ``` ```` or `~~~`. Defaults to ```` ``` ````.
79-
- **italic** Can be set to `*` or `_`. Defaults to `*`.
80-
- **element**: The DOM element for the textarea to use. Defaults to the first textarea on the page.
81-
- **forceSync**: If set to `true`, force text changes made in SimpleMDE to be immediately stored in original textarea. Defaults to `false`.
82-
- **hideIcons**: An array of icon names to hide. Can be used to hide specific icons shown by default without completely customizing the toolbar.
83-
- **indentWithTabs**: If set to `false`, indent using spaces instead of tabs. Defaults to `true`.
84-
- **initialValue**: If set, will customize the initial value of the editor.
85-
- **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://)"]`.
86-
- horizontalRule
87-
- image
88-
- link
89-
- table
90-
- **lineWrapping**: If set to `false`, disable line wrapping. Defaults to `true`.
91-
- **parsingConfig**: Adjust settings for parsing the Markdown during editing (not previewing).
92-
- **allowAtxHeaderWithoutSpace**: If set to `true`, will render headers without a space after the `#`. Defaults to `false`.
93-
- **strikethrough**: If set to `false`, will not process GFM strikethrough syntax. Defaults to `true`.
94-
- **underscoresBreakWords**: If set to `true`, let underscores be a delimiter for separating words. Defaults to `false`.
95-
- **placeholder**: Custom placeholder that should be displayed
96-
- **previewRender**: Custom function for parsing the plaintext Markdown and returning HTML. Used when user previews.
97-
- **promptURLs**: If set to `true`, a JS alert window appears asking for the link or image URL. Defaults to `false`.
98-
- **renderingConfig**: Adjust settings for parsing the Markdown during previewing (not editing).
99-
- **singleLineBreaks**: If set to `false`, disable parsing GFM single line breaks. Defaults to `true`.
100-
- **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">`
101-
- **shortcuts**: Keyboard shortcuts associated with this instance. Defaults to the [array of shortcuts](#keyboard-shortcuts).
102-
- **showIcons**: An array of icon names to show. Can be used to show specific icons hidden by default without completely customizing the toolbar.
103-
- **spellChecker**: If set to `false`, disable the spell checker. Defaults to `true`.
104-
- **status**: If set to `false`, hide the status bar. Defaults to the array of built-in status bar items.
105-
- 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.
106-
- **styleSelectedText**: If set to `false`, remove the `CodeMirror-selectedtext` class from selected lines. Defaults to `true`.
107-
- **tabSize**: If set, customize the tab size. Defaults to `2`.
108-
- **toolbar**: If set to `false`, hide the toolbar. Defaults to the [array of icons](#toolbar-icons).
109-
- **toolbarTips**: If set to `false`, disable toolbar button tips. Defaults to `true`.
110-
111-
```JavaScript
112-
// Most options demonstrate the non-default behavior
113-
var simplemde = new SimpleMDE({
114-
autofocus: true,
115-
autosave: {
116-
enabled: true,
117-
uniqueId: "MyUniqueID",
118-
delay: 1000,
119-
},
120-
blockStyles: {
121-
bold: "__",
122-
italic: "_"
123-
},
124-
element: document.getElementById("MyID"),
125-
forceSync: true,
126-
hideIcons: ["guide", "heading"],
127-
indentWithTabs: false,
128-
initialValue: "Hello world!",
129-
insertTexts: {
130-
horizontalRule: ["", "\n\n-----\n\n"],
131-
image: ["![](http://", ")"],
132-
link: ["[", "](http://)"],
133-
table: ["", "\n\n| Column 1 | Column 2 | Column 3 |\n| -------- | -------- | -------- |\n| Text | Text | Text |\n\n"],
134-
},
135-
lineWrapping: false,
136-
parsingConfig: {
137-
allowAtxHeaderWithoutSpace: true,
138-
strikethrough: false,
139-
underscoresBreakWords: true,
140-
},
141-
placeholder: "Type here...",
142-
previewRender: function(plainText) {
143-
return customMarkdownParser(plainText); // Returns HTML from a custom parser
144-
},
145-
previewRender: function(plainText, preview) { // Async method
146-
setTimeout(function(){
147-
preview.innerHTML = customMarkdownParser(plainText);
148-
}, 250);
149-
150-
return "Loading...";
151-
},
152-
promptURLs: true,
153-
renderingConfig: {
154-
singleLineBreaks: false,
155-
codeSyntaxHighlighting: true,
156-
},
157-
shortcuts: {
158-
drawTable: "Cmd-Alt-T"
159-
},
160-
showIcons: ["code", "table"],
161-
spellChecker: false,
162-
status: false,
163-
status: ["autosave", "lines", "words", "cursor"], // Optional usage
164-
status: ["autosave", "lines", "words", "cursor", {
165-
className: "keystrokes",
166-
defaultValue: function(el) {
167-
this.keystrokes = 0;
168-
el.innerHTML = "0 Keystrokes";
169-
},
170-
onUpdate: function(el) {
171-
el.innerHTML = ++this.keystrokes + " Keystrokes";
172-
}
173-
}], // Another optional usage, with a custom status bar item that counts keystrokes
174-
styleSelectedText: false,
175-
tabSize: 4,
176-
toolbar: false,
177-
toolbarTips: false,
178-
});
179-
```
180-
181-
#### Toolbar icons
182-
183-
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)").
184-
185-
Additionally, you can add a separator between any icons by adding `"|"` to the toolbar array.
186-
187-
Name | Action | Tooltip<br>Class
188-
:--- | :----- | :--------------
189-
bold | toggleBold | Bold<br>fa fa-bold
190-
italic | toggleItalic | Italic<br>fa fa-italic
191-
strikethrough | toggleStrikethrough | Strikethrough<br>fa fa-strikethrough
192-
heading | toggleHeadingSmaller | Heading<br>fa fa-header
193-
heading-smaller | toggleHeadingSmaller | Smaller Heading<br>fa fa-header
194-
heading-bigger | toggleHeadingBigger | Bigger Heading<br>fa fa-lg fa-header
195-
heading-1 | toggleHeading1 | Big Heading<br>fa fa-header fa-header-x fa-header-1
196-
heading-2 | toggleHeading2 | Medium Heading<br>fa fa-header fa-header-x fa-header-2
197-
heading-3 | toggleHeading3 | Small Heading<br>fa fa-header fa-header-x fa-header-3
198-
code | toggleCodeBlock | Code<br>fa fa-code
199-
quote | toggleBlockquote | Quote<br>fa fa-quote-left
200-
unordered-list | toggleUnorderedList | Generic List<br>fa fa-list-ul
201-
ordered-list | toggleOrderedList | Numbered List<br>fa fa-list-ol
202-
clean-block | cleanBlock | Clean block<br>fa fa-eraser fa-clean-block
203-
link | drawLink | Create Link<br>fa fa-link
204-
image | drawImage | Insert Image<br>fa fa-picture-o
205-
table | drawTable | Insert Table<br>fa fa-table
206-
horizontal-rule | drawHorizontalRule | Insert Horizontal Line<br>fa fa-minus
207-
preview | togglePreview | Toggle Preview<br>fa fa-eye no-disable
208-
side-by-side | toggleSideBySide | Toggle Side by Side<br>fa fa-columns no-disable no-mobile
209-
fullscreen | toggleFullScreen | Toggle Fullscreen<br>fa fa-arrows-alt no-disable no-mobile
210-
guide | [This link](https://simplemde.com/markdown-guide) | Markdown Guide<br>fa fa-question-circle
211-
212-
Customize the toolbar using the `toolbar` option like:
3+
Based on [sparksuite/simplemde-markdown-editor](https://github.com/sparksuite/simplemde-markdown-editor)
2134

2145
```JavaScript
215-
// Customize only the order of existing buttons
216-
var simplemde = new SimpleMDE({
217-
toolbar: ["bold", "italic", "heading", "|", "quote"],
218-
});
219-
220-
// Customize all information and/or add your own icons
221-
var simplemde = new SimpleMDE({
222-
toolbar: [{
223-
name: "bold",
224-
action: SimpleMDE.toggleBold,
225-
className: "fa fa-bold",
226-
title: "Bold",
227-
},
228-
{
229-
name: "custom",
230-
action: function customFunction(editor){
231-
// Add your own code
232-
},
233-
className: "fa fa-star",
234-
title: "Custom Button",
235-
},
236-
"|", // Separator
237-
...
238-
],
6+
var md = new SimpleMDE(
7+
{
8+
element: document.getElementById("MyID"),
9+
autoSuggest:
10+
{
11+
mode: 'markdown',
12+
startChars: ['@', '#'],
13+
listCallback: function(stringToTest)
14+
{
15+
return [
16+
{
17+
text: 'Thomas ',
18+
displayText: 'Thomas'
19+
},
20+
{
21+
text: 'Maria ',
22+
displayText: 'Maria'
23+
},
24+
{
25+
text: 'Peter ',
26+
displayText: 'Peter'
27+
}
28+
];
29+
}
30+
}
23931
});
240-
```
241-
242-
#### Keyboard shortcuts
243-
244-
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:
245-
246-
Shortcut | Action
247-
:------- | :-----
248-
*Cmd-'* | "toggleBlockquote"
249-
*Cmd-B* | "toggleBold"
250-
*Cmd-E* | "cleanBlock"
251-
*Cmd-H* | "toggleHeadingSmaller"
252-
*Cmd-I* | "toggleItalic"
253-
*Cmd-K* | "drawLink"
254-
*Cmd-L* | "toggleUnorderedList"
255-
*Cmd-P* | "togglePreview"
256-
*Cmd-Alt-C* | "toggleCodeBlock"
257-
*Cmd-Alt-I* | "drawImage"
258-
*Cmd-Alt-L* | "toggleOrderedList"
259-
*Shift-Cmd-H* | "toggleHeadingBigger"
260-
*F9* | "toggleSideBySide"
261-
*F11* | "toggleFullScreen"
262-
263-
Here is how you can change a few, while leaving others untouched:
264-
265-
```JavaScript
266-
var simplemde = new SimpleMDE({
267-
shortcuts: {
268-
"toggleOrderedList": "Ctrl-Alt-K", // alter the shortcut for toggleOrderedList
269-
"toggleCodeBlock": null, // unbind Ctrl-Alt-C
270-
"drawTable": "Cmd-Alt-T" // bind Cmd-Alt-T to drawTable action, which doesn't come with a default shortcut
271-
}
272-
});
273-
```
274-
275-
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.
276-
277-
The list of actions that can be bound is the same as the list of built-in actions available for [toolbar buttons](#toolbar-icons).
278-
279-
#### Height
280-
281-
To change the minimum height (before it starts auto-growing):
282-
283-
```CSS
284-
.CodeMirror, .CodeMirror-scroll {
285-
min-height: 200px;
286-
}
287-
```
288-
289-
Or, you can keep the height static:
290-
291-
```CSS
292-
.CodeMirror {
293-
height: 300px;
294-
}
295-
```
296-
297-
## Event handling
298-
You can catch the following list of events: https://codemirror.net/doc/manual.html#events
299-
300-
```JavaScript
301-
var simplemde = new SimpleMDE();
302-
simplemde.codemirror.on("change", function(){
303-
console.log(simplemde.value());
304-
});
305-
```
306-
307-
## Removing SimpleMDE from textarea
308-
You can revert to the initial textarea by calling the `toTextArea` method. Note that this clears up the autosave (if enabled) associated with it. The textarea will retain any text from the destroyed SimpleMDE instance.
309-
310-
```JavaScript
311-
var simplemde = new SimpleMDE();
312-
...
313-
simplemde.toTextArea();
314-
simplemde = null;
315-
```
316-
317-
## Useful methods
318-
The following self-explanatory methods may be of use while developing with SimpleMDE.
319-
320-
```js
321-
var simplemde = new SimpleMDE();
322-
simplemde.isPreviewActive(); // returns boolean
323-
simplemde.isSideBySideActive(); // returns boolean
324-
simplemde.isFullscreenActive(); // returns boolean
325-
simplemde.clearAutosavedValue(); // no returned value
326-
```
327-
328-
## How it works
329-
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).
330-
331-
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.
32+
```

0 commit comments

Comments
 (0)