Merge pull request #107 from NextStepWebs/development

Custom preview rendering, Loads of bug fixes
pull/124/head 1.7.1
Wes Cossick 9 years ago
commit 57fcf521a0

@ -9,7 +9,7 @@ A drop-in JavaScript textarea replacement for writing beautiful and understandab
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. 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.
## Quick start ## Quick start
SimpleMDE is available on npm. SimpleMDE is available on [npm](https://www.npmjs.com/package/simplemde).
``` ```
npm install simplemde --save npm install simplemde --save
``` ```
@ -32,7 +32,6 @@ And then load SimpleMDE on the first textarea on a page
```HTML ```HTML
<script> <script>
var simplemde = new SimpleMDE(); var simplemde = new SimpleMDE();
simplemde.render();
</script> </script>
``` ```
@ -43,7 +42,6 @@ Pure JavaScript method
```HTML ```HTML
<script> <script>
var simplemde = new SimpleMDE({ element: document.getElementById("MyID") }); var simplemde = new SimpleMDE({ element: document.getElementById("MyID") });
simplemde.render();
</script> </script>
``` ```
@ -52,56 +50,81 @@ jQuery method
```HTML ```HTML
<script> <script>
var simplemde = new SimpleMDE({ element: $("#MyID")[0] }); var simplemde = new SimpleMDE({ element: $("#MyID")[0] });
simplemde.render();
</script> </script>
``` ```
## Get the content ## Get/set the content
```JavaScript ```JavaScript
simplemde.value(); simplemde.value();
``` ```
```JavaScript
simplemde.value("This text will appear in the editor");
```
## Configuration ## Configuration
- **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. - **element**: The DOM element for the textarea to use. Defaults to the first textarea on the page.
- **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`.
- **spellChecker**: If set to `false`, disable the spell checker. Defaults to `true`.
- **status**: If set to `false`, hide the status bar. 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. - 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). - **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`.
- **toolbarGuideIcon**: If set to `false`, disable guide icon in the toolbar. Defaults to `true`. - **toolbarGuideIcon**: If set to `false`, disable guide icon in the toolbar. Defaults to `true`.
- **autofocus**: If set to `true`, autofocuses the editor. Defaults to `false`. - **toolbarTips**: If set to `false`, disable toolbar button tips. Defaults to `true`.
- **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`.
- **initialValue**: If set, will customize the initial value of the editor.
- **spellChecker**: If set to `false`, disable the spell checker. Defaults to `true`.
- **singleLineBreaks**: If set to `false`, disable parsing GFM single line breaks. Defaults to `true`.
- **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 ```JavaScript
var simplemde = new SimpleMDE({ var simplemde = new SimpleMDE({
element: document.getElementById("MyID"),
status: false,
status: ['autosave', 'lines', 'words', 'cursor'], // Optional usage
toolbar: false,
toolbarTips: false,
toolbarGuideIcon: false,
autofocus: true, autofocus: true,
lineWrapping: false,
indentWithTabs: false,
tabSize: 4,
initialValue: "Hello world!",
spellChecker: false,
singleLineBreaks: false,
autosave: { autosave: {
enabled: true, enabled: true,
unique_id: "MyUniqueID", unique_id: "MyUniqueID",
delay: 1000, delay: 1000,
}, },
element: document.getElementById("MyID"),
indentWithTabs: false,
initialValue: "Hello world!",
lineWrapping: false,
parsingConfig: {
allowAtxHeaderWithoutSpace: true,
fencedCodeBlocks: false,
strikethrough: false,
underscoresBreakWords: true,
},
previewRender: function(plainText) {
return customMarkdownParser(plainText); // Returns HTML from a custom parser
},
previewRender: function(plainText, preview) { // Async method
setTimeout(function(){
preview.innerHTML = customMarkdownParser(plainText);
}, 250);
return "Loading...";
}
singleLineBreaks: false,
spellChecker: false,
status: false,
status: ['autosave', 'lines', 'words', 'cursor'], // Optional usage
tabSize: 4,
toolbar: false,
toolbarGuideIcon: false,
toolbarTips: false,
}); });
``` ```
@ -109,28 +132,28 @@ var simplemde = new SimpleMDE({
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. 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.
Name | Action | Class | Tooltip Name | Action | Tooltip<br>Class
:--- | :----- | :---- | :------ :--- | :----- | :--------------
bold | toggleBold | fa fa-bold | Bold (Ctrl+B) bold | toggleBold | Bold (Ctrl+B)<br>fa fa-bold
italic | toggleItalic | fa fa-italic | Italic (Ctrl+I) italic | toggleItalic | Italic (Ctrl+I)<br>fa fa-italic
strikethrough | toggleStrikethrough | fa fa-strikethrough | Strikethrough strikethrough | toggleStrikethrough | Strikethrough<br>fa fa-strikethrough
heading | toggleHeadingSmaller | fa fa-header | Heading (Ctrl+H) heading | toggleHeadingSmaller | Heading (Ctrl+H)<br>fa fa-header
heading-smaller | toggleHeadingSmaller | fa fa-header | Smaller Heading (Ctrl+H) heading-smaller | toggleHeadingSmaller | Smaller Heading (Ctrl+H)<br>fa fa-header
heading-bigger | toggleHeadingBigger | fa fa-lg fa-header | Bigger Heading (Shift+Ctrl+H) heading-bigger | toggleHeadingBigger | Bigger Heading (Shift+Ctrl+H)<br>fa fa-lg fa-header
heading-1 | toggleHeading1 | fa fa-header fa-header-x fa-header-1 | Big Heading heading-1 | toggleHeading1 | Big Heading<br>fa fa-header fa-header-x fa-header-1
heading-2 | toggleHeading2 | fa fa-header fa-header-x fa-header-2 | Medium Heading heading-2 | toggleHeading2 | Medium Heading<br>fa fa-header fa-header-x fa-header-2
heading-3 | toggleHeading3 | fa fa-header fa-header-x fa-header-3 | Small Heading heading-3 | toggleHeading3 | Small Heading<br>fa fa-header fa-header-x fa-header-3
code | toggleCodeBlock | fa fa-code | Code (Ctrl+Alt+C) code | toggleCodeBlock | Code (Ctrl+Alt+C)<br>fa fa-code
quote | toggleBlockquote | fa fa-quote-left | Quote (Ctrl+') quote | toggleBlockquote | Quote (Ctrl+')<br>fa fa-quote-left
unordered-list | toggleUnorderedList | fa fa-list-ul | Generic List (Ctrl+L) unordered-list | toggleUnorderedList | Generic List (Ctrl+L)<br>fa fa-list-ul
numbered-list | toggleOrderedList | fa fa-list-ol | Numbered List (Ctrl+Alt+L) ordered-list | toggleOrderedList | Numbered List (Ctrl+Alt+L)<br>fa fa-list-ol
link | drawLink | fa fa-link | Create Link (Ctrl+K) link | drawLink | Create Link (Ctrl+K)<br>fa fa-link
image | drawImage | fa fa-picture-o | Insert Image (Ctrl+Alt+I) image | drawImage | Insert Image (Ctrl+Alt+I)<br>fa fa-picture-o
horizontal-rule | drawHorizontalRule | fa fa-minus | Insert Horizontal Line horizontal-rule | drawHorizontalRule | Insert Horizontal Line<br>fa fa-minus
preview | togglePreview | fa fa-eye | Toggle Preview (Ctrl+P) preview | togglePreview | Toggle Preview (Ctrl+P)<br>fa fa-eye
side-by-side | toggleSideBySide | fa fa-columns | Toggle Side by Side (F9) side-by-side | toggleSideBySide | Toggle Side by Side (F9)<br>fa fa-columns
fullscreen | toggleFullScreen | fa fa-arrows-alt | Toggle Fullscreen (F11) fullscreen | toggleFullScreen | Toggle Fullscreen (F11)<br>fa fa-arrows-alt
guide | [This link](http://nextstepwebs.github.io/simplemde-markdown-editor/markdown-guide) | fa fa-question-circle | Markdown Guide 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: 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

@ -1,61 +1,112 @@
var gulp = require('gulp'), var gulp = require("gulp"),
minifycss = require('gulp-minify-css'), minifycss = require("gulp-minify-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"),
pkg = require('./package.json'), pkg = require("./package.json"),
prettify = require('gulp-jsbeautifier'); prettify = require("gulp-jsbeautifier"),
download = require("gulp-download");
var banner = ['/**',
' * <%= pkg.name %> v<%= pkg.version %>', var banner = ["/**",
' * Copyright <%= pkg.company %>', " * <%= pkg.name %> v<%= pkg.version %>",
' * @link <%= pkg.homepage %>', " * Copyright <%= pkg.company %>",
' * @license <%= pkg.license %>', " * @link <%= pkg.homepage %>",
' */', " * @license <%= pkg.license %>",
''].join('\n'); " */",
""].join("\n");
gulp.task('scripts', function() {
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 = [ var js_files = [
'./src/js/codemirror/codemirror.js', "./src/js/codemirror/codemirror.js",
'./src/js/codemirror/continuelist.js', "./src/js/codemirror/continuelist.js",
'./src/js/codemirror/fullscreen.js', "./src/js/codemirror/tablist.js",
'./src/js/codemirror/markdown.js', "./src/js/codemirror/fullscreen.js",
'./src/js/codemirror/overlay.js', "./src/js/codemirror/markdown.js",
'./src/js/codemirror/gfm.js', "./src/js/codemirror/overlay.js",
'./src/js/codemirror/xml.js', "./src/js/codemirror/gfm.js",
'./src/js/typo.js', "./src/js/codemirror/xml.js",
'./src/js/spell-checker.js', "./src/js/typo.js",
'./src/js/marked.js', "./src/js/spell-checker.js",
'./src/js/simplemde.js']; "./src/js/marked.js",
"./src/js/simplemde.js"];
return gulp.src(js_files) return gulp.src(js_files)
.pipe(header(banner, {pkg: pkg})) .pipe(header(banner, {pkg: pkg}))
.pipe(concat('simplemde.min.js')) .pipe(concat("simplemde.min.js"))
.pipe(gulp.dest('dist')) .pipe(gulp.dest("dist"))
.pipe(uglify()) .pipe(uglify())
.pipe(header(banner, {pkg: pkg})) .pipe(header(banner, {pkg: pkg}))
.pipe(gulp.dest('dist')); .pipe(gulp.dest("dist"));
}); });
gulp.task('styles', function() { gulp.task("styles", ["downloads-codemirror", "downloads-js", "downloads-css"], function() {
return gulp.src('./src/css/*.css') return gulp.src("./src/css/*.css")
.pipe(concat('simplemde.min.css')) .pipe(concat("simplemde.min.css"))
.pipe(gulp.dest('dist')) .pipe(gulp.dest("dist"))
.pipe(minifycss()) .pipe(minifycss())
.pipe(header(banner, {pkg: pkg})) .pipe(header(banner, {pkg: pkg}))
.pipe(gulp.dest('dist')); .pipe(gulp.dest("dist"));
}); });
gulp.task('prettify-js', function() { gulp.task("prettify-js", function() {
gulp.src('./src/js/simplemde.js') gulp.src("./src/js/simplemde.js")
.pipe(prettify({js: {braceStyle: "collapse", indentChar: "\t", indentSize: 1, maxPreserveNewlines: 3, spaceBeforeConditional: false}})) .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.task("prettify-css", function() {
gulp.src('./src/css/simplemde.css') gulp.src("./src/css/simplemde.css")
.pipe(prettify({css: {indentChar: "\t", indentSize: 1}})) .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", "name": "simplemde",
"version": "1.7.0", "version": "1.7.1",
"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": ["embeddable", "markdown", "editor", "javascript", "wysiwyg"], "keywords": [
"homepage": "https://github.com/NextStepWebs/simplemde-markdown-editor", "embeddable",
"main": "gulpfile.js", "markdown",
"license": "MIT", "editor",
"company": "Next Step Webs, Inc.", "javascript",
"author": { "wysiwyg"
"name": "Wes Cossick", ],
"url": "http://www.WesCossick.com" "homepage": "https://github.com/NextStepWebs/simplemde-markdown-editor",
}, "main": "gulpfile.js",
"bugs": { "license": "MIT",
"url": "https://github.com/NextStepWebs/simplemde-markdown-editor/issues" "company": "Next Step Webs, Inc.",
}, "author": {
"devDependencies": { "name": "Wes Cossick",
"gulp": "*", "url": "http://www.WesCossick.com"
"gulp-minify-css": "*", },
"gulp-uglify": "*", "bugs": {
"gulp-concat": "*", "url": "https://github.com/NextStepWebs/simplemde-markdown-editor/issues"
"gulp-header": "*", },
"gulp-jsbeautifier": "*" "devDependencies": {
}, "gulp": "*",
"repository": { "gulp-minify-css": "*",
"type": "git", "gulp-uglify": "*",
"url": "https://github.com/NextStepWebs/simplemde-markdown-editor" "gulp-concat": "*",
} "gulp-header": "*",
"gulp-jsbeautifier": "*",
"gulp-download": "*"
},
"repository": {
"type": "git",
"url": "https://github.com/NextStepWebs/simplemde-markdown-editor"
}
} }

@ -323,7 +323,7 @@ div.CodeMirror-dragcursors {
@media print { @media print {
/* Hide the cursor when printing */ /* Hide the cursor when printing */
.CodeMirror div.CodeMirror-cursors { .CodeMirror div.CodeMirror-cursors {
visibility: hidden; visibility: hidden;
} }
} }
@ -331,4 +331,4 @@ div.CodeMirror-dragcursors {
.cm-tab-wrap-hack:after { content: ''; } .cm-tab-wrap-hack:after { content: ''; }
/* Help users use markselection to safely style text background */ /* Help users use markselection to safely style text background */
span.CodeMirror-selectedtext { background: none; } span.CodeMirror-selectedtext { background: none; }

@ -66,11 +66,13 @@
.editor-toolbar.fullscreen { .editor-toolbar.fullscreen {
width: 100%; width: 100%;
height: 40px; height: 50px;
overflow-x: auto; overflow-x: auto;
overflow-y: hidden; overflow-y: hidden;
white-space: nowrap; white-space: nowrap;
padding-top: 10px; padding-top: 10px;
padding-bottom: 10px;
box-sizing: border-box;
background: #fff; background: #fff;
border: 0; border: 0;
position: fixed; position: fixed;
@ -178,6 +180,8 @@
.editor-toolbar.disabled-for-preview a:not(.fa-eye):not(.fa-arrows-alt):not(.fa-columns) { .editor-toolbar.disabled-for-preview a:not(.fa-eye):not(.fa-arrows-alt):not(.fa-columns) {
pointer-events: none; pointer-events: none;
background: #fff; background: #fff;
border-color: transparent;
text-shadow: inherit;
} }
@media only screen and (max-width: 700px) { @media only screen and (max-width: 700px) {

@ -1,3 +1,3 @@
.CodeMirror .cm-spell-error:not(.cm-url):not(.cm-comment) { .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) { (function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror")); mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod); define(["../../lib/codemirror"], mod);
else // Plain browser env else // Plain browser env
mod(CodeMirror); mod(CodeMirror);
})(function(CodeMirror) { })(function(CodeMirror) {
"use strict"; "use strict";
var listRE = /^(\s*)(>[> ]*|[*+-]\s|(\d+)([.)]))(\s*)/, var listRE = /^(\s*)(>[> ]*|[*+-]\s|(\d+)([.)]))(\s*)/,
emptyListRE = /^(\s*)(>[> ]*|[*+-]|(\d+)[.)])(\s*)$/, emptyListRE = /^(\s*)(>[> ]*|[*+-]|(\d+)[.)])(\s*)$/,
unorderedListRE = /[*+-]\s/; unorderedListRE = /[*+-]\s/;
CodeMirror.commands.newlineAndIndentContinueMarkdownList = function(cm) { CodeMirror.commands.newlineAndIndentContinueMarkdownList = function(cm) {
if (cm.getOption("disableInput")) return CodeMirror.Pass; if (cm.getOption("disableInput")) return CodeMirror.Pass;
var ranges = cm.listSelections(), var ranges = cm.listSelections(), replacements = [];
replacements = []; for (var i = 0; i < ranges.length; i++) {
for (var i = 0; i < ranges.length; i++) { var pos = ranges[i].head;
var pos = ranges[i].head; var eolState = cm.getStateAfter(pos.line);
var eolState = cm.getStateAfter(pos.line); var inList = eolState.list !== false;
var inList = eolState.list !== false; var inQuote = eolState.quote !== 0;
var inQuote = eolState.quote !== 0;
var line = cm.getLine(pos.line), match = listRE.exec(line);
var line = cm.getLine(pos.line), if (!ranges[i].empty() || (!inList && !inQuote) || !match) {
match = listRE.exec(line); cm.execCommand("newlineAndIndent");
if (!ranges[i].empty() || (!inList && !inQuote) || !match) { return;
cm.execCommand("newlineAndIndent"); }
return; if (emptyListRE.test(line)) {
} cm.replaceRange("", {
if (emptyListRE.test(line)) { line: pos.line, ch: 0
cm.replaceRange("", { }, {
line: pos.line, line: pos.line, ch: pos.ch + 1
ch: 0 });
}, { replacements[i] = "\n";
line: pos.line, } else {
ch: pos.ch + 1 var indent = match[1], after = match[5];
}); var bullet = unorderedListRE.test(match[2]) || match[2].indexOf(">") >= 0
replacements[i] = "\n"; ? match[2]
} else { : (parseInt(match[3], 10) + 1) + match[4];
var indent = match[1],
after = match[5]; replacements[i] = "\n" + indent + bullet + after;
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);
} };
});
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);
}
};
});

@ -3,39 +3,39 @@
(function(mod) { (function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror")); mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod); define(["../../lib/codemirror"], mod);
else // Plain browser env else // Plain browser env
mod(CodeMirror); mod(CodeMirror);
})(function(CodeMirror) { })(function(CodeMirror) {
"use strict"; "use strict";
CodeMirror.defineOption("fullScreen", false, function(cm, val, old) { CodeMirror.defineOption("fullScreen", false, function(cm, val, old) {
if (old == CodeMirror.Init) old = false; if (old == CodeMirror.Init) old = false;
if (!old == !val) return; if (!old == !val) return;
if (val) setFullscreen(cm); if (val) setFullscreen(cm);
else setNormal(cm); else setNormal(cm);
}); });
function setFullscreen(cm) { function setFullscreen(cm) {
var wrap = cm.getWrapperElement(); var wrap = cm.getWrapperElement();
cm.state.fullScreenRestore = {scrollTop: window.pageYOffset, scrollLeft: window.pageXOffset, cm.state.fullScreenRestore = {scrollTop: window.pageYOffset, scrollLeft: window.pageXOffset,
width: wrap.style.width, height: wrap.style.height}; width: wrap.style.width, height: wrap.style.height};
wrap.style.width = ""; wrap.style.width = "";
wrap.style.height = "auto"; wrap.style.height = "auto";
wrap.className += " CodeMirror-fullscreen"; wrap.className += " CodeMirror-fullscreen";
document.documentElement.style.overflow = "hidden"; document.documentElement.style.overflow = "hidden";
cm.refresh(); cm.refresh();
} }
function setNormal(cm) { function setNormal(cm) {
var wrap = cm.getWrapperElement(); var wrap = cm.getWrapperElement();
wrap.className = wrap.className.replace(/\s*CodeMirror-fullscreen\b/, ""); wrap.className = wrap.className.replace(/\s*CodeMirror-fullscreen\b/, "");
document.documentElement.style.overflow = ""; document.documentElement.style.overflow = "";
var info = cm.state.fullScreenRestore; var info = cm.state.fullScreenRestore;
wrap.style.width = info.width; wrap.style.height = info.height; wrap.style.width = info.width; wrap.style.height = info.height;
window.scrollTo(info.scrollLeft, info.scrollTop); window.scrollTo(info.scrollLeft, info.scrollTop);
cm.refresh(); cm.refresh();
} }
}); });

@ -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) { (function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS 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 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 else // Plain browser env
mod(CodeMirror); mod(CodeMirror);
})(function(CodeMirror) { })(function(CodeMirror) {
"use strict"; "use strict";
CodeMirror.defineMode("gfm", function(config, modeConfig) { 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 codeDepth = 0;
function blankLine(state) { CodeMirror.defineMode("gfm", function(config, modeConfig) {
state.code = false; // Should GitHub spice be added (like linking #Num, SHA, etc.)
return null; if (modeConfig.gitHubSpice === undefined)
} modeConfig.gitHubSpice = true;
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;
// Hack to prevent formatting override inside code blocks (block and inline) var codeDepth = 0;
if (state.codeBlock) { function blankLine(state) {
if (stream.match(/^```/)) { state.code = false;
state.codeBlock = false; return null;
return null; }
} var gfmOverlay = {
stream.skipToEnd(); startState: function() {
return null; return {
} code: false,
if (stream.sol()) { codeBlock: false,
state.code = false; ateSpace: false
} };
if (stream.sol() && stream.match(/^```/)) { },
stream.skipToEnd(); copyState: function(s) {
state.codeBlock = true; return {
return null; code: s.code,
} codeBlock: s.codeBlock,
// If this block is changed, it may need to be updated in Markdown mode ateSpace: s.ateSpace
if (stream.peek() === '`') { };
stream.next(); },
var before = stream.pos; token: function(stream, state) {
stream.eatWhile('`'); state.combineTokens = null;
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 markdownConfig = { // Hack to prevent formatting override inside code blocks (block and inline)
underscoresBreakWords: false, if (state.codeBlock) {
taskLists: true, if (stream.match(/^```/)) {
fencedCodeBlocks: true, state.codeBlock = false;
strikethrough: true return null;
};
for (var attr in modeConfig) {
markdownConfig[attr] = modeConfig[attr];
} }
markdownConfig.name = "markdown"; stream.skipToEnd();
return CodeMirror.overlayMode(CodeMirror.getMode(config, markdownConfig), gfmOverlay); 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

@ -12,74 +12,74 @@
(function(mod) { (function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror")); mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod); define(["../../lib/codemirror"], mod);
else // Plain browser env else // Plain browser env
mod(CodeMirror); mod(CodeMirror);
})(function(CodeMirror) { })(function(CodeMirror) {
"use strict"; "use strict";
CodeMirror.overlayMode = function(base, overlay, combine) { CodeMirror.overlayMode = function(base, overlay, combine) {
return { return {
startState: function() { startState: function() {
return { return {
base: CodeMirror.startState(base), base: CodeMirror.startState(base),
overlay: CodeMirror.startState(overlay), overlay: CodeMirror.startState(overlay),
basePos: 0, baseCur: null, basePos: 0, baseCur: null,
overlayPos: 0, overlayCur: null, overlayPos: 0, overlayCur: null,
streamSeen: null streamSeen: null
}; };
}, },
copyState: function(state) { copyState: function(state) {
return { return {
base: CodeMirror.copyState(base, state.base), base: CodeMirror.copyState(base, state.base),
overlay: CodeMirror.copyState(overlay, state.overlay), overlay: CodeMirror.copyState(overlay, state.overlay),
basePos: state.basePos, baseCur: null, basePos: state.basePos, baseCur: null,
overlayPos: state.overlayPos, overlayCur: null overlayPos: state.overlayPos, overlayCur: null
}; };
}, },
token: function(stream, state) { token: function(stream, state) {
if (stream != state.streamSeen || if (stream != state.streamSeen ||
Math.min(state.basePos, state.overlayPos) < stream.start) { Math.min(state.basePos, state.overlayPos) < stream.start) {
state.streamSeen = stream; state.streamSeen = stream;
state.basePos = state.overlayPos = stream.start; state.basePos = state.overlayPos = stream.start;
} }
if (stream.start == state.basePos) { if (stream.start == state.basePos) {
state.baseCur = base.token(stream, state.base); state.baseCur = base.token(stream, state.base);
state.basePos = stream.pos; state.basePos = stream.pos;
} }
if (stream.start == state.overlayPos) { if (stream.start == state.overlayPos) {
stream.pos = stream.start; stream.pos = stream.start;
state.overlayCur = overlay.token(stream, state.overlay); state.overlayCur = overlay.token(stream, state.overlay);
state.overlayPos = stream.pos; state.overlayPos = stream.pos;
} }
stream.pos = Math.min(state.basePos, state.overlayPos); stream.pos = Math.min(state.basePos, state.overlayPos);
// state.overlay.combineTokens always takes precedence over combine, // state.overlay.combineTokens always takes precedence over combine,
// unless set to null // unless set to null
if (state.overlayCur == null) return state.baseCur; if (state.overlayCur == null) return state.baseCur;
else if (state.baseCur != null && else if (state.baseCur != null &&
state.overlay.combineTokens || state.overlay.combineTokens ||
combine && state.overlay.combineTokens == null) combine && state.overlay.combineTokens == null)
return state.baseCur + " " + state.overlayCur; return state.baseCur + " " + state.overlayCur;
else return state.overlayCur; else return state.overlayCur;
}, },
indent: base.indent && function(state, textAfter) { indent: base.indent && function(state, textAfter) {
return base.indent(state.base, textAfter); return base.indent(state.base, textAfter);
}, },
electricChars: base.electricChars, electricChars: base.electricChars,
innerMode: function(state) { return {state: state.base, mode: base}; }, innerMode: function(state) { return {state: state.base, mode: base}; },
blankLine: function(state) { blankLine: function(state) {
if (base.blankLine) base.blankLine(state.base); if (base.blankLine) base.blankLine(state.base);
if (overlay.blankLine) overlay.blankLine(state.overlay); if (overlay.blankLine) overlay.blankLine(state.overlay);
} }
}; };
}; };
}); });

@ -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);
}
};
});

@ -3,11 +3,11 @@
(function(mod) { (function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror")); mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod); define(["../../lib/codemirror"], mod);
else // Plain browser env else // Plain browser env
mod(CodeMirror); mod(CodeMirror);
})(function(CodeMirror) { })(function(CodeMirror) {
"use strict"; "use strict";
@ -18,45 +18,45 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
if (multilineTagIndentPastTag == null) multilineTagIndentPastTag = true; if (multilineTagIndentPastTag == null) multilineTagIndentPastTag = true;
var Kludges = parserConfig.htmlMode ? { var Kludges = parserConfig.htmlMode ? {
autoSelfClosers: {'area': true, 'base': true, 'br': true, 'col': true, 'command': true, autoSelfClosers: {'area': true, 'base': true, 'br': true, 'col': true, 'command': true,
'embed': true, 'frame': true, 'hr': true, 'img': true, 'input': true, 'embed': true, 'frame': true, 'hr': true, 'img': true, 'input': true,
'keygen': true, 'link': true, 'meta': true, 'param': true, 'source': true, 'keygen': true, 'link': true, 'meta': true, 'param': true, 'source': true,
'track': true, 'wbr': true, 'menuitem': true}, 'track': true, 'wbr': true, 'menuitem': true},
implicitlyClosed: {'dd': true, 'li': true, 'optgroup': true, 'option': true, 'p': true, implicitlyClosed: {'dd': true, 'li': true, 'optgroup': true, 'option': true, 'p': true,
'rp': true, 'rt': true, 'tbody': true, 'td': true, 'tfoot': true, 'rp': true, 'rt': true, 'tbody': true, 'td': true, 'tfoot': true,
'th': true, 'tr': true}, 'th': true, 'tr': true},
contextGrabbers: { contextGrabbers: {
'dd': {'dd': true, 'dt': true}, 'dd': {'dd': true, 'dt': true},
'dt': {'dd': true, 'dt': true}, 'dt': {'dd': true, 'dt': true},
'li': {'li': true}, 'li': {'li': true},
'option': {'option': true, 'optgroup': true}, 'option': {'option': true, 'optgroup': true},
'optgroup': {'optgroup': true}, 'optgroup': {'optgroup': true},
'p': {'address': true, 'article': true, 'aside': true, 'blockquote': true, 'dir': true, 'p': {'address': true, 'article': true, 'aside': true, 'blockquote': true, 'dir': true,
'div': true, 'dl': true, 'fieldset': true, 'footer': true, 'form': true, 'div': true, 'dl': true, 'fieldset': true, 'footer': true, 'form': true,
'h1': true, 'h2': true, 'h3': true, 'h4': true, 'h5': true, 'h6': true, 'h1': true, 'h2': true, 'h3': true, 'h4': true, 'h5': true, 'h6': true,
'header': true, 'hgroup': true, 'hr': true, 'menu': true, 'nav': true, 'ol': true, 'header': true, 'hgroup': true, 'hr': true, 'menu': true, 'nav': true, 'ol': true,
'p': true, 'pre': true, 'section': true, 'table': true, 'ul': true}, 'p': true, 'pre': true, 'section': true, 'table': true, 'ul': true},
'rp': {'rp': true, 'rt': true}, 'rp': {'rp': true, 'rt': true},
'rt': {'rp': true, 'rt': true}, 'rt': {'rp': true, 'rt': true},
'tbody': {'tbody': true, 'tfoot': true}, 'tbody': {'tbody': true, 'tfoot': true},
'td': {'td': true, 'th': true}, 'td': {'td': true, 'th': true},
'tfoot': {'tbody': true}, 'tfoot': {'tbody': true},
'th': {'td': true, 'th': true}, 'th': {'td': true, 'th': true},
'thead': {'tbody': true, 'tfoot': true}, 'thead': {'tbody': true, 'tfoot': true},
'tr': {'tr': true} 'tr': {'tr': true}
}, },
doNotIndent: {"pre": true}, doNotIndent: {"pre": true},
allowUnquoted: true, allowUnquoted: true,
allowMissing: true, allowMissing: true,
caseFold: true caseFold: true
} : { } : {
autoSelfClosers: {}, autoSelfClosers: {},
implicitlyClosed: {}, implicitlyClosed: {},
contextGrabbers: {}, contextGrabbers: {},
doNotIndent: {}, doNotIndent: {},
allowUnquoted: false, allowUnquoted: false,
allowMissing: false, allowMissing: false,
caseFold: false caseFold: false
}; };
var alignCDATA = parserConfig.alignCDATA; var alignCDATA = parserConfig.alignCDATA;
@ -64,316 +64,316 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
var type, setStyle; var type, setStyle;
function inText(stream, state) { function inText(stream, state) {
function chain(parser) { function chain(parser) {
state.tokenize = parser; state.tokenize = parser;
return parser(stream, state); return parser(stream, state);
} }
var ch = stream.next(); var ch = stream.next();
if (ch == "<") { if (ch == "<") {
if (stream.eat("!")) { if (stream.eat("!")) {
if (stream.eat("[")) { if (stream.eat("[")) {
if (stream.match("CDATA[")) return chain(inBlock("atom", "]]>")); if (stream.match("CDATA[")) return chain(inBlock("atom", "]]>"));
else return null; else return null;
} else if (stream.match("--")) { } else if (stream.match("--")) {
return chain(inBlock("comment", "-->")); return chain(inBlock("comment", "-->"));
} else if (stream.match("DOCTYPE", true, true)) { } else if (stream.match("DOCTYPE", true, true)) {
stream.eatWhile(/[\w\._\-]/); stream.eatWhile(/[\w\._\-]/);
return chain(doctype(1)); return chain(doctype(1));
} else { } else {
return null; return null;
} }
} else if (stream.eat("?")) { } else if (stream.eat("?")) {
stream.eatWhile(/[\w\._\-]/); stream.eatWhile(/[\w\._\-]/);
state.tokenize = inBlock("meta", "?>"); state.tokenize = inBlock("meta", "?>");
return "meta"; return "meta";
} else { } else {
type = stream.eat("/") ? "closeTag" : "openTag"; type = stream.eat("/") ? "closeTag" : "openTag";
state.tokenize = inTag; state.tokenize = inTag;
return "tag bracket"; return "tag bracket";
} }
} else if (ch == "&") { } else if (ch == "&") {
var ok; var ok;
if (stream.eat("#")) { if (stream.eat("#")) {
if (stream.eat("x")) { if (stream.eat("x")) {
ok = stream.eatWhile(/[a-fA-F\d]/) && stream.eat(";"); ok = stream.eatWhile(/[a-fA-F\d]/) && stream.eat(";");
} else { } else {
ok = stream.eatWhile(/[\d]/) && stream.eat(";"); ok = stream.eatWhile(/[\d]/) && stream.eat(";");
} }
} else { } else {
ok = stream.eatWhile(/[\w\.\-:]/) && stream.eat(";"); ok = stream.eatWhile(/[\w\.\-:]/) && stream.eat(";");
} }
return ok ? "atom" : "error"; return ok ? "atom" : "error";
} else { } else {
stream.eatWhile(/[^&<]/); stream.eatWhile(/[^&<]/);
return null; return null;
} }
} }
inText.isInText = true; inText.isInText = true;
function inTag(stream, state) { function inTag(stream, state) {
var ch = stream.next(); var ch = stream.next();
if (ch == ">" || (ch == "/" && stream.eat(">"))) { if (ch == ">" || (ch == "/" && stream.eat(">"))) {
state.tokenize = inText; state.tokenize = inText;
type = ch == ">" ? "endTag" : "selfcloseTag"; type = ch == ">" ? "endTag" : "selfcloseTag";
return "tag bracket"; return "tag bracket";
} else if (ch == "=") { } else if (ch == "=") {
type = "equals"; type = "equals";
return null; return null;
} else if (ch == "<") { } else if (ch == "<") {
state.tokenize = inText; state.tokenize = inText;
state.state = baseState; state.state = baseState;
state.tagName = state.tagStart = null; state.tagName = state.tagStart = null;
var next = state.tokenize(stream, state); var next = state.tokenize(stream, state);
return next ? next + " tag error" : "tag error"; return next ? next + " tag error" : "tag error";
} else if (/[\'\"]/.test(ch)) { } else if (/[\'\"]/.test(ch)) {
state.tokenize = inAttribute(ch); state.tokenize = inAttribute(ch);
state.stringStartCol = stream.column(); state.stringStartCol = stream.column();
return state.tokenize(stream, state); return state.tokenize(stream, state);
} else { } else {
stream.match(/^[^\s\u00a0=<>\"\']*[^\s\u00a0=<>\"\'\/]/); stream.match(/^[^\s\u00a0=<>\"\']*[^\s\u00a0=<>\"\'\/]/);
return "word"; return "word";
} }
} }
function inAttribute(quote) { function inAttribute(quote) {
var closure = function(stream, state) { var closure = function(stream, state) {
while (!stream.eol()) { while (!stream.eol()) {
if (stream.next() == quote) { if (stream.next() == quote) {
state.tokenize = inTag; state.tokenize = inTag;
break; break;
} }
} }
return "string"; return "string";
}; };
closure.isInAttribute = true; closure.isInAttribute = true;
return closure; return closure;
} }
function inBlock(style, terminator) { function inBlock(style, terminator) {
return function(stream, state) { return function(stream, state) {
while (!stream.eol()) { while (!stream.eol()) {
if (stream.match(terminator)) { if (stream.match(terminator)) {
state.tokenize = inText; state.tokenize = inText;
break; break;
} }
stream.next(); stream.next();
} }
return style; return style;
}; };
} }
function doctype(depth) { function doctype(depth) {
return function(stream, state) { return function(stream, state) {
var ch; var ch;
while ((ch = stream.next()) != null) { while ((ch = stream.next()) != null) {
if (ch == "<") { if (ch == "<") {
state.tokenize = doctype(depth + 1); state.tokenize = doctype(depth + 1);
return state.tokenize(stream, state); return state.tokenize(stream, state);
} else if (ch == ">") { } else if (ch == ">") {
if (depth == 1) { if (depth == 1) {
state.tokenize = inText; state.tokenize = inText;
break; break;
} else { } else {
state.tokenize = doctype(depth - 1); state.tokenize = doctype(depth - 1);
return state.tokenize(stream, state); return state.tokenize(stream, state);
} }
} }
} }
return "meta"; return "meta";
}; };
} }
function Context(state, tagName, startOfLine) { function Context(state, tagName, startOfLine) {
this.prev = state.context; this.prev = state.context;
this.tagName = tagName; this.tagName = tagName;
this.indent = state.indented; this.indent = state.indented;
this.startOfLine = startOfLine; this.startOfLine = startOfLine;
if (Kludges.doNotIndent.hasOwnProperty(tagName) || (state.context && state.context.noIndent)) if (Kludges.doNotIndent.hasOwnProperty(tagName) || (state.context && state.context.noIndent))
this.noIndent = true; this.noIndent = true;
} }
function popContext(state) { function popContext(state) {
if (state.context) state.context = state.context.prev; if (state.context) state.context = state.context.prev;
} }
function maybePopContext(state, nextTagName) { function maybePopContext(state, nextTagName) {
var parentTagName; var parentTagName;
while (true) { while (true) {
if (!state.context) { if (!state.context) {
return; return;
} }
parentTagName = state.context.tagName; parentTagName = state.context.tagName;
if (!Kludges.contextGrabbers.hasOwnProperty(parentTagName) || if (!Kludges.contextGrabbers.hasOwnProperty(parentTagName) ||
!Kludges.contextGrabbers[parentTagName].hasOwnProperty(nextTagName)) { !Kludges.contextGrabbers[parentTagName].hasOwnProperty(nextTagName)) {
return; return;
} }
popContext(state); popContext(state);
} }
} }
function baseState(type, stream, state) { function baseState(type, stream, state) {
if (type == "openTag") { if (type == "openTag") {
state.tagStart = stream.column(); state.tagStart = stream.column();
return tagNameState; return tagNameState;
} else if (type == "closeTag") { } else if (type == "closeTag") {
return closeTagNameState; return closeTagNameState;
} else { } else {
return baseState; return baseState;
} }
} }
function tagNameState(type, stream, state) { function tagNameState(type, stream, state) {
if (type == "word") { if (type == "word") {
state.tagName = stream.current(); state.tagName = stream.current();
setStyle = "tag"; setStyle = "tag";
return attrState; return attrState;
} else { } else {
setStyle = "error"; setStyle = "error";
return tagNameState; return tagNameState;
} }
} }
function closeTagNameState(type, stream, state) { function closeTagNameState(type, stream, state) {
if (type == "word") { if (type == "word") {
var tagName = stream.current(); var tagName = stream.current();
if (state.context && state.context.tagName != tagName && if (state.context && state.context.tagName != tagName &&
Kludges.implicitlyClosed.hasOwnProperty(state.context.tagName)) Kludges.implicitlyClosed.hasOwnProperty(state.context.tagName))
popContext(state); popContext(state);
if (state.context && state.context.tagName == tagName) { if (state.context && state.context.tagName == tagName) {
setStyle = "tag"; setStyle = "tag";
return closeState; return closeState;
} else { } else {
setStyle = "tag error"; setStyle = "tag error";
return closeStateErr; return closeStateErr;
} }
} else { } else {
setStyle = "error"; setStyle = "error";
return closeStateErr; return closeStateErr;
} }
} }
function closeState(type, _stream, state) { function closeState(type, _stream, state) {
if (type != "endTag") { if (type != "endTag") {
setStyle = "error"; setStyle = "error";
return closeState; return closeState;
} }
popContext(state); popContext(state);
return baseState; return baseState;
} }
function closeStateErr(type, stream, state) { function closeStateErr(type, stream, state) {
setStyle = "error"; setStyle = "error";
return closeState(type, stream, state); return closeState(type, stream, state);
} }
function attrState(type, _stream, state) { function attrState(type, _stream, state) {
if (type == "word") { if (type == "word") {
setStyle = "attribute"; setStyle = "attribute";
return attrEqState; return attrEqState;
} else if (type == "endTag" || type == "selfcloseTag") { } else if (type == "endTag" || type == "selfcloseTag") {
var tagName = state.tagName, tagStart = state.tagStart; var tagName = state.tagName, tagStart = state.tagStart;
state.tagName = state.tagStart = null; state.tagName = state.tagStart = null;
if (type == "selfcloseTag" || if (type == "selfcloseTag" ||
Kludges.autoSelfClosers.hasOwnProperty(tagName)) { Kludges.autoSelfClosers.hasOwnProperty(tagName)) {
maybePopContext(state, tagName); maybePopContext(state, tagName);
} else { } else {
maybePopContext(state, tagName); maybePopContext(state, tagName);
state.context = new Context(state, tagName, tagStart == state.indented); state.context = new Context(state, tagName, tagStart == state.indented);
} }
return baseState; return baseState;
} }
setStyle = "error"; setStyle = "error";
return attrState; return attrState;
} }
function attrEqState(type, stream, state) { function attrEqState(type, stream, state) {
if (type == "equals") return attrValueState; if (type == "equals") return attrValueState;
if (!Kludges.allowMissing) setStyle = "error"; if (!Kludges.allowMissing) setStyle = "error";
return attrState(type, stream, state); return attrState(type, stream, state);
} }
function attrValueState(type, stream, state) { function attrValueState(type, stream, state) {
if (type == "string") return attrContinuedState; if (type == "string") return attrContinuedState;
if (type == "word" && Kludges.allowUnquoted) {setStyle = "string"; return attrState;} if (type == "word" && Kludges.allowUnquoted) {setStyle = "string"; return attrState;}
setStyle = "error"; setStyle = "error";
return attrState(type, stream, state); return attrState(type, stream, state);
} }
function attrContinuedState(type, stream, state) { function attrContinuedState(type, stream, state) {
if (type == "string") return attrContinuedState; if (type == "string") return attrContinuedState;
return attrState(type, stream, state); return attrState(type, stream, state);
} }
return { return {
startState: function() { startState: function() {
return {tokenize: inText, return {tokenize: inText,
state: baseState, state: baseState,
indented: 0, indented: 0,
tagName: null, tagStart: null, tagName: null, tagStart: null,
context: null}; context: null};
}, },
token: function(stream, state) { token: function(stream, state) {
if (!state.tagName && stream.sol()) if (!state.tagName && stream.sol())
state.indented = stream.indentation(); state.indented = stream.indentation();
if (stream.eatSpace()) return null; if (stream.eatSpace()) return null;
type = null; type = null;
var style = state.tokenize(stream, state); var style = state.tokenize(stream, state);
if ((style || type) && style != "comment") { if ((style || type) && style != "comment") {
setStyle = null; setStyle = null;
state.state = state.state(type || style, stream, state); state.state = state.state(type || style, stream, state);
if (setStyle) if (setStyle)
style = setStyle == "error" ? style + " error" : setStyle; style = setStyle == "error" ? style + " error" : setStyle;
} }
return style; return style;
}, },
indent: function(state, textAfter, fullLine) { indent: function(state, textAfter, fullLine) {
var context = state.context; var context = state.context;
// Indent multi-line strings (e.g. css). // Indent multi-line strings (e.g. css).
if (state.tokenize.isInAttribute) { if (state.tokenize.isInAttribute) {
if (state.tagStart == state.indented) if (state.tagStart == state.indented)
return state.stringStartCol + 1; return state.stringStartCol + 1;
else else
return state.indented + indentUnit; return state.indented + indentUnit;
} }
if (context && context.noIndent) return CodeMirror.Pass; if (context && context.noIndent) return CodeMirror.Pass;
if (state.tokenize != inTag && state.tokenize != inText) if (state.tokenize != inTag && state.tokenize != inText)
return fullLine ? fullLine.match(/^(\s*)/)[0].length : 0; return fullLine ? fullLine.match(/^(\s*)/)[0].length : 0;
// Indent the starts of attribute names. // Indent the starts of attribute names.
if (state.tagName) { if (state.tagName) {
if (multilineTagIndentPastTag) if (multilineTagIndentPastTag)
return state.tagStart + state.tagName.length + 2; return state.tagStart + state.tagName.length + 2;
else else
return state.tagStart + indentUnit * multilineTagIndentFactor; return state.tagStart + indentUnit * multilineTagIndentFactor;
} }
if (alignCDATA && /<!\[CDATA\[/.test(textAfter)) return 0; if (alignCDATA && /<!\[CDATA\[/.test(textAfter)) return 0;
var tagAfter = textAfter && /^<(\/)?([\w_:\.-]*)/.exec(textAfter); var tagAfter = textAfter && /^<(\/)?([\w_:\.-]*)/.exec(textAfter);
if (tagAfter && tagAfter[1]) { // Closing tag spotted if (tagAfter && tagAfter[1]) { // Closing tag spotted
while (context) { while (context) {
if (context.tagName == tagAfter[2]) { if (context.tagName == tagAfter[2]) {
context = context.prev; context = context.prev;
break; break;
} else if (Kludges.implicitlyClosed.hasOwnProperty(context.tagName)) { } else if (Kludges.implicitlyClosed.hasOwnProperty(context.tagName)) {
context = context.prev; context = context.prev;
} else { } else {
break; break;
} }
} }
} else if (tagAfter) { // Opening tag spotted } else if (tagAfter) { // Opening tag spotted
while (context) { while (context) {
var grabbers = Kludges.contextGrabbers[context.tagName]; var grabbers = Kludges.contextGrabbers[context.tagName];
if (grabbers && grabbers.hasOwnProperty(tagAfter[2])) if (grabbers && grabbers.hasOwnProperty(tagAfter[2]))
context = context.prev; context = context.prev;
else else
break; break;
} }
} }
while (context && !context.startOfLine) while (context && !context.startOfLine)
context = context.prev; context = context.prev;
if (context) return context.indent + indentUnit; if (context) return context.indent + indentUnit;
else return 0; else return 0;
}, },
electricInput: /<\/[\s\w:]+>$/, electricInput: /<\/[\s\w:]+>$/,
blockCommentStart: "<!--", blockCommentStart: "<!--",
blockCommentEnd: "-->", blockCommentEnd: "-->",
configuration: parserConfig.htmlMode ? "html" : "xml", configuration: parserConfig.htmlMode ? "html" : "xml",
helperType: parserConfig.htmlMode ? "html" : "xml" helperType: parserConfig.htmlMode ? "html" : "xml"
}; };
}); });
@ -382,4 +382,4 @@ CodeMirror.defineMIME("application/xml", "xml");
if (!CodeMirror.mimeModes.hasOwnProperty("text/html")) if (!CodeMirror.mimeModes.hasOwnProperty("text/html"))
CodeMirror.defineMIME("text/html", {name: "xml", htmlMode: true}); CodeMirror.defineMIME("text/html", {name: "xml", htmlMode: true});
}); });

File diff suppressed because it is too large Load Diff

@ -88,6 +88,8 @@ function getState(cm, pos) {
ret.quote = true; ret.quote = true;
} else if(data === 'strikethrough') { } else if(data === 'strikethrough') {
ret.strikethrough = true; ret.strikethrough = true;
} else if(data === 'comment') {
ret.code = true;
} }
} }
return ret; return ret;
@ -331,12 +333,11 @@ function toggleSideBySide(editor) {
} }
// Start preview with the current text // Start preview with the current text
var parse = editor.constructor.markdown; preview.innerHTML = editor.options.previewRender(editor.value(), preview);
preview.innerHTML = parse(cm.getValue());
// Updates preview // Updates preview
cm.on('update', function() { cm.on('update', function() {
preview.innerHTML = parse(cm.getValue()); preview.innerHTML = editor.options.previewRender(editor.value(), preview);
}); });
} }
@ -349,9 +350,8 @@ function togglePreview(editor) {
var wrapper = cm.getWrapperElement(); var wrapper = cm.getWrapperElement();
var toolbar_div = wrapper.previousSibling; var toolbar_div = wrapper.previousSibling;
var toolbar = editor.toolbarElements.preview; var toolbar = editor.toolbarElements.preview;
var parse = editor.constructor.markdown;
var preview = wrapper.lastChild; var preview = wrapper.lastChild;
if(!/editor-preview/.test(preview.className)) { if(!preview || !/editor-preview/.test(preview.className)) {
preview = document.createElement('div'); preview = document.createElement('div');
preview.className = 'editor-preview'; preview.className = 'editor-preview';
wrapper.appendChild(preview); wrapper.appendChild(preview);
@ -373,8 +373,7 @@ function togglePreview(editor) {
toolbar.className += ' active'; toolbar.className += ' active';
toolbar_div.className += ' disabled-for-preview'; toolbar_div.className += ' disabled-for-preview';
} }
var text = cm.getValue(); preview.innerHTML = editor.options.previewRender(editor.value(), preview);
preview.innerHTML = parse(text);
// Turn off side by side if needed // Turn off side by side if needed
var sidebyside = cm.getWrapperElement().nextSibling; var sidebyside = cm.getWrapperElement().nextSibling;
@ -402,7 +401,9 @@ function _replaceSelection(cm, active, start, end) {
cm.replaceSelection(start + text + end); cm.replaceSelection(start + text + end);
startPoint.ch += start.length; startPoint.ch += start.length;
endPoint.ch += start.length; if(startPoint !== endPoint) {
endPoint.ch += start.length;
}
} }
cm.setSelection(startPoint, endPoint); cm.setSelection(startPoint, endPoint);
cm.focus(); cm.focus();
@ -555,10 +556,14 @@ function _toggleBlock(editor, type, start_chars, end_chars) {
if(type == "bold" || type == "strikethrough") { if(type == "bold" || type == "strikethrough") {
startPoint.ch -= 2; startPoint.ch -= 2;
endPoint.ch -= 2; if(startPoint !== endPoint) {
endPoint.ch -= 2;
}
} else if(type == "italic") { } else if(type == "italic") {
startPoint.ch -= 1; startPoint.ch -= 1;
endPoint.ch -= 1; if(startPoint !== endPoint) {
endPoint.ch -= 1;
}
} }
} else { } else {
text = cm.getSelection(); text = cm.getSelection();
@ -730,6 +735,10 @@ var toolbar = ["bold", "italic", "heading", "|", "quote", "unordered-list", "ord
function SimpleMDE(options) { function SimpleMDE(options) {
options = options || {}; options = options || {};
// Used later to refer to it's parent
options.parent = this;
// Find the textarea to use
if(options.element) { if(options.element) {
this.element = options.element; this.element = options.element;
} else if(options.element === null) { } else if(options.element === null) {
@ -738,6 +747,7 @@ function SimpleMDE(options) {
return; return;
} }
// Handle toolbar and status bar
if(options.toolbar !== false) if(options.toolbar !== false)
options.toolbar = options.toolbar || SimpleMDE.toolbar; options.toolbar = options.toolbar || SimpleMDE.toolbar;
@ -745,9 +755,21 @@ function SimpleMDE(options) {
options.status = ['autosave', 'lines', 'words', 'cursor']; options.status = ['autosave', 'lines', 'words', 'cursor'];
} }
// Add default preview rendering function
if(!options.previewRender) {
options.previewRender = function(plainText) {
// Note: 'this' refers to the options object
return this.parent.markdown(plainText);
}
}
// Set default options for parsing config
options.parsingConfig = options.parsingConfig || {};
// Update this options
this.options = options; this.options = options;
// If user has passed an element, it should auto rendered // Auto render
this.render(); this.render();
// The codemirror component is only available after rendering // The codemirror component is only available after rendering
@ -766,10 +788,10 @@ SimpleMDE.toolbar = toolbar;
/** /**
* Default markdown render. * Default markdown render.
*/ */
SimpleMDE.markdown = function(text) { SimpleMDE.prototype.markdown = function(text) {
if(window.marked) { if(window.marked) {
// Update options // Update options
if(this.options.singleLineBreaks !== false) { if(this.options && this.options.singleLineBreaks !== false) {
marked.setOptions({ marked.setOptions({
breaks: true breaks: true
}); });
@ -807,8 +829,8 @@ SimpleMDE.prototype.render = function(el) {
} }
keyMaps["Enter"] = "newlineAndIndentContinueMarkdownList"; keyMaps["Enter"] = "newlineAndIndentContinueMarkdownList";
keyMaps["Tab"] = "tabAndIndentContinueMarkdownList"; keyMaps["Tab"] = "tabAndIndentMarkdownList";
keyMaps["Shift-Tab"] = "shiftTabAndIndentContinueMarkdownList"; keyMaps["Shift-Tab"] = "shiftTabAndUnindentMarkdownList";
keyMaps["F11"] = function(cm) { keyMaps["F11"] = function(cm) {
toggleFullScreen(self); toggleFullScreen(self);
}; };
@ -816,21 +838,25 @@ SimpleMDE.prototype.render = function(el) {
toggleSideBySide(self); toggleSideBySide(self);
}; };
keyMaps["Esc"] = function(cm) { keyMaps["Esc"] = function(cm) {
if(cm.getOption("fullScreen")) cm.setOption("fullScreen", false); if(cm.getOption("fullScreen")) toggleFullScreen(self);
}; };
var mode = "spell-checker"; var mode, backdrop;
var backdrop = "gfm"; if(options.spellChecker !== false) {
mode = "spell-checker";
if(options.spellChecker === false) { backdrop = options.parsingConfig;
mode = "gfm"; backdrop.name = "gfm";
backdrop = undefined; backdrop.gitHubSpice = false;
} else {
mode = options.parsingConfig;
mode.name = "gfm";
mode.gitHubSpice = false;
} }
this.codemirror = CodeMirror.fromTextArea(el, { this.codemirror = CodeMirror.fromTextArea(el, {
mode: mode, mode: mode,
backdrop: backdrop, backdrop: backdrop,
theme: 'paper', theme: "paper",
tabSize: (options.tabSize != undefined) ? options.tabSize : 2, tabSize: (options.tabSize != undefined) ? options.tabSize : 2,
indentUnit: (options.tabSize != undefined) ? options.tabSize : 2, indentUnit: (options.tabSize != undefined) ? options.tabSize : 2,
indentWithTabs: (options.indentWithTabs === false) ? false : true, indentWithTabs: (options.indentWithTabs === false) ? false : true,
@ -850,7 +876,7 @@ SimpleMDE.prototype.render = function(el) {
this.autosave(); this.autosave();
} }
this.createSidebyside(); this.createSideBySide();
this._rendered = this.element; this._rendered = this.element;
}; };
@ -905,12 +931,12 @@ SimpleMDE.prototype.autosave = function() {
}, this.options.autosave.delay || 10000); }, this.options.autosave.delay || 10000);
}; };
SimpleMDE.prototype.createSidebyside = function() { SimpleMDE.prototype.createSideBySide = function() {
var cm = this.codemirror; var cm = this.codemirror;
var wrapper = cm.getWrapperElement(); var wrapper = cm.getWrapperElement();
var preview = wrapper.nextSibling; var preview = wrapper.nextSibling;
if(!/editor-preview-side/.test(preview.className)) { if(!preview || !/editor-preview-side/.test(preview.className)) {
preview = document.createElement('div'); preview = document.createElement('div');
preview.className = 'editor-preview-side'; preview.className = 'editor-preview-side';
wrapper.parentNode.insertBefore(preview, wrapper.nextSibling); wrapper.parentNode.insertBefore(preview, wrapper.nextSibling);

Loading…
Cancel
Save