Merge pull request #353 from NextStepWebs/development

Development
master 1.11.0
Wes Cossick 8 years ago
commit 316b8a58f8

@ -1,5 +1,6 @@
language: node_js language: node_js
node_js: node_js:
- '6'
- '5' - '5'
- '4' - '4'
- '0.12' - '0.12'

@ -20,11 +20,11 @@ Via [bower](https://www.bower.io).
bower install simplemde --save bower install simplemde --save
``` ```
Via [jsDelivr](http://www.jsdelivr.com/#!simplemde). *Please note, jsDelivr may take a few days to update to the latest release.* Via [jsDelivr](https://www.jsdelivr.com/#!simplemde). *Please note, jsDelivr may take a few days to update to the latest release.*
```HTML ```HTML
<link rel="stylesheet" href="//cdn.jsdelivr.net/simplemde/latest/simplemde.min.css"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.css">
<script src="//cdn.jsdelivr.net/simplemde/latest/simplemde.min.js"></script> <script src="https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.js"></script>
``` ```
## Quick start ## Quick start
@ -103,6 +103,7 @@ simplemde.value("This text will appear in the editor");
- **spellChecker**: If set to `false`, disable the spell checker. Defaults to `true`. - **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. - **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. - 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`.
- **tabSize**: If set, customize the tab size. Defaults to `2`. - **tabSize**: If set, customize the tab size. Defaults to `2`.
- **toolbar**: If set to `false`, hide the toolbar. Defaults to the [array of icons](#toolbar-icons). - **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`. - **toolbarTips**: If set to `false`, disable toolbar button tips. Defaults to `true`.
@ -170,6 +171,7 @@ var simplemde = new SimpleMDE({
el.innerHTML = ++this.keystrokes + " Keystrokes"; el.innerHTML = ++this.keystrokes + " Keystrokes";
} }
}], // Another optional usage, with a custom status bar item that counts keystrokes }], // Another optional usage, with a custom status bar item that counts keystrokes
styleSelectedText: false,
tabSize: 4, tabSize: 4,
toolbar: false, toolbar: false,
toolbarTips: false, toolbarTips: false,
@ -225,7 +227,7 @@ var simplemde = new SimpleMDE({
}, },
{ {
name: "custom", name: "custom",
action: customFunction(editor){ action: function customFunction(editor){
// Add your own code // Add your own code
}, },
className: "fa fa-star", className: "fa fa-star",
@ -324,6 +326,6 @@ simplemde.clearAutosavedValue(); // no returned value
``` ```
## How it works ## How it works
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://fortawesome.github.io/Font-Awesome/). 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).
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. 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.

@ -1,25 +1,23 @@
{ {
"name": "simplemde", "name": "simplemde",
"version": "1.10.1", "version": "1.11.0",
"homepage": "https://github.com/NextStepWebs/simplemde-markdown-editor", "homepage": "https://github.com/NextStepWebs/simplemde-markdown-editor",
"authors": [ "authors": [
"Wes Cossick" "Wes Cossick <https://wescossick.com>"
], ],
"description": "A simple, beautiful, and embeddable JavaScript Markdown editor.", "description": "A simple, beautiful, and embeddable JavaScript Markdown editor.",
"main": ["dist/simplemde.min.js", "dist/simplemde.min.css"], "main": ["src/js/simplemde.js", "src/css/simplemde.css"],
"moduleType": [ "keywords": [
"globals" "embeddable",
], "markdown",
"keywords": [ "editor",
"embeddable", "javascript",
"markdown", "wysiwyg"
"editor", ],
"javascript", "license": "MIT",
"wysiwyg" "ignore": [
], "**/.*",
"license": "MIT", "node_modules",
"ignore": [ "bower_components"
"node_modules", ]
"bower_components"
]
} }

@ -1,5 +1,5 @@
/** /**
* simplemde v1.10.1 * simplemde v1.11.0
* Copyright Next Step Webs, Inc. * Copyright Next Step Webs, Inc.
* @link https://github.com/NextStepWebs/simplemde-markdown-editor * @link https://github.com/NextStepWebs/simplemde-markdown-editor
* @license MIT * @license MIT
@ -58,7 +58,7 @@
} }
.cm-fat-cursor .CodeMirror-cursor { .cm-fat-cursor .CodeMirror-cursor {
width: auto; width: auto;
border: 0; border: 0 !important;
background: #7e7; background: #7e7;
} }
.cm-fat-cursor div.CodeMirror-cursors { .cm-fat-cursor div.CodeMirror-cursors {
@ -197,6 +197,7 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
.CodeMirror-gutters { .CodeMirror-gutters {
position: absolute; left: 0; top: 0; position: absolute; left: 0; top: 0;
min-height: 100%;
z-index: 3; z-index: 3;
} }
.CodeMirror-gutter { .CodeMirror-gutter {
@ -251,6 +252,8 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
position: relative; position: relative;
overflow: visible; overflow: visible;
-webkit-tap-highlight-color: transparent; -webkit-tap-highlight-color: transparent;
-webkit-font-variant-ligatures: none;
font-variant-ligatures: none;
} }
.CodeMirror-wrap pre { .CodeMirror-wrap pre {
word-wrap: break-word; word-wrap: break-word;
@ -669,5 +672,5 @@ span.CodeMirror-selectedtext { background: none; }
opacity: .5; opacity: .5;
} }
.CodeMirror .cm-spell-error:not(.cm-url):not(.cm-comment):not(.cm-tag):not(.cm-word) { .CodeMirror .cm-spell-error:not(.cm-url):not(.cm-comment):not(.cm-tag):not(.cm-word) {
background: rgba(255, 0, 0, .15); background: rgba(255, 0, 0, .15);
} }

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -1,6 +1,7 @@
"use strict"; "use strict";
var gulp = require("gulp"), var gulp = require("gulp"),
minifycss = require("gulp-minify-css"), minifycss = require("gulp-clean-css"),
uglify = require("gulp-uglify"), uglify = require("gulp-uglify"),
concat = require("gulp-concat"), concat = require("gulp-concat"),
header = require("gulp-header"), header = require("gulp-header"),
@ -8,11 +9,10 @@ var gulp = require("gulp"),
pkg = require("./package.json"), pkg = require("./package.json"),
debug = require("gulp-debug"), debug = require("gulp-debug"),
eslint = require("gulp-eslint"), eslint = require("gulp-eslint"),
prettify = require("gulp-jsbeautifier"); prettify = require("gulp-jsbeautifier"),
var browserify = require("browserify"); browserify = require("browserify"),
var source = require("vinyl-source-stream"); source = require("vinyl-source-stream"),
var rename = require("gulp-rename"); rename = require("gulp-rename");
var banner = ["/**", var banner = ["/**",
" * <%= pkg.name %> v<%= pkg.version %>", " * <%= pkg.name %> v<%= pkg.version %>",
@ -45,10 +45,9 @@ gulp.task("lint", ["prettify-js"], function() {
function taskBrowserify(opts) { function taskBrowserify(opts) {
return browserify("./src/js/simplemde.js", opts) return browserify("./src/js/simplemde.js", opts)
.bundle(); .bundle();
} }
gulp.task("browserify:dev", ["lint"], function() { gulp.task("browserify:debug", ["lint"], function() {
return taskBrowserify({debug:true, standalone:"SimpleMDE"}) return taskBrowserify({debug:true, standalone:"SimpleMDE"})
.pipe(source("simplemde.debug.js")) .pipe(source("simplemde.debug.js"))
.pipe(buffer()) .pipe(buffer())
@ -56,7 +55,7 @@ gulp.task("browserify:dev", ["lint"], function() {
.pipe(gulp.dest("./debug/")); .pipe(gulp.dest("./debug/"));
}); });
gulp.task("browserify:min", ["lint"], function() { gulp.task("browserify", ["lint"], function() {
return taskBrowserify({standalone:"SimpleMDE"}) return taskBrowserify({standalone:"SimpleMDE"})
.pipe(source("simplemde.js")) .pipe(source("simplemde.js"))
.pipe(buffer()) .pipe(buffer())
@ -64,7 +63,7 @@ gulp.task("browserify:min", ["lint"], function() {
.pipe(gulp.dest("./debug/")); .pipe(gulp.dest("./debug/"));
}); });
gulp.task("scripts", ["browserify:dev", "browserify:min", "lint"], function() { gulp.task("scripts", ["browserify:debug", "browserify", "lint"], function() {
var js_files = ["./debug/simplemde.js"]; var js_files = ["./debug/simplemde.js"];
return gulp.src(js_files) return gulp.src(js_files)

@ -1,69 +1,48 @@
{ {
"name": "simplemde", "name": "simplemde",
"version": "1.10.1", "version": "1.11.0",
"description": "A simple, beautiful, and embeddable JavaScript Markdown editor. Features autosaving and spell checking.", "description": "A simple, beautiful, and embeddable JavaScript Markdown editor. Features autosaving and spell checking.",
"keywords": [ "keywords": [
"embeddable", "embeddable",
"markdown", "markdown",
"editor", "editor",
"javascript", "javascript",
"wysiwyg" "wysiwyg"
], ],
"homepage": "https://github.com/NextStepWebs/simplemde-markdown-editor", "homepage": "https://github.com/NextStepWebs/simplemde-markdown-editor",
"main": "./src/js/simplemde.js", "main": "./src/js/simplemde.js",
"license": "MIT", "license": "MIT",
"company": "Next Step Webs, Inc.", "company": "Next Step Webs, Inc.",
"author": { "author": {
"name": "Wes Cossick", "name": "Wes Cossick",
"url": "http://www.WesCossick.com" "url": "http://www.WesCossick.com"
}, },
"bugs": { "bugs": {
"url": "https://github.com/NextStepWebs/simplemde-markdown-editor/issues" "url": "https://github.com/NextStepWebs/simplemde-markdown-editor/issues"
}, },
"dependencies": { "dependencies": {
"codemirror": "codemirror/CodeMirror", "codemirror": "*",
"codemirror-spell-checker": "nextstepwebs/codemirror-spell-checker", "codemirror-spell-checker": "*",
"marked": "0.3.5" "marked": "*"
}, },
"devDependencies": { "devDependencies": {
"browserify": "^11.2.0", "browserify": "*",
"browserify-shim": "^3.8.10", "debug": "*",
"debug": "^2.2.0", "eslint": "*",
"eslint": "*", "gulp": "*",
"gulp": "*", "gulp-concat": "*",
"gulp-concat": "*", "gulp-debug": "*",
"gulp-debug": "^2.1.1", "gulp-eslint": "*",
"gulp-eslint": "*", "gulp-header": "*",
"gulp-header": "*", "gulp-jsbeautifier": "*",
"gulp-jsbeautifier": "*", "gulp-clean-css": "*",
"gulp-minify-css": "^1.2.1", "gulp-rename": "*",
"gulp-rename": "^1.2.2", "gulp-uglify": "*",
"gulp-uglify": "*", "vinyl-source-stream": "*",
"vinyl-source-stream": "*", "vinyl-buffer": "*"
"vinyl-buffer": "*"
},
"browserify": {
"transform": [
"browserify-shim"
]
},
"browser": {
"spell-checker": "./node_modules/codemirror-spell-checker/src/js/spell-checker.js",
"typo": "./node_modules/codemirror-spell-checker/src/js/typo.js"
},
"browserify-shim": {
"spell-checker": {
"depends": [
"typo:Typo",
"codemirror:CodeMirror"
]
},
"typo": {
"exports": "Typo"
}
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/NextStepWebs/simplemde-markdown-editor" "url": "https://github.com/NextStepWebs/simplemde-markdown-editor"
} }
} }

@ -7,9 +7,10 @@ require("codemirror/addon/display/fullscreen.js");
require("codemirror/mode/markdown/markdown.js"); require("codemirror/mode/markdown/markdown.js");
require("codemirror/addon/mode/overlay.js"); require("codemirror/addon/mode/overlay.js");
require("codemirror/addon/display/placeholder.js"); require("codemirror/addon/display/placeholder.js");
require("codemirror/addon/selection/mark-selection.js");
require("codemirror/mode/gfm/gfm.js"); require("codemirror/mode/gfm/gfm.js");
require("codemirror/mode/xml/xml.js"); require("codemirror/mode/xml/xml.js");
require("spell-checker"); var CodeMirrorSpellChecker = require("codemirror-spell-checker");
var marked = require("marked"); var marked = require("marked");
@ -739,6 +740,9 @@ function toggleSideBySide(editor) {
} else { } else {
cm.off("update", cm.sideBySideRenderingFunction); cm.off("update", cm.sideBySideRenderingFunction);
} }
// Refresh to fix selection being off (#309)
cm.refresh();
} }
@ -1048,7 +1052,7 @@ function extend(target) {
/* The right word count in respect for CJK. */ /* The right word count in respect for CJK. */
function wordCount(data) { function wordCount(data) {
var pattern = /[a-zA-Z0-9_\u0392-\u03c9]+|[\u4E00-\u9FFF\u3400-\u4dbf\uf900-\ufaff\u3040-\u309f\uac00-\ud7af]+/g; var pattern = /[a-zA-Z0-9_\u0392-\u03c9\u0410-\u04F9]+|[\u4E00-\u9FFF\u3400-\u4dbf\uf900-\ufaff\u3040-\u309f\uac00-\ud7af]+/g;
var m = data.match(pattern); var m = data.match(pattern);
var count = 0; var count = 0;
if(m === null) return count; if(m === null) return count;
@ -1238,7 +1242,7 @@ var toolbarBuiltInButtons = {
var insertTexts = { var insertTexts = {
link: ["[", "](#url#)"], link: ["[", "](#url#)"],
image: ["![", "](#url#)"], image: ["![](", "#url#)"],
table: ["", "\n\n| Column 1 | Column 2 | Column 3 |\n| -------- | -------- | -------- |\n| Text | Text | Text |\n\n"], table: ["", "\n\n| Column 1 | Column 2 | Column 3 |\n| -------- | -------- | -------- |\n| Text | Text | Text |\n\n"],
horizontalRule: ["", "\n\n-----\n\n"] horizontalRule: ["", "\n\n-----\n\n"]
}; };
@ -1465,6 +1469,10 @@ SimpleMDE.prototype.render = function(el) {
backdrop = options.parsingConfig; backdrop = options.parsingConfig;
backdrop.name = "gfm"; backdrop.name = "gfm";
backdrop.gitHubSpice = false; backdrop.gitHubSpice = false;
CodeMirrorSpellChecker({
codeMirrorInstance: CodeMirror
});
} else { } else {
mode = options.parsingConfig; mode = options.parsingConfig;
mode.name = "gfm"; mode.name = "gfm";
@ -1483,7 +1491,8 @@ SimpleMDE.prototype.render = function(el) {
extraKeys: keyMaps, extraKeys: keyMaps,
lineWrapping: (options.lineWrapping === false) ? false : true, lineWrapping: (options.lineWrapping === false) ? false : true,
allowDropFileTypes: ["text/plain"], allowDropFileTypes: ["text/plain"],
placeholder: options.placeholder || el.getAttribute("placeholder") || "" placeholder: options.placeholder || el.getAttribute("placeholder") || "",
styleSelectedText: (options.styleSelectedText != undefined) ? options.styleSelectedText : true
}); });
if(options.forceSync === true) { if(options.forceSync === true) {
@ -1508,6 +1517,13 @@ SimpleMDE.prototype.render = function(el) {
this.gui.sideBySide = this.createSideBySide(); this.gui.sideBySide = this.createSideBySide();
this._rendered = this.element; this._rendered = this.element;
// Fixes CodeMirror bug (#344)
var temp_cm = this.codemirror;
setTimeout(function() {
temp_cm.refresh();
}.bind(temp_cm), 0);
}; };
// Safari, in Private Browsing Mode, looks like it supports localStorage but all calls to setItem throw QuotaExceededError. We're going to detect this and set a variable accordingly. // Safari, in Private Browsing Mode, looks like it supports localStorage but all calls to setItem throw QuotaExceededError. We're going to detect this and set a variable accordingly.
@ -1672,9 +1688,7 @@ SimpleMDE.prototype.createToolbar = function(items) {
var nonSeparatorIconsFollow = false; var nonSeparatorIconsFollow = false;
for(var x = (i + 1); x < items.length; x++) { for(var x = (i + 1); x < items.length; x++) {
console.log(x);
if(items[x] !== "|" && (!self.options.hideIcons || self.options.hideIcons.indexOf(items[x].name) == -1)) { if(items[x] !== "|" && (!self.options.hideIcons || self.options.hideIcons.indexOf(items[x].name) == -1)) {
console.log(items[x]);
nonSeparatorIconsFollow = true; nonSeparatorIconsFollow = true;
} }
} }
@ -1696,7 +1710,8 @@ SimpleMDE.prototype.createToolbar = function(items) {
// bind events, special for info // bind events, special for info
if(item.action) { if(item.action) {
if(typeof item.action === "function") { if(typeof item.action === "function") {
el.onclick = function() { el.onclick = function(e) {
e.preventDefault();
item.action(self); item.action(self);
}; };
} else if(typeof item.action === "string") { } else if(typeof item.action === "string") {
@ -1767,14 +1782,14 @@ SimpleMDE.prototype.createStatusbar = function(status) {
if(name === "words") { if(name === "words") {
defaultValue = function(el) { defaultValue = function(el) {
el.innerHTML = "0"; el.innerHTML = wordCount(cm.getValue());
}; };
onUpdate = function(el) { onUpdate = function(el) {
el.innerHTML = wordCount(cm.getValue()); el.innerHTML = wordCount(cm.getValue());
}; };
} else if(name === "lines") { } else if(name === "lines") {
defaultValue = function(el) { defaultValue = function(el) {
el.innerHTML = "0"; el.innerHTML = cm.lineCount();
}; };
onUpdate = function(el) { onUpdate = function(el) {
el.innerHTML = cm.lineCount(); el.innerHTML = cm.lineCount();
@ -1989,9 +2004,17 @@ SimpleMDE.prototype.toTextArea = function() {
var cm = this.codemirror; var cm = this.codemirror;
var wrapper = cm.getWrapperElement(); var wrapper = cm.getWrapperElement();
wrapper.parentNode.removeChild(this.gui.toolbar); if(wrapper.parentNode) {
wrapper.parentNode.removeChild(this.gui.statusbar); if(this.gui.toolbar) {
wrapper.parentNode.removeChild(this.gui.sideBySide); wrapper.parentNode.removeChild(this.gui.toolbar);
}
if(this.gui.statusbar) {
wrapper.parentNode.removeChild(this.gui.statusbar);
}
if(this.gui.sideBySide) {
wrapper.parentNode.removeChild(this.gui.sideBySide);
}
}
cm.toTextArea(); cm.toTextArea();

Loading…
Cancel
Save