Merge pull request #107 from NextStepWebs/development
Custom preview rendering, Loads of bug fixespull/75/head 1.7.1
commit
57fcf521a0
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,61 +1,112 @@
|
||||
var gulp = require('gulp'),
|
||||
minifycss = require('gulp-minify-css'),
|
||||
uglify = require('gulp-uglify'),
|
||||
concat = require('gulp-concat'),
|
||||
header = require('gulp-header'),
|
||||
pkg = require('./package.json'),
|
||||
prettify = require('gulp-jsbeautifier');
|
||||
|
||||
var banner = ['/**',
|
||||
' * <%= pkg.name %> v<%= pkg.version %>',
|
||||
' * Copyright <%= pkg.company %>',
|
||||
' * @link <%= pkg.homepage %>',
|
||||
' * @license <%= pkg.license %>',
|
||||
' */',
|
||||
''].join('\n');
|
||||
|
||||
gulp.task('scripts', function() {
|
||||
var gulp = require("gulp"),
|
||||
minifycss = require("gulp-minify-css"),
|
||||
uglify = require("gulp-uglify"),
|
||||
concat = require("gulp-concat"),
|
||||
header = require("gulp-header"),
|
||||
pkg = require("./package.json"),
|
||||
prettify = require("gulp-jsbeautifier"),
|
||||
download = require("gulp-download");
|
||||
|
||||
var banner = ["/**",
|
||||
" * <%= pkg.name %> v<%= pkg.version %>",
|
||||
" * Copyright <%= pkg.company %>",
|
||||
" * @link <%= pkg.homepage %>",
|
||||
" * @license <%= pkg.license %>",
|
||||
" */",
|
||||
""].join("\n");
|
||||
|
||||
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/markdown/markdown.js",
|
||||
"https://raw.githubusercontent.com/codemirror/CodeMirror/master/mode/xml/xml.js"];
|
||||
|
||||
download(download_urls)
|
||||
.pipe(gulp.dest("src/js/codemirror/"));
|
||||
|
||||
// Wait to make sure they've been downloaded
|
||||
setTimeout(function() {
|
||||
callback();
|
||||
}, 5000);
|
||||
});
|
||||
|
||||
gulp.task("downloads-js", function(callback) {
|
||||
var download_urls = [
|
||||
"https://raw.githubusercontent.com/chjj/marked/master/lib/marked.js",
|
||||
"https://raw.githubusercontent.com/NextStepWebs/codemirror-spell-checker/master/src/js/spell-checker.js",
|
||||
"https://raw.githubusercontent.com/NextStepWebs/codemirror-spell-checker/master/src/js/typo.js"];
|
||||
|
||||
download(download_urls)
|
||||
.pipe(gulp.dest("src/js/"));
|
||||
|
||||
// Wait to make sure they've been downloaded
|
||||
setTimeout(function() {
|
||||
callback();
|
||||
}, 5000);
|
||||
});
|
||||
|
||||
gulp.task("downloads-css", function(callback) {
|
||||
var download_urls = [
|
||||
"https://raw.githubusercontent.com/codemirror/CodeMirror/master/lib/codemirror.css",
|
||||
"https://raw.githubusercontent.com/NextStepWebs/codemirror-spell-checker/master/src/css/spell-checker.css"];
|
||||
|
||||
download(download_urls)
|
||||
.pipe(gulp.dest("src/css/"));
|
||||
|
||||
// Wait to make sure they've been downloaded
|
||||
setTimeout(function() {
|
||||
callback();
|
||||
}, 5000);
|
||||
});
|
||||
|
||||
gulp.task("scripts", ["downloads-codemirror", "downloads-js", "downloads-css"], function() {
|
||||
var js_files = [
|
||||
'./src/js/codemirror/codemirror.js',
|
||||
'./src/js/codemirror/continuelist.js',
|
||||
'./src/js/codemirror/fullscreen.js',
|
||||
'./src/js/codemirror/markdown.js',
|
||||
'./src/js/codemirror/overlay.js',
|
||||
'./src/js/codemirror/gfm.js',
|
||||
'./src/js/codemirror/xml.js',
|
||||
'./src/js/typo.js',
|
||||
'./src/js/spell-checker.js',
|
||||
'./src/js/marked.js',
|
||||
'./src/js/simplemde.js'];
|
||||
"./src/js/codemirror/codemirror.js",
|
||||
"./src/js/codemirror/continuelist.js",
|
||||
"./src/js/codemirror/tablist.js",
|
||||
"./src/js/codemirror/fullscreen.js",
|
||||
"./src/js/codemirror/markdown.js",
|
||||
"./src/js/codemirror/overlay.js",
|
||||
"./src/js/codemirror/gfm.js",
|
||||
"./src/js/codemirror/xml.js",
|
||||
"./src/js/typo.js",
|
||||
"./src/js/spell-checker.js",
|
||||
"./src/js/marked.js",
|
||||
"./src/js/simplemde.js"];
|
||||
|
||||
return gulp.src(js_files)
|
||||
.pipe(header(banner, {pkg: pkg}))
|
||||
.pipe(concat('simplemde.min.js'))
|
||||
.pipe(gulp.dest('dist'))
|
||||
.pipe(concat("simplemde.min.js"))
|
||||
.pipe(gulp.dest("dist"))
|
||||
.pipe(uglify())
|
||||
.pipe(header(banner, {pkg: pkg}))
|
||||
.pipe(gulp.dest('dist'));
|
||||
.pipe(gulp.dest("dist"));
|
||||
});
|
||||
|
||||
gulp.task('styles', function() {
|
||||
return gulp.src('./src/css/*.css')
|
||||
.pipe(concat('simplemde.min.css'))
|
||||
.pipe(gulp.dest('dist'))
|
||||
gulp.task("styles", ["downloads-codemirror", "downloads-js", "downloads-css"], function() {
|
||||
return gulp.src("./src/css/*.css")
|
||||
.pipe(concat("simplemde.min.css"))
|
||||
.pipe(gulp.dest("dist"))
|
||||
.pipe(minifycss())
|
||||
.pipe(header(banner, {pkg: pkg}))
|
||||
.pipe(gulp.dest('dist'));
|
||||
.pipe(gulp.dest("dist"));
|
||||
});
|
||||
|
||||
gulp.task('prettify-js', function() {
|
||||
gulp.src('./src/js/simplemde.js')
|
||||
gulp.task("prettify-js", function() {
|
||||
gulp.src("./src/js/simplemde.js")
|
||||
.pipe(prettify({js: {braceStyle: "collapse", indentChar: "\t", indentSize: 1, maxPreserveNewlines: 3, spaceBeforeConditional: false}}))
|
||||
.pipe(gulp.dest('./src/js'));
|
||||
.pipe(gulp.dest("./src/js"));
|
||||
});
|
||||
|
||||
gulp.task('prettify-css', function() {
|
||||
gulp.src('./src/css/simplemde.css')
|
||||
gulp.task("prettify-css", function() {
|
||||
gulp.src("./src/css/simplemde.css")
|
||||
.pipe(prettify({css: {indentChar: "\t", indentSize: 1}}))
|
||||
.pipe(gulp.dest('./src/css'));
|
||||
.pipe(gulp.dest("./src/css"));
|
||||
});
|
||||
|
||||
gulp.task('default', ['scripts', 'styles', 'prettify-js', 'prettify-css']);
|
||||
gulp.task("default", ["downloads-codemirror", "downloads-js", "downloads-css", "scripts", "styles", "prettify-js", "prettify-css"]);
|
@ -1,29 +1,36 @@
|
||||
{
|
||||
"name": "simplemde",
|
||||
"version": "1.7.0",
|
||||
"description": "A simple, beautiful, and embeddable JavaScript markdown editor. Features autosaving and spell checking.",
|
||||
"keywords": ["embeddable", "markdown", "editor", "javascript", "wysiwyg"],
|
||||
"homepage": "https://github.com/NextStepWebs/simplemde-markdown-editor",
|
||||
"main": "gulpfile.js",
|
||||
"license": "MIT",
|
||||
"company": "Next Step Webs, Inc.",
|
||||
"author": {
|
||||
"name": "Wes Cossick",
|
||||
"url": "http://www.WesCossick.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/NextStepWebs/simplemde-markdown-editor/issues"
|
||||
},
|
||||
"devDependencies": {
|
||||
"gulp": "*",
|
||||
"gulp-minify-css": "*",
|
||||
"gulp-uglify": "*",
|
||||
"gulp-concat": "*",
|
||||
"gulp-header": "*",
|
||||
"gulp-jsbeautifier": "*"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/NextStepWebs/simplemde-markdown-editor"
|
||||
}
|
||||
"name": "simplemde",
|
||||
"version": "1.7.1",
|
||||
"description": "A simple, beautiful, and embeddable JavaScript markdown editor. Features autosaving and spell checking.",
|
||||
"keywords": [
|
||||
"embeddable",
|
||||
"markdown",
|
||||
"editor",
|
||||
"javascript",
|
||||
"wysiwyg"
|
||||
],
|
||||
"homepage": "https://github.com/NextStepWebs/simplemde-markdown-editor",
|
||||
"main": "gulpfile.js",
|
||||
"license": "MIT",
|
||||
"company": "Next Step Webs, Inc.",
|
||||
"author": {
|
||||
"name": "Wes Cossick",
|
||||
"url": "http://www.WesCossick.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/NextStepWebs/simplemde-markdown-editor/issues"
|
||||
},
|
||||
"devDependencies": {
|
||||
"gulp": "*",
|
||||
"gulp-minify-css": "*",
|
||||
"gulp-uglify": "*",
|
||||
"gulp-concat": "*",
|
||||
"gulp-header": "*",
|
||||
"gulp-jsbeautifier": "*",
|
||||
"gulp-download": "*"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/NextStepWebs/simplemde-markdown-editor"
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,3 @@
|
||||
.CodeMirror .cm-spell-error:not(.cm-url):not(.cm-comment) {
|
||||
background: rgba(255, 0, 0, .15);
|
||||
}
|
||||
background: rgba(255, 0, 0, .15);
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,94 +1,51 @@
|
||||
// NOTE: This has been modified from the original version to add additional commands
|
||||
|
||||
// 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);
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
};
|
||||
});
|
||||
"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);
|
||||
};
|
||||
});
|
||||
|
@ -1,113 +1,133 @@
|
||||
// NOTE: This has been modified from the original version to remove linking GitHub-only references, like references to issues using #X.
|
||||
|
||||
|
||||
// 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"), require("../markdown/markdown"), require("../../addon/mode/overlay"));
|
||||
else if (typeof define == "function" && define.amd) // AMD
|
||||
define(["../../lib/codemirror", "../markdown/markdown", "../../addon/mode/overlay"], mod);
|
||||
else // Plain browser env
|
||||
mod(CodeMirror);
|
||||
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
||||
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);
|
||||
else // Plain browser env
|
||||
mod(CodeMirror);
|
||||
})(function(CodeMirror) {
|
||||
"use strict";
|
||||
"use strict";
|
||||
|
||||
CodeMirror.defineMode("gfm", function(config, modeConfig) {
|
||||
var codeDepth = 0;
|
||||
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
|
||||
|
||||
function blankLine(state) {
|
||||
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;
|
||||
CodeMirror.defineMode("gfm", function(config, modeConfig) {
|
||||
// Should GitHub spice be added (like linking #Num, SHA, etc.)
|
||||
if (modeConfig.gitHubSpice === undefined)
|
||||
modeConfig.gitHubSpice = true;
|
||||
|
||||
// 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 (stream.match(/^((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]|\([^\s()<>]*\))+(?:\([^\s()<>]*\)|[^\s`*!()\[\]{};:'".,<>?«»“”‘’]))/i) &&
|
||||
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
|
||||
state.combineTokens = true;
|
||||
return "link";
|
||||
}
|
||||
stream.next();
|
||||
return null;
|
||||
},
|
||||
blankLine: blankLine
|
||||
};
|
||||
var codeDepth = 0;
|
||||
function blankLine(state) {
|
||||
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;
|
||||
|
||||
var markdownConfig = {
|
||||
underscoresBreakWords: false,
|
||||
taskLists: true,
|
||||
fencedCodeBlocks: true,
|
||||
strikethrough: true
|
||||
};
|
||||
for (var attr in modeConfig) {
|
||||
markdownConfig[attr] = modeConfig[attr];
|
||||
// Hack to prevent formatting override inside code blocks (block and inline)
|
||||
if (state.codeBlock) {
|
||||
if (stream.match(/^```/)) {
|
||||
state.codeBlock = false;
|
||||
return null;
|
||||
}
|
||||
markdownConfig.name = "markdown";
|
||||
return CodeMirror.overlayMode(CodeMirror.getMode(config, markdownConfig), gfmOverlay);
|
||||
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
|
||||
};
|
||||
|
||||
var markdownConfig = {
|
||||
underscoresBreakWords: false,
|
||||
taskLists: true,
|
||||
fencedCodeBlocks: true,
|
||||
strikethrough: true
|
||||
};
|
||||
for (var attr in modeConfig) {
|
||||
markdownConfig[attr] = modeConfig[attr];
|
||||
}
|
||||
markdownConfig.name = "markdown";
|
||||
return CodeMirror.overlayMode(CodeMirror.getMode(config, markdownConfig), gfmOverlay);
|
||||
|
||||
}, "markdown");
|
||||
}, "markdown");
|
||||
|
||||
CodeMirror.defineMIME("text/x-gfm", "gfm");
|
||||
CodeMirror.defineMIME("text/x-gfm", "gfm");
|
||||
});
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,53 @@
|
||||
// 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);
|
||||
})(function(CodeMirror) {
|
||||
"use strict";
|
||||
|
||||
CodeMirror.commands.tabAndIndentMarkdownList = 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);
|
||||
}
|
||||
};
|
||||
|
||||
CodeMirror.commands.shiftTabAndUnindentMarkdownList = 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);
|
||||
}
|
||||
};
|
||||
});
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue