2019-02-11 11:48:29 +01:00
|
|
|
# EasyMDE - Markdown Editor
|
2018-01-24 10:58:55 +01:00
|
|
|
|
2018-11-09 14:28:55 +01:00
|
|
|
[](https://www.npmjs.com/package/easymde)
|
|
|
|
[](https://www.npmjs.com/package/easymde/v/next)
|
|
|
|
[](https://travis-ci.org/Ionaru/easy-markdown-editor)
|
2018-04-23 15:52:34 +02:00
|
|
|
|
2019-02-11 11:48:29 +01:00
|
|
|
> This repository is a fork of
|
|
|
|
[SimpleMDE, made by Sparksuite](https://github.com/sparksuite/simplemde-markdown-editor/).
|
|
|
|
Go to the [dedicated section](#simplemde-fork) for more information.
|
|
|
|
|
|
|
|
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. EasyMDE is one of the first editors to feature both built-in
|
|
|
|
auto-saving and spell checking.
|
|
|
|
|
|
|
|
Try [**the demo**](https://easymde.tk/)!
|
|
|
|
|
|
|
|
[](https://easymde.tk/)
|
|
|
|
|
|
|
|
|
|
|
|
## Quick access
|
|
|
|
|
|
|
|
- [Why not a WYSIWYG editor or pure Markdown?](#why-not-a-wysiwyg-editor-or-pure-markdown)
|
|
|
|
- [Install EasyMDE](#install-easymde)
|
|
|
|
- [How to use](#how-to-use)
|
|
|
|
- [Loading the editor](#loading-the-editor)
|
|
|
|
- [Editor functions](#editor-functions)
|
|
|
|
- [Configuration](#configuration)
|
|
|
|
- [Options list](#options-list)
|
2019-02-11 11:56:41 +01:00
|
|
|
- [Options example](#options-example)
|
2019-02-11 11:48:29 +01:00
|
|
|
- [Toolbar icons](#toolbar-icons)
|
|
|
|
- [Toolbar customization](#toolbar-customization)
|
|
|
|
- [Keyboard shortcuts](#keyboard-shortcuts)
|
|
|
|
- [Advanced use](#advanced-use)
|
|
|
|
- [Event handling](#event-handling)
|
|
|
|
- [Removing EasyMDE from text area](#removing-easymde-from-text-area)
|
|
|
|
- [Useful methods](#useful-methods)
|
|
|
|
- [How it works](#how-it-works)
|
2019-02-11 11:56:41 +01:00
|
|
|
- [SimpleMDE fork](#simplemde-fork)
|
2019-02-11 11:48:29 +01:00
|
|
|
- [License](#license)
|
|
|
|
|
|
|
|
## Why not a WYSIWYG editor or pure Markdown?
|
|
|
|
|
|
|
|
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 other words, for an
|
|
|
|
unfamiliar user, the syntax they write will make little sense until they click
|
|
|
|
the preview button. EasyMDE has been designed to bridge this gap for
|
|
|
|
non-technical users who are less familiar with or just learning Markdown syntax.
|
|
|
|
|
|
|
|
|
2018-04-23 15:18:49 +02:00
|
|
|
## Install EasyMDE
|
2019-02-11 11:48:29 +01:00
|
|
|
|
|
|
|
Via [npm](https://www.npmjs.com/package/easymde):
|
|
|
|
|
2018-04-23 15:18:49 +02:00
|
|
|
```
|
|
|
|
npm install easymde --save
|
|
|
|
```
|
|
|
|
|
2019-02-11 11:48:29 +01:00
|
|
|
Via the *UNPKG* CDN:
|
|
|
|
|
2018-04-25 15:32:52 +02:00
|
|
|
```html
|
|
|
|
<link rel="stylesheet" href="https://unpkg.com/easymde/dist/easymde.min.css">
|
|
|
|
<script src="https://unpkg.com/easymde/dist/easymde.min.js"></script>
|
|
|
|
```
|
|
|
|
|
2019-02-11 11:48:29 +01:00
|
|
|
|
2018-04-25 15:32:52 +02:00
|
|
|
## How to use
|
|
|
|
|
|
|
|
|
2019-02-11 11:48:29 +01:00
|
|
|
### Loading the editor
|
|
|
|
|
|
|
|
After installing and/or importing the module, you can load EasyMDE onto the
|
|
|
|
first TextArea on the web page:
|
|
|
|
|
2018-04-25 15:32:52 +02:00
|
|
|
```html
|
|
|
|
<textarea></textarea>
|
|
|
|
<script>
|
|
|
|
var easyMDE = new EasyMDE();
|
|
|
|
</script>
|
|
|
|
```
|
|
|
|
|
2019-02-11 11:48:29 +01:00
|
|
|
Alternatively you can select a specific TextArea, via Javascript:
|
|
|
|
|
2018-04-25 15:32:52 +02:00
|
|
|
```html
|
|
|
|
<textarea id="my-text-area"></textarea>
|
|
|
|
<script>
|
|
|
|
var easyMDE = new EasyMDE({element: document.getElementById('my-text-area')});
|
|
|
|
</script>
|
|
|
|
```
|
|
|
|
|
2019-02-11 11:48:29 +01:00
|
|
|
Or via jQuery:
|
|
|
|
|
2018-04-25 15:32:52 +02:00
|
|
|
```html
|
|
|
|
<textarea id="my-text-area"></textarea>
|
|
|
|
<script>
|
2018-05-09 10:28:22 +02:00
|
|
|
var easyMDE = new EasyMDE({element: $('#my-text-area')[0]});
|
2018-04-25 15:32:52 +02:00
|
|
|
</script>
|
|
|
|
```
|
|
|
|
|
|
|
|
|
2019-02-11 11:48:29 +01:00
|
|
|
### Editor functions
|
|
|
|
|
|
|
|
Use `EasyMDE.value()` to get the content of the editor:
|
|
|
|
|
2018-04-25 15:32:52 +02:00
|
|
|
```html
|
|
|
|
<script>
|
|
|
|
easyMDE.value();
|
|
|
|
</script>
|
|
|
|
```
|
|
|
|
|
2019-02-11 11:48:29 +01:00
|
|
|
Use `EasyMDE.value(val)` to set the content of the editor:
|
|
|
|
|
2018-04-25 15:32:52 +02:00
|
|
|
```html
|
|
|
|
<script>
|
|
|
|
easyMDE.value('New input for **EasyMDE**');
|
|
|
|
</script>
|
|
|
|
```
|
|
|
|
|
|
|
|
|
2015-06-22 13:16:28 -05:00
|
|
|
## Configuration
|
|
|
|
|
2019-02-11 11:48:29 +01:00
|
|
|
### Options list
|
|
|
|
|
|
|
|
- **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.
|
|
|
|
- **autofocus**: If set to `true`, auto-focuses the editor. Defaults to `false`.
|
|
|
|
- **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.*
|
|
|
|
- **enabled**: If set to `true`, auto-save the text. Defaults to `false`.
|
2015-06-26 15:33:28 -05:00
|
|
|
- **delay**: Delay between saves, in milliseconds. Defaults to `10000` (10s).
|
2019-02-11 11:48:29 +01:00
|
|
|
- **uniqueId**: You must set a unique string identifier so that EasyMDE can
|
|
|
|
auto-save. Something that separates this from other instances of EasyMDE
|
|
|
|
elsewhere on your website.
|
2015-11-30 10:24:32 +01:00
|
|
|
- **blockStyles**: Customize how certain buttons that style blocks of text behave.
|
2017-04-25 15:40:05 -05:00
|
|
|
- **bold**: Can be set to `**` or `__`. Defaults to `**`.
|
|
|
|
- **code**: Can be set to ```` ``` ```` or `~~~`. Defaults to ```` ``` ````.
|
|
|
|
- **italic**: Can be set to `*` or `_`. Defaults to `*`.
|
2019-02-11 11:48:29 +01:00
|
|
|
- **element**: The DOM element for the text area to use. Defaults to the first
|
|
|
|
text area on the page.
|
|
|
|
- **forceSync**: If set to `true`, force text changes made in EasyMDE to be
|
|
|
|
immediately stored in original text area. Defaults to `false`.
|
|
|
|
- **hideIcons**: An array of icon names to hide. Can be used to hide specific
|
|
|
|
icons shown by default without completely customizing the toolbar.
|
|
|
|
- **indentWithTabs**: If set to `false`, indent using spaces instead of tabs.
|
|
|
|
Defaults to `true`.
|
2015-09-17 00:57:03 -05:00
|
|
|
- **initialValue**: If set, will customize the initial value of the editor.
|
2019-02-11 11:48:29 +01:00
|
|
|
- **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://)"]`.
|
2015-11-03 11:28:06 -06:00
|
|
|
- horizontalRule
|
|
|
|
- image
|
|
|
|
- link
|
2015-11-25 10:07:51 +00:00
|
|
|
- table
|
2015-09-17 00:57:03 -05:00
|
|
|
- **lineWrapping**: If set to `false`, disable line wrapping. Defaults to `true`.
|
2019-02-11 11:48:29 +01:00
|
|
|
- **minHeight**: Sets the minimum height for the composition area, before it
|
|
|
|
starts auto-growing. Should be a string containing a valid CSS value like
|
|
|
|
`"500px"`. Defaults to `"300px"`.
|
|
|
|
- **onToggleFullScreen**: A function that gets called when the editor's
|
|
|
|
full screen mode is toggled. The function will be passed a boolean as parameter,
|
|
|
|
`true` when the editor is currently going into full screen mode, or `false`.
|
|
|
|
- **parsingConfig**: Adjust settings for parsing the Markdown during editing
|
|
|
|
(not previewing).
|
|
|
|
- **allowAtxHeaderWithoutSpace**: If set to `true`, will render headers
|
|
|
|
without a space after the `#`. Defaults to `false`.
|
|
|
|
- **strikethrough**: If set to `false`, will not process GFM strikethrough
|
|
|
|
syntax. Defaults to `true`.
|
|
|
|
- **underscoresBreakWords**: If set to `true`, let underscores be a delimiter
|
|
|
|
for separating words. Defaults to `false`.
|
2016-07-10 13:07:00 -05:00
|
|
|
- **placeholder**: If set, displays a custom placeholder message.
|
2019-02-11 11:48:29 +01:00
|
|
|
- **previewRender**: Custom function for parsing the plaintext Markdown and
|
|
|
|
returning HTML. Used when user previews.
|
|
|
|
- **promptURLs**: If set to `true`, a JS alert window appears asking for the
|
|
|
|
link or image URL. Defaults to `false`.
|
2017-04-25 15:39:53 -05:00
|
|
|
- **promptTexts**: Customize the text used to prompt for URLs.
|
2019-02-11 11:48:29 +01:00
|
|
|
- **image**: The text to use when prompting for an image's URL. Defaults to
|
|
|
|
`URL of the image:`.
|
|
|
|
- **link**: The text to use when prompting for a link's URL. Defaults to
|
|
|
|
`URL for the link:`.
|
|
|
|
- **renderingConfig**: Adjust settings for parsing the Markdown during
|
|
|
|
previewing (not editing).
|
|
|
|
- **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 or pass in using
|
|
|
|
the `hljs` option. 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">`
|
|
|
|
- **hljs**: An injectible instance of
|
|
|
|
[highlight.js](https://github.com/isagalaev/highlight.js). If you don't want to
|
|
|
|
rely on the global namespace (`window.hljs`), you can provide an instance here.
|
|
|
|
Defaults to `undefined`.
|
|
|
|
- **markedOptions**: Set the internal Markdown renderer's
|
|
|
|
[options](https://github.com/chjj/marked#options-1). Other `renderingConfig`
|
|
|
|
options will take precedence.
|
|
|
|
- **singleLineBreaks**: If set to `false`, disable parsing GFM single line
|
|
|
|
breaks. Defaults to `true`.
|
|
|
|
- **shortcuts**: Keyboard shortcuts associated with this instance. Defaults to
|
|
|
|
the [array of shortcuts](#keyboard-shortcuts).
|
|
|
|
- **showIcons**: An array of icon names to show. Can be used to show specific
|
|
|
|
icons hidden by default without completely customizing the toolbar.
|
|
|
|
- **spellChecker**: If set to `false`, disable the spell checker. Defaults to
|
|
|
|
`true`.
|
|
|
|
- **status**: If set to `false`, hide the status bar. Defaults to the array of
|
|
|
|
built-in status bar items.
|
|
|
|
- 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.
|
|
|
|
- **styleSelectedText**: If set to `false`, remove the `CodeMirror-selectedtext`
|
|
|
|
class from selected lines. Defaults to `true`.
|
|
|
|
- **syncSideBySidePreviewScroll**: If set to `false`, disable syncing scroll in
|
|
|
|
side by side mode. Defaults to `true`.
|
2015-09-17 00:57:03 -05:00
|
|
|
- **tabSize**: If set, customize the tab size. Defaults to `2`.
|
2018-07-29 11:59:50 +02:00
|
|
|
- **theme**: Override the theme. Defaults to `easymde`.
|
2019-02-11 11:48:29 +01:00
|
|
|
- **toolbar**: If set to `false`, hide the toolbar. Defaults to the
|
|
|
|
[array of icons](#toolbar-icons).
|
|
|
|
- **toolbarTips**: If set to `false`, disable toolbar button tips. Defaults to
|
|
|
|
`true`.
|
|
|
|
|
|
|
|
|
|
|
|
### Options example
|
|
|
|
|
|
|
|
Most options demonstrate the non-default behavior:
|
2015-06-22 13:16:28 -05:00
|
|
|
|
2015-06-26 13:52:19 -05:00
|
|
|
```JavaScript
|
2019-02-11 11:48:29 +01:00
|
|
|
var easyMDE = new EasyMDE({
|
2015-06-26 12:53:24 -05:00
|
|
|
autofocus: true,
|
2015-06-26 15:33:28 -05:00
|
|
|
autosave: {
|
|
|
|
enabled: true,
|
2015-11-19 14:47:15 -06:00
|
|
|
uniqueId: "MyUniqueID",
|
2015-06-26 15:33:28 -05:00
|
|
|
delay: 1000,
|
|
|
|
},
|
2015-11-30 10:24:32 +01:00
|
|
|
blockStyles: {
|
2015-11-30 17:53:41 +01:00
|
|
|
bold: "__",
|
2015-11-30 10:24:32 +01:00
|
|
|
italic: "_"
|
|
|
|
},
|
2015-09-17 00:57:03 -05:00
|
|
|
element: document.getElementById("MyID"),
|
2016-02-12 11:17:43 -07:00
|
|
|
forceSync: true,
|
2015-09-24 15:03:20 -05:00
|
|
|
hideIcons: ["guide", "heading"],
|
2015-09-17 00:57:03 -05:00
|
|
|
indentWithTabs: false,
|
|
|
|
initialValue: "Hello world!",
|
2015-11-03 11:28:06 -06:00
|
|
|
insertTexts: {
|
|
|
|
horizontalRule: ["", "\n\n-----\n\n"],
|
|
|
|
image: [""],
|
|
|
|
link: ["[", "](http://)"],
|
2015-11-25 10:07:51 +00:00
|
|
|
table: ["", "\n\n| Column 1 | Column 2 | Column 3 |\n| -------- | -------- | -------- |\n| Text | Text | Text |\n\n"],
|
2015-11-03 11:28:06 -06:00
|
|
|
},
|
2015-09-17 00:57:03 -05:00
|
|
|
lineWrapping: false,
|
2016-07-10 13:07:00 -05:00
|
|
|
minHeight: "500px",
|
2015-09-17 00:57:03 -05:00
|
|
|
parsingConfig: {
|
|
|
|
allowAtxHeaderWithoutSpace: true,
|
|
|
|
strikethrough: false,
|
|
|
|
underscoresBreakWords: true,
|
|
|
|
},
|
2015-12-10 22:46:31 +01:00
|
|
|
placeholder: "Type here...",
|
2015-09-03 17:59:50 -05:00
|
|
|
previewRender: function(plainText) {
|
|
|
|
return customMarkdownParser(plainText); // Returns HTML from a custom parser
|
2015-09-05 14:28:50 -05:00
|
|
|
},
|
|
|
|
previewRender: function(plainText, preview) { // Async method
|
|
|
|
setTimeout(function(){
|
|
|
|
preview.innerHTML = customMarkdownParser(plainText);
|
|
|
|
}, 250);
|
2016-01-09 10:13:16 +01:00
|
|
|
|
2015-09-05 14:28:50 -05:00
|
|
|
return "Loading...";
|
2015-10-20 11:15:54 -05:00
|
|
|
},
|
2016-01-26 10:43:25 -06:00
|
|
|
promptURLs: true,
|
2017-04-25 15:39:53 -05:00
|
|
|
promptTexts: {
|
|
|
|
image: "Custom prompt for URL:",
|
|
|
|
link: "Custom prompt for URL:",
|
|
|
|
},
|
2015-09-25 16:47:24 -05:00
|
|
|
renderingConfig: {
|
|
|
|
singleLineBreaks: false,
|
|
|
|
codeSyntaxHighlighting: true,
|
|
|
|
},
|
2016-01-09 10:13:16 +01:00
|
|
|
shortcuts: {
|
|
|
|
drawTable: "Cmd-Alt-T"
|
|
|
|
},
|
2015-12-05 00:37:12 -06:00
|
|
|
showIcons: ["code", "table"],
|
2015-09-17 00:57:03 -05:00
|
|
|
spellChecker: false,
|
|
|
|
status: false,
|
2015-11-03 11:37:00 -06:00
|
|
|
status: ["autosave", "lines", "words", "cursor"], // Optional usage
|
2016-01-22 13:02:39 -06:00
|
|
|
status: ["autosave", "lines", "words", "cursor", {
|
|
|
|
className: "keystrokes",
|
|
|
|
defaultValue: function(el) {
|
|
|
|
this.keystrokes = 0;
|
|
|
|
el.innerHTML = "0 Keystrokes";
|
|
|
|
},
|
|
|
|
onUpdate: function(el) {
|
|
|
|
el.innerHTML = ++this.keystrokes + " Keystrokes";
|
|
|
|
}
|
2016-01-22 13:59:40 -06:00
|
|
|
}], // Another optional usage, with a custom status bar item that counts keystrokes
|
2016-04-09 21:17:07 -05:00
|
|
|
styleSelectedText: false,
|
2017-03-02 10:33:42 +09:00
|
|
|
syncSideBySidePreviewScroll: false,
|
2015-09-17 00:57:03 -05:00
|
|
|
tabSize: 4,
|
|
|
|
toolbar: false,
|
|
|
|
toolbarTips: false,
|
2015-06-22 13:16:28 -05:00
|
|
|
});
|
2015-06-26 13:52:19 -05:00
|
|
|
```
|
|
|
|
|
2015-07-14 11:52:28 -05:00
|
|
|
|
2019-02-11 11:48:29 +01:00
|
|
|
### Toolbar icons
|
2016-01-09 10:13:16 +01:00
|
|
|
|
2019-02-11 11:48:29 +01:00
|
|
|
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 key bind 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)").
|
|
|
|
|
|
|
|
Additionally, you can add a separator between any icons by adding `"|"` to the
|
|
|
|
toolbar array.
|
2015-07-14 11:52:28 -05:00
|
|
|
|
2015-09-17 01:01:28 -05:00
|
|
|
Name | Action | Tooltip<br>Class
|
|
|
|
:--- | :----- | :--------------
|
2016-01-09 10:13:16 +01:00
|
|
|
bold | toggleBold | Bold<br>fa fa-bold
|
|
|
|
italic | toggleItalic | Italic<br>fa fa-italic
|
2015-09-17 01:01:28 -05:00
|
|
|
strikethrough | toggleStrikethrough | Strikethrough<br>fa fa-strikethrough
|
2016-01-09 10:13:16 +01:00
|
|
|
heading | toggleHeadingSmaller | Heading<br>fa fa-header
|
|
|
|
heading-smaller | toggleHeadingSmaller | Smaller Heading<br>fa fa-header
|
|
|
|
heading-bigger | toggleHeadingBigger | Bigger Heading<br>fa fa-lg fa-header
|
2018-11-09 10:37:20 +01:00
|
|
|
heading-1 | toggleHeading1 | Big Heading<br>fa fa-header header-1
|
|
|
|
heading-2 | toggleHeading2 | Medium Heading<br>fa fa-header header-2
|
|
|
|
heading-3 | toggleHeading3 | Small Heading<br>fa fa-header header-3
|
2016-01-09 10:13:16 +01:00
|
|
|
code | toggleCodeBlock | Code<br>fa fa-code
|
|
|
|
quote | toggleBlockquote | Quote<br>fa fa-quote-left
|
|
|
|
unordered-list | toggleUnorderedList | Generic List<br>fa fa-list-ul
|
|
|
|
ordered-list | toggleOrderedList | Numbered List<br>fa fa-list-ol
|
2018-11-09 14:41:48 +01:00
|
|
|
clean-block | cleanBlock | Clean block<br>fa fa-eraser
|
2016-01-09 10:13:16 +01:00
|
|
|
link | drawLink | Create Link<br>fa fa-link
|
|
|
|
image | drawImage | Insert Image<br>fa fa-picture-o
|
2015-11-25 10:07:51 +00:00
|
|
|
table | drawTable | Insert Table<br>fa fa-table
|
2015-12-05 00:37:12 -06:00
|
|
|
horizontal-rule | drawHorizontalRule | Insert Horizontal Line<br>fa fa-minus
|
2016-01-09 10:13:16 +01:00
|
|
|
preview | togglePreview | Toggle Preview<br>fa fa-eye no-disable
|
|
|
|
side-by-side | toggleSideBySide | Toggle Side by Side<br>fa fa-columns no-disable no-mobile
|
|
|
|
fullscreen | toggleFullScreen | Toggle Fullscreen<br>fa fa-arrows-alt no-disable no-mobile
|
2016-02-25 14:17:41 -06:00
|
|
|
guide | [This link](https://simplemde.com/markdown-guide) | Markdown Guide<br>fa fa-question-circle
|
2015-07-14 11:52:28 -05:00
|
|
|
|
2019-02-11 11:48:29 +01:00
|
|
|
### Toolbar customization
|
|
|
|
|
|
|
|
You can customize the toolbar using the `toolbar` option.
|
|
|
|
|
|
|
|
Only the order of existing buttons:
|
2015-07-14 11:52:28 -05:00
|
|
|
|
|
|
|
```JavaScript
|
2019-02-11 11:48:29 +01:00
|
|
|
var easyMDE = new EasyMDE({
|
2015-08-17 16:34:05 -05:00
|
|
|
toolbar: ["bold", "italic", "heading", "|", "quote"],
|
|
|
|
});
|
2019-02-11 11:48:29 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
Or all information and/or add your own icons:
|
2015-08-17 16:34:05 -05:00
|
|
|
|
2019-02-11 11:48:29 +01:00
|
|
|
```JavaScript
|
|
|
|
var easyMDE = new EasyMDE({
|
2015-07-14 11:52:28 -05:00
|
|
|
toolbar: [{
|
2015-07-14 12:58:28 -05:00
|
|
|
name: "bold",
|
2019-02-11 11:48:29 +01:00
|
|
|
action: EasyMDE.toggleBold,
|
2015-07-14 11:52:28 -05:00
|
|
|
className: "fa fa-bold",
|
2016-01-09 10:13:16 +01:00
|
|
|
title: "Bold",
|
2015-07-14 11:52:28 -05:00
|
|
|
},
|
2015-12-04 14:31:33 -06:00
|
|
|
{
|
|
|
|
name: "custom",
|
2016-04-22 19:38:20 -04:00
|
|
|
action: function customFunction(editor){
|
2015-12-04 14:31:33 -06:00
|
|
|
// Add your own code
|
|
|
|
},
|
|
|
|
className: "fa fa-star",
|
|
|
|
title: "Custom Button",
|
|
|
|
},
|
2015-07-14 11:52:28 -05:00
|
|
|
"|", // Separator
|
2019-02-11 11:48:29 +01:00
|
|
|
// ...
|
2015-07-14 11:52:28 -05:00
|
|
|
],
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2016-01-09 10:13:16 +01:00
|
|
|
|
2019-02-11 11:48:29 +01:00
|
|
|
### Keyboard shortcuts
|
|
|
|
|
|
|
|
EasyMDE 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:
|
2016-01-09 10:13:16 +01:00
|
|
|
|
2018-05-13 01:00:07 +02:00
|
|
|
Shortcut (Windows / Linux) | Shortcut (macOS) | Action
|
|
|
|
:--- | :--- | :---
|
|
|
|
*Ctrl-'* | *Cmd-'* | "toggleBlockquote"
|
|
|
|
*Ctrl-B* | *Cmd-B* | "toggleBold"
|
|
|
|
*Ctrl-E* | *Cmd-E* | "cleanBlock"
|
|
|
|
*Ctrl-H* | *Cmd-H* | "toggleHeadingSmaller"
|
|
|
|
*Ctrl-I* | *Cmd-I* | "toggleItalic"
|
|
|
|
*Ctrl-K* | *Cmd-K* | "drawLink"
|
|
|
|
*Ctrl-L* | *Cmd-L* | "toggleUnorderedList"
|
|
|
|
*Ctrl-P* | *Cmd-P* | "togglePreview"
|
|
|
|
*Ctrl-Alt-C* | *Cmd-Alt-C* | "toggleCodeBlock"
|
|
|
|
*Ctrl-Alt-I* | *Cmd-Alt-I* | "drawImage"
|
|
|
|
*Ctrl-Alt-L* | *Cmd-Alt-L* | "toggleOrderedList"
|
|
|
|
*Shift-Ctrl-H* | *Shift-Cmd-H* | "toggleHeadingBigger"
|
|
|
|
*F9* | *F9* | "toggleSideBySide"
|
|
|
|
*F11* | *F11* | "toggleFullScreen"
|
2016-01-09 10:13:16 +01:00
|
|
|
|
|
|
|
Here is how you can change a few, while leaving others untouched:
|
|
|
|
|
|
|
|
```JavaScript
|
2019-02-11 11:48:29 +01:00
|
|
|
var easyMDE = new EasyMDE({
|
2016-01-09 10:13:16 +01:00
|
|
|
shortcuts: {
|
|
|
|
"toggleOrderedList": "Ctrl-Alt-K", // alter the shortcut for toggleOrderedList
|
|
|
|
"toggleCodeBlock": null, // unbind Ctrl-Alt-C
|
|
|
|
"drawTable": "Cmd-Alt-T" // bind Cmd-Alt-T to drawTable action, which doesn't come with a default shortcut
|
|
|
|
}
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2019-02-11 11:48:29 +01:00
|
|
|
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.
|
|
|
|
|
|
|
|
The list of actions that can be bound is the same as the list of built-in
|
|
|
|
actions available for [toolbar buttons](#toolbar-icons).
|
2016-01-09 10:13:16 +01:00
|
|
|
|
|
|
|
|
2019-02-11 11:48:29 +01:00
|
|
|
## Advanced use
|
|
|
|
|
|
|
|
### Event handling
|
|
|
|
|
|
|
|
You can catch the following list of events:
|
|
|
|
https://codemirror.net/doc/manual.html#events
|
2015-07-11 10:09:02 -05:00
|
|
|
|
2015-07-20 11:49:47 -05:00
|
|
|
```JavaScript
|
2019-02-11 11:48:29 +01:00
|
|
|
var easyMDE = new EasyMDE();
|
|
|
|
easyMDE.codemirror.on("change", function(){
|
|
|
|
console.log(easyMDE.value());
|
2015-07-11 10:09:02 -05:00
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2019-02-11 11:48:29 +01:00
|
|
|
### Removing EasyMDE from text area
|
|
|
|
|
|
|
|
You can revert to the initial text area by calling the `toTextArea` method. Note
|
|
|
|
that this clears up the auto-save (if enabled) associated with it. The text area
|
|
|
|
will retain any text from the destroyed EasyMDE instance.
|
2016-01-24 07:10:25 +01:00
|
|
|
|
|
|
|
```JavaScript
|
2019-02-11 11:48:29 +01:00
|
|
|
var easyMDE = new EasyMDE();
|
|
|
|
// ...
|
|
|
|
easyMDE.toTextArea();
|
|
|
|
easyMDE = null;
|
2016-01-24 07:10:25 +01:00
|
|
|
```
|
|
|
|
|
2019-02-11 11:48:29 +01:00
|
|
|
|
|
|
|
### Useful methods
|
|
|
|
|
|
|
|
The following self-explanatory methods may be of use while developing with
|
|
|
|
EasyMDE.
|
2015-10-20 15:01:14 -05:00
|
|
|
|
2015-10-20 15:03:43 -05:00
|
|
|
```js
|
2019-02-11 11:48:29 +01:00
|
|
|
var easyMDE = new EasyMDE();
|
|
|
|
easyMDE.isPreviewActive(); // returns boolean
|
|
|
|
easyMDE.isSideBySideActive(); // returns boolean
|
|
|
|
easyMDE.isFullscreenActive(); // returns boolean
|
|
|
|
easyMDE.clearAutosavedValue(); // no returned value
|
2015-10-20 15:01:14 -05:00
|
|
|
```
|
|
|
|
|
2019-02-11 11:48:29 +01:00
|
|
|
|
2015-06-22 13:30:38 -05:00
|
|
|
## How it works
|
|
|
|
|
2019-02-11 11:48:29 +01:00
|
|
|
EasyMDE 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).
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
2019-02-11 11:56:41 +01:00
|
|
|
## SimpleMDE fork
|
2019-02-11 11:48:29 +01:00
|
|
|
|
|
|
|
I originally made this fork to implement FontAwesome 5 compatibility into
|
|
|
|
EasyMDE. When that was done I submitted a
|
|
|
|
[pull request](https://github.com/sparksuite/simplemde-markdown-editor/pull/666),
|
|
|
|
which has not been accepted yet. This, and the project being inactive since May
|
|
|
|
2017, triggered me to make more changes and try to put new life into the project.
|
|
|
|
|
|
|
|
Changes include:
|
|
|
|
* FontAwesome 5 compatibility;
|
|
|
|
* guide button works when editor is in preview mode;
|
|
|
|
* links are now `https://` by default;
|
|
|
|
* small styling changes;
|
|
|
|
* support for Node 8 and beyond;
|
|
|
|
* lots of refactored code;
|
|
|
|
* links in preview will open in a new tab by default;
|
|
|
|
* Typescript support.
|
|
|
|
|
|
|
|
My intention is to continue development on this project, improving it and
|
|
|
|
keeping it alive.
|
|
|
|
|
|
|
|
## License
|
|
|
|
|
|
|
|
This project is released under the [MIT License](./LICENSE).
|
|
|
|
|
|
|
|
- Copyright (c) 2015 Sparksuite, Inc.
|
|
|
|
- Copyright (c) 2017 Jeroen Akkerman.
|