Skip to content

Commit 57fcf52

Browse files
committed
Merge pull request sparksuite#107 from NextStepWebs/development
Custom preview rendering, Loads of bug fixes
2 parents cd17552 + 263827a commit 57fcf52

18 files changed

+9003
-8861
lines changed

README.md

Lines changed: 74 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ A drop-in JavaScript textarea replacement for writing beautiful and understandab
99
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.
1010

1111
## Quick start
12-
SimpleMDE is available on npm.
12+
SimpleMDE is available on [npm](https://www.npmjs.com/package/simplemde).
1313
```
1414
npm install simplemde --save
1515
```
@@ -32,7 +32,6 @@ And then load SimpleMDE on the first textarea on a page
3232
```HTML
3333
<script>
3434
var simplemde = new SimpleMDE();
35-
simplemde.render();
3635
</script>
3736
```
3837

@@ -43,7 +42,6 @@ Pure JavaScript method
4342
```HTML
4443
<script>
4544
var simplemde = new SimpleMDE({ element: document.getElementById("MyID") });
46-
simplemde.render();
4745
</script>
4846
```
4947

@@ -52,85 +50,110 @@ jQuery method
5250
```HTML
5351
<script>
5452
var simplemde = new SimpleMDE({ element: $("#MyID")[0] });
55-
simplemde.render();
5653
</script>
5754
```
5855

59-
## Get the content
56+
## Get/set the content
6057

6158
```JavaScript
6259
simplemde.value();
6360
```
6461

62+
```JavaScript
63+
simplemde.value("This text will appear in the editor");
64+
```
65+
6566
## Configuration
6667

68+
- **autofocus**: If set to `true`, autofocuses the editor. Defaults to `false`.
69+
- **autosave**: *Saves the text that's being written. It will forget the text when the form is submitted.*
70+
- **enabled**: If set to `true`, autosave the text. Defaults to `false`.
71+
- **delay**: Delay between saves, in milliseconds. Defaults to `10000` (10s).
72+
- **unique_id**: You must set a unique identifier so that SimpleMDE can autosave. Something that separates this from other textareas.
6773
- **element**: The DOM element for the textarea to use. Defaults to the first textarea on the page.
74+
- **indentWithTabs**: If set to `false`, indent using spaces instead of tabs. Defaults to `true`.
75+
- **initialValue**: If set, will customize the initial value of the editor.
76+
- **lineWrapping**: If set to `false`, disable line wrapping. Defaults to `true`.
77+
- **parsingConfig**: Adjust settings for parsing the Markdown during editing (not previewing).
78+
- **allowAtxHeaderWithoutSpace**: If set to `true`, will render headers without a space after the `#`. Defaults to `false`.
79+
- **fencedCodeBlocks**: If set to `false`, will not process GFM fenced code blocks syntax. Defaults to `true`.
80+
- **strikethrough**: If set to `false`, will not process GFM strikethrough syntax. Defaults to `true`.
81+
- **underscoresBreakWords**: If set to `true`, let underscores be a delimiter for separating words. Defaults to `false`.
82+
- **previewRender**: Custom function for parsing the plaintext Markdown and returning HTML. Used when user previews.
83+
- **singleLineBreaks**: If set to `false`, disable parsing GFM single line breaks. Defaults to `true`.
84+
- **spellChecker**: If set to `false`, disable the spell checker. Defaults to `true`.
6885
- **status**: If set to `false`, hide the status bar. Defaults to `true`.
6986
- Optionally, you can set an array of status bar elements to include, and in what order.
87+
- **tabSize**: If set, customize the tab size. Defaults to `2`.
7088
- **toolbar**: If set to `false`, hide the toolbar. Defaults to the [array of icons](#toolbar-icons).
71-
- **toolbarTips**: If set to `false`, disable toolbar button tips. Defaults to `true`.
7289
- **toolbarGuideIcon**: If set to `false`, disable guide icon in the toolbar. Defaults to `true`.
73-
- **autofocus**: If set to `true`, autofocuses the editor. Defaults to `false`.
74-
- **lineWrapping**: If set to `false`, disable line wrapping. Defaults to `true`.
75-
- **indentWithTabs**: If set to `false`, indent using spaces instead of tabs. Defaults to `true`.
76-
- **tabSize**: If set, customize the tab size. Defaults to `2`.
77-
- **initialValue**: If set, will customize the initial value of the editor.
78-
- **spellChecker**: If set to `false`, disable the spell checker. Defaults to `true`.
79-
- **singleLineBreaks**: If set to `false`, disable parsing GFM single line breaks. Defaults to `true`.
80-
- **autosave**: *Saves the text that's being written. It will forget the text when the form is submitted.*
81-
- **enabled**: If set to `true`, autosave the text. Defaults to `false`.
82-
- **unique_id**: You must set a unique identifier so that SimpleMDE can autosave. Something that separates this from other textareas.
83-
- **delay**: Delay between saves, in milliseconds. Defaults to `10000` (10s).
90+
- **toolbarTips**: If set to `false`, disable toolbar button tips. Defaults to `true`.
8491

8592
```JavaScript
8693
var simplemde = new SimpleMDE({
87-
element: document.getElementById("MyID"),
88-
status: false,
89-
status: ['autosave', 'lines', 'words', 'cursor'], // Optional usage
90-
toolbar: false,
91-
toolbarTips: false,
92-
toolbarGuideIcon: false,
9394
autofocus: true,
94-
lineWrapping: false,
95-
indentWithTabs: false,
96-
tabSize: 4,
97-
initialValue: "Hello world!",
98-
spellChecker: false,
99-
singleLineBreaks: false,
10095
autosave: {
10196
enabled: true,
10297
unique_id: "MyUniqueID",
10398
delay: 1000,
10499
},
100+
element: document.getElementById("MyID"),
101+
indentWithTabs: false,
102+
initialValue: "Hello world!",
103+
lineWrapping: false,
104+
parsingConfig: {
105+
allowAtxHeaderWithoutSpace: true,
106+
fencedCodeBlocks: false,
107+
strikethrough: false,
108+
underscoresBreakWords: true,
109+
},
110+
previewRender: function(plainText) {
111+
return customMarkdownParser(plainText); // Returns HTML from a custom parser
112+
},
113+
previewRender: function(plainText, preview) { // Async method
114+
setTimeout(function(){
115+
preview.innerHTML = customMarkdownParser(plainText);
116+
}, 250);
117+
118+
return "Loading...";
119+
}
120+
singleLineBreaks: false,
121+
spellChecker: false,
122+
status: false,
123+
status: ['autosave', 'lines', 'words', 'cursor'], // Optional usage
124+
tabSize: 4,
125+
toolbar: false,
126+
toolbarGuideIcon: false,
127+
toolbarTips: false,
105128
});
106129
```
107130

108131
#### Toolbar icons
109132

110133
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. The `Ctrl` and `Alt` in the title tags will be changed automatically to their Mac equivalents when needed. Additionally, you can add a separator between any icons by adding `"|"` to the toolbar array.
111134

112-
Name | Action | Class | Tooltip
113-
:--- | :----- | :---- | :------
114-
bold | toggleBold | fa fa-bold | Bold (Ctrl+B)
115-
italic | toggleItalic | fa fa-italic | Italic (Ctrl+I)
116-
strikethrough | toggleStrikethrough | fa fa-strikethrough | Strikethrough
117-
heading | toggleHeadingSmaller | fa fa-header | Heading (Ctrl+H)
118-
heading-smaller | toggleHeadingSmaller | fa fa-header | Smaller Heading (Ctrl+H)
119-
heading-bigger | toggleHeadingBigger | fa fa-lg fa-header | Bigger Heading (Shift+Ctrl+H)
120-
heading-1 | toggleHeading1 | fa fa-header fa-header-x fa-header-1 | Big Heading
121-
heading-2 | toggleHeading2 | fa fa-header fa-header-x fa-header-2 | Medium Heading
122-
heading-3 | toggleHeading3 | fa fa-header fa-header-x fa-header-3 | Small Heading
123-
code | toggleCodeBlock | fa fa-code | Code (Ctrl+Alt+C)
124-
quote | toggleBlockquote | fa fa-quote-left | Quote (Ctrl+')
125-
unordered-list | toggleUnorderedList | fa fa-list-ul | Generic List (Ctrl+L)
126-
numbered-list | toggleOrderedList | fa fa-list-ol | Numbered List (Ctrl+Alt+L)
127-
link | drawLink | fa fa-link | Create Link (Ctrl+K)
128-
image | drawImage | fa fa-picture-o | Insert Image (Ctrl+Alt+I)
129-
horizontal-rule | drawHorizontalRule | fa fa-minus | Insert Horizontal Line
130-
preview | togglePreview | fa fa-eye | Toggle Preview (Ctrl+P)
131-
side-by-side | toggleSideBySide | fa fa-columns | Toggle Side by Side (F9)
132-
fullscreen | toggleFullScreen | fa fa-arrows-alt | Toggle Fullscreen (F11)
133-
guide | [This link](http://nextstepwebs.github.io/simplemde-markdown-editor/markdown-guide) | fa fa-question-circle | Markdown Guide
135+
Name | Action | Tooltip<br>Class
136+
:--- | :----- | :--------------
137+
bold | toggleBold | Bold (Ctrl+B)<br>fa fa-bold
138+
italic | toggleItalic | Italic (Ctrl+I)<br>fa fa-italic
139+
strikethrough | toggleStrikethrough | Strikethrough<br>fa fa-strikethrough
140+
heading | toggleHeadingSmaller | Heading (Ctrl+H)<br>fa fa-header
141+
heading-smaller | toggleHeadingSmaller | Smaller Heading (Ctrl+H)<br>fa fa-header
142+
heading-bigger | toggleHeadingBigger | Bigger Heading (Shift+Ctrl+H)<br>fa fa-lg fa-header
143+
heading-1 | toggleHeading1 | Big Heading<br>fa fa-header fa-header-x fa-header-1
144+
heading-2 | toggleHeading2 | Medium Heading<br>fa fa-header fa-header-x fa-header-2
145+
heading-3 | toggleHeading3 | Small Heading<br>fa fa-header fa-header-x fa-header-3
146+
code | toggleCodeBlock | Code (Ctrl+Alt+C)<br>fa fa-code
147+
quote | toggleBlockquote | Quote (Ctrl+')<br>fa fa-quote-left
148+
unordered-list | toggleUnorderedList | Generic List (Ctrl+L)<br>fa fa-list-ul
149+
ordered-list | toggleOrderedList | Numbered List (Ctrl+Alt+L)<br>fa fa-list-ol
150+
link | drawLink | Create Link (Ctrl+K)<br>fa fa-link
151+
image | drawImage | Insert Image (Ctrl+Alt+I)<br>fa fa-picture-o
152+
horizontal-rule | drawHorizontalRule | Insert Horizontal Line<br>fa fa-minus
153+
preview | togglePreview | Toggle Preview (Ctrl+P)<br>fa fa-eye
154+
side-by-side | toggleSideBySide | Toggle Side by Side (F9)<br>fa fa-columns
155+
fullscreen | toggleFullScreen | Toggle Fullscreen (F11)<br>fa fa-arrows-alt
156+
guide | [This link](http://nextstepwebs.github.io/simplemde-markdown-editor/markdown-guide) | Markdown Guide<br>fa fa-question-circle
134157

135158
Customize the toolbar using the `toolbar` option like:
136159

0 commit comments

Comments
 (0)