Skip to content

Commit

Permalink
Merge pull request #9 from NextStepWebs/development
Browse files Browse the repository at this point in the history
Autosaving, More options, Split out Font Awesome, Fix bugs
  • Loading branch information
WesCossick committed Jun 26, 2015
2 parents 54de199 + 03da7bb commit 47132fc
Show file tree
Hide file tree
Showing 11 changed files with 647 additions and 2,108 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
localtesting/*
73 changes: 58 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,58 +6,100 @@ A drop-in JavaScript textarea replacement for writing beautiful and understandab
[![Preview](http://i.imgur.com/b9hFHFT.png)](http://nextstepwebs.github.io/simplemde-markdown-editor)

## Quick start
Available on [jsDelivr](http://www.jsdelivr.com/about.php)
SimpleMDE is available on [jsDelivr](http://www.jsdelivr.com/#!simplemde). Font Awesome is available on MaxCDN.

```
```HTML
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css">
<link rel="stylesheet" href="//cdn.jsdelivr.net/simplemde/latest/simplemde.min.css">
<script src="//cdn.jsdelivr.net/simplemde/latest/simplemde.min.js"></script>
```

And then load SimpleMDE on the first textarea on a page

```
```HTML
<script>
var simplemde = new SimpleMDE();
simplemde.render();
</script>
```

#### Use a specific textarea

Pure JavaScript method

```
```HTML
<script>
var simplemde = new SimpleMDE(document.getElementById("MyID"));
simplemde.render();
</script>
```

jQuery method

```
```HTML
<script>
var simplemde = new SimpleMDE($("#MyID")[0]);
simplemde.render();
</script>
```

## Get the content

```
simplemde.codemirror.getValue();
```JavaScript
simplemde.value();
```

## Configuration

- **element**: The DOM element for the textarea to use. Defaults to the first textarea on the page.
- **status**: If set false, hide the status bar. Defaults to true.
- **tools**: If set false, hide the toolbar. Defaults to true.
- **status**: If set to `false`, hide the status bar. Defaults to `true`.
- Optionally, you can set an array of status bar elements to include, and in what order.
- **toolbar**: If set to `false`, hide the toolbar. Defaults to `true`.
- **autofocus**: If set to `true`, autofocuses the editor. Defaults to `false`.
- **lineWrapping**: If set to `false`, disable line wrapping. Defaults to `true`.
- **indentWithTabs**: If set to `false`, indent using spaces instead of tabs. Defaults to `true`.
- **tabSize**: If set, customize the tab size. Defaults to `2`.
- **autosave**: *Saves the text that's being written. It will forget the text when the form is submitted.*
- **enabled**: If set to `true`, autosave the text. Defaults to `false`.
- **unique_id**: You must set a unique identifier so that SimpleMDE can autosave. Something that separates this from other textareas.
- **delay**: Delay between saves, in milliseconds. Defaults to `10000` (10s).

```JavaScript
var simplemde = new SimpleMDE({
element: document.getElementById("MyID"),
status: false,
status: ['autosave', 'lines', 'words', 'cursor'], // Optional usage
toolbar: false,
autofocus: true,
lineWrapping: false,
indentWithTabs: false,
tabSize: 4,
autosave: {
enabled: true,
unique_id: "MyUniqueID",
delay: 1000,
},
});
```

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

```CSS
.CodeMirror {
min-height: 300px;
}
```
new SimpleMDE({
element: document.getElementById("MyID"),
status: false,
tools: false,
});

Or, you can keep the height static:

```CSS
.CodeMirror {
height: 300px;
}
```

## How it works
SimpleMDE is an improvement of [lepture's Editor project](https://github.com/lepture/editor) and includes a great many number of changes. It is bundled with [CodeMirror](https://github.com/codemirror/codemirror) and [Font Awesome](http://fortawesome.github.io/Font-Awesome/).
SimpleMDE is an improvement of [lepture's Editor project](https://github.com/lepture/editor) and includes a great many number of changes. It is bundled with [CodeMirror](https://github.com/codemirror/codemirror) and depends on [Font Awesome](http://fortawesome.github.io/Font-Awesome/).

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 has been added to the top and bottom, respectively. Previews are rendered by [Marked](https://github.com/chjj/marked).

Expand All @@ -74,3 +116,4 @@ As mentioned earlier, SimpleMDE is an improvement of [lepture's Editor project](
- Improved preview rendering in many ways
- Improved as-you-type appearance of headers and code blocks
- Simplified the toolbar
- Many new options during instantiation
7 changes: 2 additions & 5 deletions simplemde.min.css

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions simplemde.min.js

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions source files/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ Minify the JS in this order:

Minify the CSS in this order:

1. `theme.css`
1. `font-awesome.css`
1. `theme.css`
4 changes: 2 additions & 2 deletions source files/codemirror/codemirror.js
Original file line number Diff line number Diff line change
Expand Up @@ -6791,7 +6791,7 @@
// is needed on Webkit to be able to get line-level bounding
// rectangles for it (in measureChar).
var content = elt("span", null, null, webkit ? "padding-right: .1px" : null);
var builder = {pre: elt("pre", [content]), content: content,
var builder = {pre: elt("pre", [content], "CodeMirror-line"), content: content,
col: 0, pos: 0, cm: cm,
splitSpaces: (ie || webkit) && cm.getOption("lineWrapping")};
lineView.measure = {};
Expand Down Expand Up @@ -8729,7 +8729,7 @@

// THE END

CodeMirror.version = "5.3.1";
CodeMirror.version = "5.4.1";

return CodeMirror;
});
134 changes: 88 additions & 46 deletions source files/codemirror/continuelist.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,93 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE

(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";

var listRE = /^(\s*)(>[> ]*|[*+-]\s|(\d+)([.)]))(\s*)/,
emptyListRE = /^(\s*)(>[> ]*|[*+-]|(\d+)[.)])(\s*)$/,
unorderedListRE = /[*+-]\s/;

CodeMirror.commands.newlineAndIndentContinueMarkdownList = function(cm) {
if (cm.getOption("disableInput")) return CodeMirror.Pass;
var ranges = cm.listSelections(), replacements = [];
for (var i = 0; i < ranges.length; i++) {
var pos = ranges[i].head;
var eolState = cm.getStateAfter(pos.line);
var inList = eolState.list !== false;
var inQuote = eolState.quote !== 0;

var line = cm.getLine(pos.line), match = listRE.exec(line);
if (!ranges[i].empty() || (!inList && !inQuote) || !match) {
cm.execCommand("newlineAndIndent");
return;
}
if (emptyListRE.test(line)) {
cm.replaceRange("", {
line: pos.line, ch: 0
}, {
line: pos.line, ch: pos.ch + 1
});
replacements[i] = "\n";
} else {
var indent = match[1], after = match[5];
var bullet = unorderedListRE.test(match[2]) || match[2].indexOf(">") >= 0
? match[2]
: (parseInt(match[3], 10) + 1) + match[4];

replacements[i] = "\n" + indent + bullet + after;
}
}

cm.replaceSelections(replacements);
};
"use strict";

var listRE = /^(\s*)(>[> ]*|[*+-]\s|(\d+)([.)]))(\s*)/,
emptyListRE = /^(\s*)(>[> ]*|[*+-]|(\d+)[.)])(\s*)$/,
unorderedListRE = /[*+-]\s/;

CodeMirror.commands.newlineAndIndentContinueMarkdownList = function(cm) {
if (cm.getOption("disableInput")) return CodeMirror.Pass;
var ranges = cm.listSelections(),
replacements = [];
for (var i = 0; i < ranges.length; i++) {
var pos = ranges[i].head;
var eolState = cm.getStateAfter(pos.line);
var inList = eolState.list !== false;
var inQuote = eolState.quote !== 0;

var line = cm.getLine(pos.line),
match = listRE.exec(line);
if (!ranges[i].empty() || (!inList && !inQuote) || !match) {
cm.execCommand("newlineAndIndent");
return;
}
if (emptyListRE.test(line)) {
cm.replaceRange("", {
line: pos.line,
ch: 0
}, {
line: pos.line,
ch: pos.ch + 1
});
replacements[i] = "\n";
} else {
var indent = match[1],
after = match[5];
var bullet = unorderedListRE.test(match[2]) || match[2].indexOf(">") >= 0 ? match[2] : (parseInt(match[3], 10) + 1) + match[4];

replacements[i] = "\n" + indent + bullet + after;
}
}

cm.replaceSelections(replacements);
};

CodeMirror.commands.shiftTabAndIndentContinueMarkdownList = function(cm) {
var ranges = cm.listSelections();
var pos = ranges[0].head;
var eolState = cm.getStateAfter(pos.line);
var inList = eolState.list !== false;

if (inList) {
cm.execCommand('indentLess');
return;
}

if(cm.options.indentWithTabs){
cm.execCommand('insertTab');
}
else{
var spaces = Array(cm.options.tabSize + 1).join(" ");
cm.replaceSelection(spaces);
}
};

CodeMirror.commands.tabAndIndentContinueMarkdownList = function(cm) {
var ranges = cm.listSelections();
var pos = ranges[0].head;
var eolState = cm.getStateAfter(pos.line);
var inList = eolState.list !== false;

if (inList) {
cm.execCommand('indentMore');
return;
}

if(cm.options.indentWithTabs){
cm.execCommand('insertTab');
}
else{
var spaces = Array(cm.options.tabSize + 1).join(" ");
cm.replaceSelection(spaces);
}
};
});
Loading

0 comments on commit 47132fc

Please sign in to comment.