Skip to content

Commit 6318fc1

Browse files
committed
Merge pull request sparksuite#237 from NextStepWebs/development
Placeholder, Character counter, New icons, Customizable keyboard shortcuts, Custom status items, Bug fixes
2 parents 5f3a67d + 4b75a4e commit 6318fc1

10 files changed

+1154
-295
lines changed

README.md

Lines changed: 75 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,16 @@ simplemde.value("This text will appear in the editor");
9090
- **allowAtxHeaderWithoutSpace**: If set to `true`, will render headers without a space after the `#`. Defaults to `false`.
9191
- **strikethrough**: If set to `false`, will not process GFM strikethrough syntax. Defaults to `true`.
9292
- **underscoresBreakWords**: If set to `true`, let underscores be a delimiter for separating words. Defaults to `false`.
93+
- **placeholder**: Custom placeholder that should be displayed
9394
- **previewRender**: Custom function for parsing the plaintext Markdown and returning HTML. Used when user previews.
9495
- **renderingConfig**: Adjust settings for parsing the Markdown during previewing (not editing).
9596
- **singleLineBreaks**: If set to `false`, disable parsing GFM single line breaks. Defaults to `true`.
9697
- **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">`
98+
- **shortcuts**: Keyboard shortcuts associated with this instance. Defaults to the [array of shortcuts](#keyboard-shortcuts).
9799
- **showIcons**: An array of icon names to show. Can be used to show specific icons hidden by default without completely customizing the toolbar.
98100
- **spellChecker**: If set to `false`, disable the spell checker. Defaults to `true`.
99-
- **status**: If set to `false`, hide the status bar. Defaults to `true`.
100-
- Optionally, you can set an array of status bar elements to include, and in what order.
101+
- **status**: If set to `false`, hide the status bar. Defaults to the array of built-in status bar items.
102+
- 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.
101103
- **tabSize**: If set, customize the tab size. Defaults to `2`.
102104
- **toolbar**: If set to `false`, hide the toolbar. Defaults to the [array of icons](#toolbar-icons).
103105
- **toolbarTips**: If set to `false`, disable toolbar button tips. Defaults to `true`.
@@ -131,24 +133,38 @@ var simplemde = new SimpleMDE({
131133
strikethrough: false,
132134
underscoresBreakWords: true,
133135
},
136+
placeholder: "Type here...",
134137
previewRender: function(plainText) {
135138
return customMarkdownParser(plainText); // Returns HTML from a custom parser
136139
},
137140
previewRender: function(plainText, preview) { // Async method
138141
setTimeout(function(){
139142
preview.innerHTML = customMarkdownParser(plainText);
140143
}, 250);
141-
144+
142145
return "Loading...";
143146
},
144147
renderingConfig: {
145148
singleLineBreaks: false,
146149
codeSyntaxHighlighting: true,
147150
},
151+
shortcuts: {
152+
drawTable: "Cmd-Alt-T"
153+
},
148154
showIcons: ["code", "table"],
149155
spellChecker: false,
150156
status: false,
151157
status: ["autosave", "lines", "words", "cursor"], // Optional usage
158+
status: ["autosave", "lines", "words", "cursor", {
159+
className: "keystrokes",
160+
defaultValue: function(el) {
161+
this.keystrokes = 0;
162+
el.innerHTML = "0 Keystrokes";
163+
},
164+
onUpdate: function(el) {
165+
el.innerHTML = ++this.keystrokes + " Keystrokes";
166+
}
167+
}], // Another optional usage, with a custom status bar item that counts keystrokes
152168
tabSize: 4,
153169
toolbar: false,
154170
toolbarTips: false,
@@ -157,30 +173,33 @@ var simplemde = new SimpleMDE({
157173

158174
#### Toolbar icons
159175

160-
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. Any `Ctrl` or `Alt` in the title tags will be converted automatically to their Mac equivalents when needed. Additionally, you can add a separator between any icons by adding `"|"` to the toolbar array.
176+
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)").
177+
178+
Additionally, you can add a separator between any icons by adding `"|"` to the toolbar array.
161179

162180
Name | Action | Tooltip<br>Class
163181
:--- | :----- | :--------------
164-
bold | toggleBold | Bold (Ctrl+B)<br>fa fa-bold
165-
italic | toggleItalic | Italic (Ctrl+I)<br>fa fa-italic
182+
bold | toggleBold | Bold<br>fa fa-bold
183+
italic | toggleItalic | Italic<br>fa fa-italic
166184
strikethrough | toggleStrikethrough | Strikethrough<br>fa fa-strikethrough
167-
heading | toggleHeadingSmaller | Heading (Ctrl+H)<br>fa fa-header
168-
heading-smaller | toggleHeadingSmaller | Smaller Heading (Ctrl+H)<br>fa fa-header
169-
heading-bigger | toggleHeadingBigger | Bigger Heading (Shift+Ctrl+H)<br>fa fa-lg fa-header
185+
heading | toggleHeadingSmaller | Heading<br>fa fa-header
186+
heading-smaller | toggleHeadingSmaller | Smaller Heading<br>fa fa-header
187+
heading-bigger | toggleHeadingBigger | Bigger Heading<br>fa fa-lg fa-header
170188
heading-1 | toggleHeading1 | Big Heading<br>fa fa-header fa-header-x fa-header-1
171189
heading-2 | toggleHeading2 | Medium Heading<br>fa fa-header fa-header-x fa-header-2
172190
heading-3 | toggleHeading3 | Small Heading<br>fa fa-header fa-header-x fa-header-3
173-
code | toggleCodeBlock | Code (Ctrl+Alt+C)<br>fa fa-code
174-
quote | toggleBlockquote | Quote (Ctrl+')<br>fa fa-quote-left
175-
unordered-list | toggleUnorderedList | Generic List (Ctrl+L)<br>fa fa-list-ul
176-
ordered-list | toggleOrderedList | Numbered List (Ctrl+Alt+L)<br>fa fa-list-ol
177-
link | drawLink | Create Link (Ctrl+K)<br>fa fa-link
178-
image | drawImage | Insert Image (Ctrl+Alt+I)<br>fa fa-picture-o
191+
code | toggleCodeBlock | Code<br>fa fa-code
192+
quote | toggleBlockquote | Quote<br>fa fa-quote-left
193+
unordered-list | toggleUnorderedList | Generic List<br>fa fa-list-ul
194+
ordered-list | toggleOrderedList | Numbered List<br>fa fa-list-ol
195+
clean-block | cleanBlock | Clean block<br>fa fa-eraser fa-clean-block
196+
link | drawLink | Create Link<br>fa fa-link
197+
image | drawImage | Insert Image<br>fa fa-picture-o
179198
table | drawTable | Insert Table<br>fa fa-table
180199
horizontal-rule | drawHorizontalRule | Insert Horizontal Line<br>fa fa-minus
181-
preview | togglePreview | Toggle Preview (Ctrl+P)<br>fa fa-eye no-disable
182-
side-by-side | toggleSideBySide | Toggle Side by Side (F9)<br>fa fa-columns no-disable no-mobile
183-
fullscreen | toggleFullScreen | Toggle Fullscreen (F11)<br>fa fa-arrows-alt no-disable no-mobile
200+
preview | togglePreview | Toggle Preview<br>fa fa-eye no-disable
201+
side-by-side | toggleSideBySide | Toggle Side by Side<br>fa fa-columns no-disable no-mobile
202+
fullscreen | toggleFullScreen | Toggle Fullscreen<br>fa fa-arrows-alt no-disable no-mobile
184203
guide | [This link](http://nextstepwebs.github.io/simplemde-markdown-editor/markdown-guide) | Markdown Guide<br>fa fa-question-circle
185204

186205
Customize the toolbar using the `toolbar` option like:
@@ -197,7 +216,7 @@ var simplemde = new SimpleMDE({
197216
name: "bold",
198217
action: SimpleMDE.toggleBold,
199218
className: "fa fa-bold",
200-
title: "Bold (Ctrl+B)",
219+
title: "Bold",
201220
},
202221
{
203222
name: "custom",
@@ -213,6 +232,43 @@ var simplemde = new SimpleMDE({
213232
});
214233
```
215234

235+
#### Keyboard shortcuts
236+
237+
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:
238+
239+
Shortcut | Action
240+
:------- | :-----
241+
*Cmd-'* | "toggleBlockquote"
242+
*Cmd-B* | "toggleBold"
243+
*Cmd-E* | "cleanBlock"
244+
*Cmd-H* | "toggleHeadingSmaller"
245+
*Cmd-I* | "toggleItalic"
246+
*Cmd-K* | "drawLink"
247+
*Cmd-L* | "toggleUnorderedList"
248+
*Cmd-P* | "togglePreview"
249+
*Cmd-Alt-C* | "toggleCodeBlock"
250+
*Cmd-Alt-I* | "drawImage"
251+
*Cmd-Alt-L* | "toggleOrderedList"
252+
*Shift-Cmd-H* | "toggleHeadingBigger"
253+
*F9* | "toggleSideBySide"
254+
*F11* | "toggleFullScreen"
255+
256+
Here is how you can change a few, while leaving others untouched:
257+
258+
```JavaScript
259+
var simplemde = new SimpleMDE({
260+
shortcuts: {
261+
"toggleOrderedList": "Ctrl-Alt-K", // alter the shortcut for toggleOrderedList
262+
"toggleCodeBlock": null, // unbind Ctrl-Alt-C
263+
"drawTable": "Cmd-Alt-T" // bind Cmd-Alt-T to drawTable action, which doesn't come with a default shortcut
264+
}
265+
});
266+
```
267+
268+
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.
269+
270+
The list of actions that can be bound is the same as the list of built-in actions available for [toolbar buttons](#toolbar-icons).
271+
216272
#### Height
217273

218274
To change the minimum height (before it starts auto-growing):

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "simplemde",
3-
"version": "1.9.0",
3+
"version": "1.10.0",
44
"homepage": "https://github.com/NextStepWebs/simplemde-markdown-editor",
55
"authors": [
66
"Wes Cossick"

debug/simplemde.css

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* simplemde v1.9.0
2+
* simplemde v1.10.0
33
* Copyright Next Step Webs, Inc.
44
* @link https://github.com/NextStepWebs/simplemde-markdown-editor
55
* @license MIT
@@ -551,6 +551,10 @@ span.CodeMirror-selectedtext { background: none; }
551551
content: 'words: '
552552
}
553553

554+
.editor-statusbar .characters:before {
555+
content: 'characters: '
556+
}
557+
554558
.editor-preview {
555559
padding: 10px;
556560
position: absolute;
@@ -659,6 +663,10 @@ span.CodeMirror-selectedtext { background: none; }
659663
.CodeMirror .CodeMirror-code .cm-strikethrough {
660664
text-decoration: line-through;
661665
}
666+
667+
.CodeMirror .CodeMirror-placeholder {
668+
opacity: .5;
669+
}
662670
.CodeMirror .cm-spell-error:not(.cm-url):not(.cm-comment):not(.cm-tag):not(.cm-word) {
663671
background: rgba(255, 0, 0, .15);
664672
}

0 commit comments

Comments
 (0)