Merge pull request #114 from NextStepWebs/development

Intelligently download Font Awesome, New options, Bug fixes
pull/124/head 1.7.2
Wes Cossick 9 years ago
commit f32e103944

@ -21,12 +21,6 @@ SimpleMDE is also available on [jsDelivr](http://www.jsdelivr.com/#!simplemde).
<script src="//cdn.jsdelivr.net/simplemde/latest/simplemde.min.js"></script>
```
SimpleMDE depends on Font Awesome (load via MaxCDN for best performance).
```HTML
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css">
```
And then load SimpleMDE on the first textarea on a page
```HTML
@ -65,28 +59,30 @@ simplemde.value("This text will appear in the editor");
## Configuration
- **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`, autofocuses the editor. Defaults to `false`.
- **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`.
- **delay**: Delay between saves, in milliseconds. Defaults to `10000` (10s).
- **unique_id**: You must set a unique identifier so that SimpleMDE can autosave. Something that separates this from other textareas.
- **element**: The DOM element for the textarea to use. Defaults to the first textarea on the page.
- **hideIcons**: An array of icon names to hide. Can be used to hide specific icons without completely customizing the toolbar.
- **indentWithTabs**: If set to `false`, indent using spaces instead of tabs. Defaults to `true`.
- **initialValue**: If set, will customize the initial value of the editor.
- **lineWrapping**: If set to `false`, disable line wrapping. Defaults to `true`.
- **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`.
- **fencedCodeBlocks**: If set to `false`, will not process GFM fenced code blocks syntax. Defaults to `true`.
- **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`.
- **previewRender**: Custom function for parsing the plaintext Markdown and returning HTML. Used when user previews.
- **singleLineBreaks**: If set to `false`, disable parsing GFM single line breaks. Defaults to `true`.
- **renderingConfig**: Adjust settings for parsing the Markdown during previewing (not editing).
- **singleLineBreaks**: If set to `false`, disable parsing GFM single line breaks. Defaults to `true`.
- **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">`
- **spellChecker**: If set to `false`, disable the spell checker. 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.
- **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).
- **toolbarGuideIcon**: If set to `false`, disable guide icon in the toolbar. Defaults to `true`.
- **toolbarTips**: If set to `false`, disable toolbar button tips. Defaults to `true`.
```JavaScript
@ -98,12 +94,12 @@ var simplemde = new SimpleMDE({
delay: 1000,
},
element: document.getElementById("MyID"),
hideIcons: ["guide", "heading"],
indentWithTabs: false,
initialValue: "Hello world!",
lineWrapping: false,
parsingConfig: {
allowAtxHeaderWithoutSpace: true,
fencedCodeBlocks: false,
strikethrough: false,
underscoresBreakWords: true,
},
@ -117,13 +113,15 @@ var simplemde = new SimpleMDE({
return "Loading...";
}
singleLineBreaks: false,
renderingConfig: {
singleLineBreaks: false,
codeSyntaxHighlighting: true,
},
spellChecker: false,
status: false,
status: ['autosave', 'lines', 'words', 'cursor'], // Optional usage
tabSize: 4,
toolbar: false,
toolbarGuideIcon: false,
toolbarTips: false,
});
```
@ -150,9 +148,9 @@ ordered-list | toggleOrderedList | Numbered List (Ctrl+Alt+L)<br>fa fa-list-ol
link | drawLink | Create Link (Ctrl+K)<br>fa fa-link
image | drawImage | Insert Image (Ctrl+Alt+I)<br>fa fa-picture-o
horizontal-rule | drawHorizontalRule | Insert Horizontal Line<br>fa fa-minus
preview | togglePreview | Toggle Preview (Ctrl+P)<br>fa fa-eye
side-by-side | toggleSideBySide | Toggle Side by Side (F9)<br>fa fa-columns
fullscreen | toggleFullScreen | Toggle Fullscreen (F11)<br>fa fa-arrows-alt
preview | togglePreview | Toggle Preview (Ctrl+P)<br>fa fa-eye no-disable
side-by-side | toggleSideBySide | Toggle Side by Side (F9)<br>fa fa-columns no-disable no-mobile
fullscreen | toggleFullScreen | Toggle Fullscreen (F11)<br>fa fa-arrows-alt no-disable no-mobile
guide | [This link](http://nextstepwebs.github.io/simplemde-markdown-editor/markdown-guide) | Markdown Guide<br>fa fa-question-circle
Customize the toolbar using the `toolbar` option like:

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -19,10 +19,9 @@ gulp.task("downloads-codemirror", function(callback) {
var download_urls = [
"https://raw.githubusercontent.com/codemirror/CodeMirror/master/lib/codemirror.js",
"https://raw.githubusercontent.com/codemirror/CodeMirror/master/addon/edit/continuelist.js",
//"https://raw.githubusercontent.com/codemirror/CodeMirror/master/addon/edit/tablist.js", //waiting for PRs
"https://raw.githubusercontent.com/codemirror/CodeMirror/master/addon/display/fullscreen.js",
"https://raw.githubusercontent.com/codemirror/CodeMirror/master/addon/mode/overlay.js",
//"https://raw.githubusercontent.com/codemirror/CodeMirror/master/mode/gfm/gfm.js", //waiting for PRs
"https://raw.githubusercontent.com/codemirror/CodeMirror/master/mode/gfm/gfm.js",
"https://raw.githubusercontent.com/codemirror/CodeMirror/master/mode/markdown/markdown.js",
"https://raw.githubusercontent.com/codemirror/CodeMirror/master/mode/xml/xml.js"];

@ -1,6 +1,6 @@
{
"name": "simplemde",
"version": "1.7.1",
"version": "1.7.2",
"description": "A simple, beautiful, and embeddable JavaScript markdown editor. Features autosaving and spell checking.",
"keywords": [
"embeddable",

@ -177,7 +177,7 @@
content: "▼";
}
.editor-toolbar.disabled-for-preview a:not(.fa-eye):not(.fa-arrows-alt):not(.fa-columns) {
.editor-toolbar.disabled-for-preview a:not(.no-disable) {
pointer-events: none;
background: #fff;
border-color: transparent;
@ -185,7 +185,7 @@
}
@media only screen and (max-width: 700px) {
.editor-toolbar a.fa-columns {
.editor-toolbar a.no-mobile {
display: none;
}
}

@ -1534,6 +1534,10 @@
}
},
readOnlyChanged: function(val) {
if (!val) this.reset();
},
setUneditable: nothing,
needsContentAttribute: false
@ -1552,7 +1556,6 @@
init: function(display) {
var input = this, cm = input.cm;
var div = input.div = display.lineDiv;
div.contentEditable = "true";
disableBrowserMagic(div);
on(div, "paste", function(e) { handlePaste(e, cm); })
@ -1593,7 +1596,7 @@
on(div, "input", function() {
if (input.composing) return;
if (!input.pollContent())
if (isReadOnly(cm) || !input.pollContent())
runInOp(input.cm, function() {regChange(cm);});
});
@ -1818,17 +1821,24 @@
this.div.focus();
},
applyComposition: function(composing) {
if (composing.data && composing.data != composing.startData)
if (isReadOnly(this.cm))
operation(this.cm, regChange)(this.cm)
else if (composing.data && composing.data != composing.startData)
operation(this.cm, applyTextInput)(this.cm, composing.data, 0, composing.sel);
},
setUneditable: function(node) {
node.setAttribute("contenteditable", "false");
node.contentEditable = "false"
},
onKeyPress: function(e) {
e.preventDefault();
operation(this.cm, applyTextInput)(this.cm, String.fromCharCode(e.charCode == null ? e.keyCode : e.charCode), 0);
if (!isReadOnly(this.cm))
operation(this.cm, applyTextInput)(this.cm, String.fromCharCode(e.charCode == null ? e.keyCode : e.charCode), 0);
},
readOnlyChanged: function(val) {
this.div.contentEditable = String(val != "nocursor")
},
onContextMenu: nothing,
@ -5389,8 +5399,8 @@
cm.display.disabled = true;
} else {
cm.display.disabled = false;
if (!val) cm.display.input.reset();
}
cm.display.input.readOnlyChanged(val)
});
option("disableInput", false, function(cm, val) {if (!val) cm.display.input.reset();}, true);
option("dragDrop", true, dragDropChanged);
@ -8093,24 +8103,30 @@
}
};
var noHandlers = []
function getHandlers(emitter, type, copy) {
var arr = emitter._handlers && emitter._handlers[type]
if (copy) return arr && arr.length > 0 ? arr.slice() : noHandlers
else return arr || noHandlers
}
var off = CodeMirror.off = function(emitter, type, f) {
if (emitter.removeEventListener)
emitter.removeEventListener(type, f, false);
else if (emitter.detachEvent)
emitter.detachEvent("on" + type, f);
else {
var arr = emitter._handlers && emitter._handlers[type];
if (!arr) return;
for (var i = 0; i < arr.length; ++i)
if (arr[i] == f) { arr.splice(i, 1); break; }
var handlers = getHandlers(emitter, type, false)
for (var i = 0; i < handlers.length; ++i)
if (handlers[i] == f) { handlers.splice(i, 1); break; }
}
};
var signal = CodeMirror.signal = function(emitter, type /*, values...*/) {
var arr = emitter._handlers && emitter._handlers[type];
if (!arr) return;
var handlers = getHandlers(emitter, type, true)
if (!handlers.length) return;
var args = Array.prototype.slice.call(arguments, 2);
for (var i = 0; i < arr.length; ++i) arr[i].apply(null, args);
for (var i = 0; i < handlers.length; ++i) handlers[i].apply(null, args);
};
var orphanDelayedCallbacks = null;
@ -8123,8 +8139,8 @@
// them to be executed when the last operation ends, or, if no
// operation is active, when a timeout fires.
function signalLater(emitter, type /*, values...*/) {
var arr = emitter._handlers && emitter._handlers[type];
if (!arr) return;
var arr = getHandlers(emitter, type, false)
if (!arr.length) return;
var args = Array.prototype.slice.call(arguments, 2), list;
if (operationGroup) {
list = operationGroup.delayedCallbacks;
@ -8164,8 +8180,7 @@
}
function hasHandler(emitter, type) {
var arr = emitter._handlers && emitter._handlers[type];
return arr && arr.length > 0;
return getHandlers(emitter, type).length > 0
}
// Add on and off methods to a constructor's prototype, to make
@ -8819,7 +8834,7 @@
// THE END
CodeMirror.version = "5.6.1";
CodeMirror.version = "5.7.1";
return CodeMirror;
});

@ -3,126 +3,123 @@
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"), require("../markdown/markdown"), require("../../addon/mode/overlay"));
mod(require("../../lib/codemirror"), require("../markdown/markdown"), require("../../addon/mode/overlay"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror", "../markdown/markdown", "../../addon/mode/overlay"], mod);
define(["../../lib/codemirror", "../markdown/markdown", "../../addon/mode/overlay"], mod);
else // Plain browser env
mod(CodeMirror);
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";
var urlRE = /^((?:coap|doi|javascript|aaa|aaas|about|acap|cap|cid|crid|data|dav|dict|dns|file|ftp|geo|go|gopher|h323|http|https|iax|icap|im|imap|info|ipp|iris|iris\.beep|iris\.xpc|iris\.xpcs|iris\.lwz|ldap|mailto|mid|msrp|msrps|mtqp|mupdate|news|nfs|ni|nih|nntp|opaquelocktoken|pop|pres|rtsp|service|session|shttp|sieve|sip|sips|sms|snmp|soap\.beep|soap\.beeps|tag|tel|telnet|tftp|thismessage|tn3270|tip|tv|urn|vemmi|ws|wss|xcon|xcon-userid|xmlrpc\.beep|xmlrpc\.beeps|xmpp|z39\.50r|z39\.50s|adiumxtra|afp|afs|aim|apt|attachment|aw|beshare|bitcoin|bolo|callto|chrome|chrome-extension|com-eventbrite-attendee|content|cvs|dlna-playsingle|dlna-playcontainer|dtn|dvb|ed2k|facetime|feed|finger|fish|gg|git|gizmoproject|gtalk|hcp|icon|ipn|irc|irc6|ircs|itms|jar|jms|keyparc|lastfm|ldaps|magnet|maps|market|message|mms|ms-help|msnim|mumble|mvn|notes|oid|palm|paparazzi|platform|proxy|psyc|query|res|resource|rmi|rsync|rtmp|secondlife|sftp|sgn|skype|smb|soldat|spotify|ssh|steam|svn|teamspeak|things|udp|unreal|ut2004|ventrilo|view-source|webcal|wtai|wyciwyg|xfire|xri|ymsgr:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]|\([^\s()<>]*\))+(?:\([^\s()<>]*\)|[^\s`*!()\[\]{};:'".,<>?«»“”‘’]))/i
var urlRE = /^((?:(?:aaas?|about|acap|adiumxtra|af[ps]|aim|apt|attachment|aw|beshare|bitcoin|bolo|callto|cap|chrome(?:-extension)?|cid|coap|com-eventbrite-attendee|content|crid|cvs|data|dav|dict|dlna-(?:playcontainer|playsingle)|dns|doi|dtn|dvb|ed2k|facetime|feed|file|finger|fish|ftp|geo|gg|git|gizmoproject|go|gopher|gtalk|h323|hcp|https?|iax|icap|icon|im|imap|info|ipn|ipp|irc[6s]?|iris(?:\.beep|\.lwz|\.xpc|\.xpcs)?|itms|jar|javascript|jms|keyparc|lastfm|ldaps?|magnet|mailto|maps|market|message|mid|mms|ms-help|msnim|msrps?|mtqp|mumble|mupdate|mvn|news|nfs|nih?|nntp|notes|oid|opaquelocktoken|palm|paparazzi|platform|pop|pres|proxy|psyc|query|res(?:ource)?|rmi|rsync|rtmp|rtsp|secondlife|service|session|sftp|sgn|shttp|sieve|sips?|skype|sm[bs]|snmp|soap\.beeps?|soldat|spotify|ssh|steam|svn|tag|teamspeak|tel(?:net)?|tftp|things|thismessage|tip|tn3270|tv|udp|unreal|urn|ut2004|vemmi|ventrilo|view-source|webcal|wss?|wtai|wyciwyg|xcon(?:-userid)?|xfire|xmlrpc\.beeps?|xmpp|xri|ymsgr|z39\.50[rs]?):(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]|\([^\s()<>]*\))+(?:\([^\s()<>]*\)|[^\s`*!()\[\]{};:'".,<>?«»“”‘’]))/i
CodeMirror.defineMode("gfm", function(config, modeConfig) {
// Should GitHub spice be added (like linking #Num, SHA, etc.)
if (modeConfig.gitHubSpice === undefined)
modeConfig.gitHubSpice = true;
var codeDepth = 0;
function blankLine(state) {
state.code = false;
return null;
state.code = false;
return null;
}
var gfmOverlay = {
startState: function() {
return {
code: false,
codeBlock: false,
ateSpace: false
};
},
copyState: function(s) {
return {
code: s.code,
codeBlock: s.codeBlock,
ateSpace: s.ateSpace
};
},
token: function(stream, state) {
state.combineTokens = null;
startState: function() {
return {
code: false,
codeBlock: false,
ateSpace: false
};
},
copyState: function(s) {
return {
code: s.code,
codeBlock: s.codeBlock,
ateSpace: s.ateSpace
};
},
token: function(stream, state) {
state.combineTokens = null;
// Hack to prevent formatting override inside code blocks (block and inline)
if (state.codeBlock) {
if (stream.match(/^```/)) {
state.codeBlock = false;
return null;
}
stream.skipToEnd();
return null;
}
if (stream.sol()) {
state.code = false;
}
if (stream.sol() && stream.match(/^```/)) {
stream.skipToEnd();
state.codeBlock = true;
return null;
}
// If this block is changed, it may need to be updated in Markdown mode
if (stream.peek() === '`') {
stream.next();
var before = stream.pos;
stream.eatWhile('`');
var difference = 1 + stream.pos - before;
if (!state.code) {
codeDepth = difference;
state.code = true;
} else {
if (difference === codeDepth) { // Must be exact
state.code = false;
}
}
return null;
} else if (state.code) {
stream.next();
return null;
}
// Check if space. If so, links can be formatted later on
if (stream.eatSpace()) {
state.ateSpace = true;
return null;
}
if (stream.sol() || state.ateSpace) {
state.ateSpace = false;
if (modeConfig.gitHubSpice) {
if(stream.match(/^(?:[a-zA-Z0-9\-_]+\/)?(?:[a-zA-Z0-9\-_]+@)?(?:[a-f0-9]{7,40}\b)/)) {
// User/Project@SHA
// User@SHA
// SHA
state.combineTokens = true;
return "link";
} else if (stream.match(/^(?:[a-zA-Z0-9\-_]+\/)?(?:[a-zA-Z0-9\-_]+)?#[0-9]+\b/)) {
// User/Project#Num
// User#Num
// #Num
state.combineTokens = true;
return "link";
}
}
}
if (stream.match(urlRE) &&
stream.string.slice(stream.start - 2, stream.start) != "](") {
// URLs
// Taken from http://daringfireball.net/2010/07/improved_regex_for_matching_urls
// And then (issue #1160) simplified to make it not crash the Chrome Regexp engine
// And then limited url schemes to the CommonMark list, so foo:bar isn't matched as a URL
state.combineTokens = true;
return "link";
}
stream.next();
return null;
},
blankLine: blankLine
// Hack to prevent formatting override inside code blocks (block and inline)
if (state.codeBlock) {
if (stream.match(/^```+/)) {
state.codeBlock = false;
return null;
}
stream.skipToEnd();
return null;
}
if (stream.sol()) {
state.code = false;
}
if (stream.sol() && stream.match(/^```+/)) {
stream.skipToEnd();
state.codeBlock = true;
return null;
}
// If this block is changed, it may need to be updated in Markdown mode
if (stream.peek() === '`') {
stream.next();
var before = stream.pos;
stream.eatWhile('`');
var difference = 1 + stream.pos - before;
if (!state.code) {
codeDepth = difference;
state.code = true;
} else {
if (difference === codeDepth) { // Must be exact
state.code = false;
}
}
return null;
} else if (state.code) {
stream.next();
return null;
}
// Check if space. If so, links can be formatted later on
if (stream.eatSpace()) {
state.ateSpace = true;
return null;
}
if (stream.sol() || state.ateSpace) {
state.ateSpace = false;
if (modeConfig.gitHubSpice !== false) {
if(stream.match(/^(?:[a-zA-Z0-9\-_]+\/)?(?:[a-zA-Z0-9\-_]+@)?(?:[a-f0-9]{7,40}\b)/)) {
// User/Project@SHA
// User@SHA
// SHA
state.combineTokens = true;
return "link";
} else if (stream.match(/^(?:[a-zA-Z0-9\-_]+\/)?(?:[a-zA-Z0-9\-_]+)?#[0-9]+\b/)) {
// User/Project#Num
// User#Num
// #Num
state.combineTokens = true;
return "link";
}
}
}
if (stream.match(urlRE) &&
stream.string.slice(stream.start - 2, stream.start) != "](" &&
(stream.start == 0 || /\W/.test(stream.string.charAt(stream.start - 1)))) {
// URLs
// Taken from http://daringfireball.net/2010/07/improved_regex_for_matching_urls
// And then (issue #1160) simplified to make it not crash the Chrome Regexp engine
// And then limited url schemes to the CommonMark list, so foo:bar isn't matched as a URL
state.combineTokens = true;
return "link";
}
stream.next();
return null;
},
blankLine: blankLine
};
var markdownConfig = {
underscoresBreakWords: false,
taskLists: true,
fencedCodeBlocks: true,
strikethrough: true
underscoresBreakWords: false,
taskLists: true,
fencedCodeBlocks: '```',
strikethrough: true
};
for (var attr in modeConfig) {
markdownConfig[attr] = modeConfig[attr];
markdownConfig[attr] = modeConfig[attr];
}
markdownConfig.name = "markdown";
return CodeMirror.overlayMode(CodeMirror.getMode(config, markdownConfig), gfmOverlay);
@ -130,4 +127,4 @@ CodeMirror.defineMode("gfm", function(config, modeConfig) {
}, "markdown");
CodeMirror.defineMIME("text/x-gfm", "gfm");
});
});

@ -39,8 +39,10 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
if (modeCfg.underscoresBreakWords === undefined)
modeCfg.underscoresBreakWords = true;
// Turn on fenced code blocks? ("```" to start/end)
if (modeCfg.fencedCodeBlocks === undefined) modeCfg.fencedCodeBlocks = false;
// Use `fencedCodeBlocks` to configure fenced code blocks. false to
// disable, string to specify a precise regexp that the fence should
// match, and true to allow three or more backticks or tildes (as
// per CommonMark).
// Turn on task lists? ("- [ ] " and "- [x] ")
if (modeCfg.taskLists === undefined) modeCfg.taskLists = false;
@ -74,7 +76,9 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
, taskListRE = /^\[(x| )\](?=\s)/ // Must follow ulRE or olRE
, atxHeaderRE = modeCfg.allowAtxHeaderWithoutSpace ? /^(#+)/ : /^(#+)(?: |$)/
, setextHeaderRE = /^ *(?:\={1,}|-{1,})\s*$/
, textRE = /^[^#!\[\]*_\\<>` "'(~]+/;
, textRE = /^[^#!\[\]*_\\<>` "'(~]+/
, fencedCodeRE = new RegExp("^(" + (modeCfg.fencedCodeBlocks === true ? "~~~+|```+" : modeCfg.fencedCodeBlocks) +
")[ \\t]*([\\w+#]*)");
function switchInline(stream, state, f) {
state.f = state.inline = f;
@ -86,6 +90,9 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
return f(stream, state);
}
function lineIsEmpty(line) {
return !line || !/\S/.test(line.string)
}
// Blocks
@ -110,7 +117,8 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
state.trailingSpace = 0;
state.trailingSpaceNewLine = false;
// Mark this line as blank
state.thisLineHasContent = false;
state.prevLine = state.thisLine
state.thisLine = null
return null;
}
@ -141,7 +149,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
var match = null;
if (state.indentationDiff >= 4) {
stream.skipToEnd();
if (prevLineIsIndentedCode || !state.prevLineHasContent) {
if (prevLineIsIndentedCode || lineIsEmpty(state.prevLine)) {
state.indentation -= 4;
state.indentedCode = true;
return code;
@ -155,7 +163,8 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
if (modeCfg.highlightFormatting) state.formatting = "header";
state.f = state.inline;
return getType(state);
} else if (state.prevLineHasContent && !state.quote && !prevLineIsList && !prevLineIsIndentedCode && (match = stream.match(setextHeaderRE))) {
} else if (!lineIsEmpty(state.prevLine) && !state.quote && !prevLineIsList &&
!prevLineIsIndentedCode && (match = stream.match(setextHeaderRE))) {
state.header = match[0].charAt(0) == '=' ? 1 : 2;
if (modeCfg.highlightFormatting) state.formatting = "header";
state.f = state.inline;
@ -170,7 +179,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
} else if (stream.match(hrRE, true)) {
state.hr = true;
return hr;
} else if ((!state.prevLineHasContent || prevLineIsList) && (stream.match(ulRE, false) || stream.match(olRE, false))) {
} else if ((lineIsEmpty(state.prevLine) || prevLineIsList) && (stream.match(ulRE, false) || stream.match(olRE, false))) {
var listType = null;
if (stream.match(ulRE, true)) {
listType = 'ul';
@ -187,9 +196,10 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
state.f = state.inline;
if (modeCfg.highlightFormatting) state.formatting = ["list", "list-" + listType];
return getType(state);
} else if (modeCfg.fencedCodeBlocks && stream.match(/^```[ \t]*([\w+#]*)/, true)) {
} else if (modeCfg.fencedCodeBlocks && (match = stream.match(fencedCodeRE, true))) {
state.fencedChars = match[1]
// try switching mode
state.localMode = getMode(RegExp.$1);
state.localMode = getMode(match[2]);
if (state.localMode) state.localState = state.localMode.startState();
state.f = state.block = local;
if (modeCfg.highlightFormatting) state.formatting = "code-block";
@ -213,7 +223,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
}
function local(stream, state) {
if (stream.sol() && stream.match("```", false)) {
if (stream.sol() && state.fencedChars && stream.match(state.fencedChars, false)) {
state.localMode = state.localState = null;
state.f = state.block = leavingLocal;
return null;
@ -226,9 +236,10 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
}
function leavingLocal(stream, state) {
stream.match("```");
stream.match(state.fencedChars);
state.block = blockNormal;
state.f = inlineNormal;
state.fencedChars = null;
if (modeCfg.highlightFormatting) state.formatting = "code-block";
state.code = true;
var returnType = getType(state);
@ -656,8 +667,8 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
return {
f: blockNormal,
prevLineHasContent: false,
thisLineHasContent: false,
prevLine: null,
thisLine: null,
block: blockNormal,
htmlState: null,
@ -680,7 +691,8 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
quote: 0,
trailingSpace: 0,
trailingSpaceNewLine: false,
strikethrough: false
strikethrough: false,
fencedChars: null
};
},
@ -688,8 +700,8 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
return {
f: s.f,
prevLineHasContent: s.prevLineHasContent,
thisLineHasContent: s.thisLineHasContent,
prevLine: s.prevLine,
thisLine: s.this,
block: s.block,
htmlState: s.htmlState && CodeMirror.copyState(htmlMode, s.htmlState),
@ -715,7 +727,8 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
indentedCode: s.indentedCode,
trailingSpace: s.trailingSpace,
trailingSpaceNewLine: s.trailingSpaceNewLine,
md_inside: s.md_inside
md_inside: s.md_inside,
fencedChars: s.fencedChars
};
},
@ -724,22 +737,22 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
// Reset state.formatting
state.formatting = false;
if (stream.sol()) {
var forceBlankLine = !!state.header || state.hr;
if (stream != state.thisLine) {
var forceBlankLine = state.header || state.hr;
// Reset state.header and state.hr
state.header = 0;
state.hr = false;
if (stream.match(/^\s*$/, true) || forceBlankLine) {
state.prevLineHasContent = false;
blankLine(state);
return forceBlankLine ? this.token(stream, state) : null;
} else {
state.prevLineHasContent = state.thisLineHasContent;
state.thisLineHasContent = true;
if (!forceBlankLine) return null
state.prevLine = null
}
state.prevLine = state.thisLine
state.thisLine = stream
// Reset state.taskList
state.taskList = false;

@ -313,7 +313,8 @@ function toggleSideBySide(editor) {
* instead of just appearing.
*/
setTimeout(function() {
if(!cm.getOption("fullScreen")) toggleFullScreen(editor);
if(!cm.getOption("fullScreen"))
toggleFullScreen(editor);
preview.className += ' editor-preview-active-side'
}, 1);
toolbarButton.className += ' active';
@ -704,19 +705,19 @@ var toolbarBuiltInButtons = {
"preview": {
name: "preview",
action: togglePreview,
className: "fa fa-eye",
className: "fa fa-eye no-disable",
title: "Toggle Preview (Ctrl+P)",
},
"side-by-side": {
name: "side-by-side",
action: toggleSideBySide,
className: "fa fa-columns",
className: "fa fa-columns no-disable no-mobile",
title: "Toggle Side by Side (F9)",
},
"fullscreen": {
name: "fullscreen",
action: toggleFullScreen,
className: "fa fa-arrows-alt",
className: "fa fa-arrows-alt no-disable no-mobile",
title: "Toggle Fullscreen (F11)",
},
"guide": {
@ -733,11 +734,41 @@ var toolbar = ["bold", "italic", "heading", "|", "quote", "unordered-list", "ord
* Interface of SimpleMDE.
*/
function SimpleMDE(options) {
// Handle options parameter
options = options || {};
// Used later to refer to it's parent
options.parent = this;
// Check if Font Awesome needs to be auto downloaded
var autoDownloadFA = true;
if(options.autoDownloadFontAwesome === false) {
autoDownloadFA = false;
}
if(options.autoDownloadFontAwesome !== true) {
var styleSheets = document.styleSheets;
for(var i = 0; i < styleSheets.length; i++) {
if(!styleSheets[i].href)
continue;
if(styleSheets[i].href.indexOf("//maxcdn.bootstrapcdn.com/font-awesome/") > -1) {
autoDownloadFA = false;
}
}
}
if(autoDownloadFA) {
var link = document.createElement("link");
link.rel = "stylesheet";
link.href = "https://maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css";
document.getElementsByTagName("head")[0].appendChild(link);
}
// Find the textarea to use
if(options.element) {
this.element = options.element;
@ -747,6 +778,7 @@ function SimpleMDE(options) {
return;
}
// Handle toolbar and status bar
if(options.toolbar !== false)
options.toolbar = options.toolbar || SimpleMDE.toolbar;
@ -755,6 +787,7 @@ function SimpleMDE(options) {
options.status = ['autosave', 'lines', 'words', 'cursor'];
}
// Add default preview rendering function
if(!options.previewRender) {
options.previewRender = function(plainText) {
@ -763,15 +796,19 @@ function SimpleMDE(options) {
}
}
// Set default options for parsing config
options.parsingConfig = options.parsingConfig || {};
// Update this options
this.options = options;
// Auto render
this.render();
// The codemirror component is only available after rendering
// so, the setter for the initialValue can only run after
// the element has been rendered
@ -790,13 +827,27 @@ SimpleMDE.toolbar = toolbar;
*/
SimpleMDE.prototype.markdown = function(text) {
if(window.marked) {
// Initialize
var markedOptions = {};
// Update options
if(this.options && this.options.singleLineBreaks !== false) {
marked.setOptions({
breaks: true
});
if(this.options && this.options.renderingConfig && this.options.renderingConfig.singleLineBreaks !== false) {
markedOptions.breaks = true;
}
if(this.options && this.options.renderingConfig && this.options.renderingConfig.codeSyntaxHighlighting === true && window.hljs) {
markedOptions.highlight = function(code) {
return hljs.highlightAuto(code).value;
}
}
// Set options
marked.setOptions(markedOptions);
// Return
return marked(text);
}
};
@ -863,7 +914,8 @@ SimpleMDE.prototype.render = function(el) {
lineNumbers: false,
autofocus: (options.autofocus === true) ? true : false,
extraKeys: keyMaps,
lineWrapping: (options.lineWrapping === false) ? false : true
lineWrapping: (options.lineWrapping === false) ? false : true,
allowDroppedFileTypes: ["text/plain"]
});
if(options.toolbar !== false) {
@ -998,6 +1050,9 @@ SimpleMDE.prototype.createToolbar = function(items) {
if(items[i].name == "guide" && self.options.toolbarGuideIcon === false)
continue;
if(self.options.hideIcons && self.options.hideIcons.indexOf(items[i].name) != -1)
continue;
(function(item) {
var el;
if(item === '|') {

Loading…
Cancel
Save