From 14c21da8e7e7f4db9a0123b34e3098b3c8fb4f8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedikt=20R=C3=B6tsch?= Date: Thu, 18 Apr 2019 20:15:05 +0700 Subject: [PATCH 1/2] fix indentations and white space errors via prettier --- package-lock.json | 47 +- package.json | 9 +- src/css/easymde.css | 110 ++-- src/js/codemirror/tablist.js | 10 +- src/js/easymde.js | 978 +++++++++++++++++++++-------------- 5 files changed, 708 insertions(+), 446 deletions(-) diff --git a/package-lock.json b/package-lock.json index ccd44264..23fcabe8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1991,8 +1991,7 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "aproba": { "version": "1.2.0", @@ -2013,14 +2012,12 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -2035,20 +2032,17 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "core-util-is": { "version": "1.0.2", @@ -2165,8 +2159,7 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "ini": { "version": "1.3.5", @@ -2178,7 +2171,6 @@ "version": "1.0.0", "bundled": true, "dev": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -2193,7 +2185,6 @@ "version": "3.0.4", "bundled": true, "dev": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -2201,14 +2192,12 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "minipass": { "version": "2.3.5", "bundled": true, "dev": true, - "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -2227,7 +2216,6 @@ "version": "0.5.1", "bundled": true, "dev": true, - "optional": true, "requires": { "minimist": "0.0.8" } @@ -2308,8 +2296,7 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "object-assign": { "version": "4.1.1", @@ -2321,7 +2308,6 @@ "version": "1.4.0", "bundled": true, "dev": true, - "optional": true, "requires": { "wrappy": "1" } @@ -2407,8 +2393,7 @@ "safe-buffer": { "version": "5.1.2", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "safer-buffer": { "version": "2.1.2", @@ -2444,7 +2429,6 @@ "version": "1.0.2", "bundled": true, "dev": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -2464,7 +2448,6 @@ "version": "3.0.1", "bundled": true, "dev": true, - "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -2508,14 +2491,12 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "yallist": { "version": "3.0.3", "bundled": true, - "dev": true, - "optional": true + "dev": true } } }, @@ -4157,6 +4138,12 @@ "integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=", "dev": true }, + "prettier": { + "version": "1.17.0", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.17.0.tgz", + "integrity": "sha512-sXe5lSt2WQlCbydGETgfm1YBShgOX4HxQkFPvbxkcwgDvGDeqVau8h+12+lmSVlP3rHPz0oavfddSZg/q+Szjw==", + "dev": true + }, "pretty-hrtime": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/pretty-hrtime/-/pretty-hrtime-1.0.3.tgz", diff --git a/package.json b/package.json index 23441c86..3fdaff15 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "gulp-header": "^2.0.7", "gulp-rename": "^1.4.0", "gulp-uglify": "^3.0.1", + "prettier": "1.17.0", "typescript": "^3.3.3", "vinyl-buffer": "^1.0.0", "vinyl-source-stream": "^2.0.0" @@ -40,6 +41,12 @@ "repository": "github:Ionaru/easy-markdown-editor", "scripts": { "prepare": "gulp", - "test:types": "tsc --project types/tsconfig.json" + "test:types": "tsc --project types/tsconfig.json", + "format": "prettier --write 'src/**/*'" + }, + "prettier": { + "trailingComma": "es5", + "tabWidth": 4, + "singleQuote": true } } diff --git a/src/css/easymde.css b/src/css/easymde.css index 3843bdc4..733d25a5 100644 --- a/src/css/easymde.css +++ b/src/css/easymde.css @@ -32,7 +32,7 @@ } .CodeMirror-placeholder { - opacity: .5; + opacity: 0.5; } .CodeMirror-focused .CodeMirror-selected { @@ -62,11 +62,11 @@ } .editor-toolbar:before { - margin-bottom: 8px + margin-bottom: 8px; } .editor-toolbar:after { - margin-top: 8px + margin-top: 8px; } .editor-toolbar.fullscreen { @@ -90,12 +90,38 @@ .editor-toolbar.fullscreen::before { width: 20px; height: 50px; - background: -moz-linear-gradient(left, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 0) 100%); - background: -webkit-gradient(linear, left top, right top, color-stop(0%, rgba(255, 255, 255, 1)), color-stop(100%, rgba(255, 255, 255, 0))); - background: -webkit-linear-gradient(left, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 0) 100%); - background: -o-linear-gradient(left, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 0) 100%); - background: -ms-linear-gradient(left, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 0) 100%); - background: linear-gradient(to right, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 0) 100%); + background: -moz-linear-gradient( + left, + rgba(255, 255, 255, 1) 0%, + rgba(255, 255, 255, 0) 100% + ); + background: -webkit-gradient( + linear, + left top, + right top, + color-stop(0%, rgba(255, 255, 255, 1)), + color-stop(100%, rgba(255, 255, 255, 0)) + ); + background: -webkit-linear-gradient( + left, + rgba(255, 255, 255, 1) 0%, + rgba(255, 255, 255, 0) 100% + ); + background: -o-linear-gradient( + left, + rgba(255, 255, 255, 1) 0%, + rgba(255, 255, 255, 0) 100% + ); + background: -ms-linear-gradient( + left, + rgba(255, 255, 255, 1) 0%, + rgba(255, 255, 255, 0) 100% + ); + background: linear-gradient( + to right, + rgba(255, 255, 255, 1) 0%, + rgba(255, 255, 255, 0) 100% + ); position: fixed; top: 0; left: 0; @@ -106,12 +132,38 @@ .editor-toolbar.fullscreen::after { width: 20px; height: 50px; - background: -moz-linear-gradient(left, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 1) 100%); - background: -webkit-gradient(linear, left top, right top, color-stop(0%, rgba(255, 255, 255, 0)), color-stop(100%, rgba(255, 255, 255, 1))); - background: -webkit-linear-gradient(left, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 1) 100%); - background: -o-linear-gradient(left, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 1) 100%); - background: -ms-linear-gradient(left, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 1) 100%); - background: linear-gradient(to right, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 1) 100%); + background: -moz-linear-gradient( + left, + rgba(255, 255, 255, 0) 0%, + rgba(255, 255, 255, 1) 100% + ); + background: -webkit-gradient( + linear, + left top, + right top, + color-stop(0%, rgba(255, 255, 255, 0)), + color-stop(100%, rgba(255, 255, 255, 1)) + ); + background: -webkit-linear-gradient( + left, + rgba(255, 255, 255, 0) 0%, + rgba(255, 255, 255, 1) 100% + ); + background: -o-linear-gradient( + left, + rgba(255, 255, 255, 0) 0%, + rgba(255, 255, 255, 1) 100% + ); + background: -ms-linear-gradient( + left, + rgba(255, 255, 255, 0) 0%, + rgba(255, 255, 255, 1) 100% + ); + background: linear-gradient( + to right, + rgba(255, 255, 255, 0) 0%, + rgba(255, 255, 255, 1) 100% + ); position: fixed; top: 0; right: 0; @@ -150,7 +202,7 @@ } .editor-toolbar button:after { - font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; + font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; font-size: 65%; vertical-align: text-bottom; position: relative; @@ -158,27 +210,27 @@ } .editor-toolbar button.heading-1:after { - content: "1"; + content: '1'; } .editor-toolbar button.heading-2:after { - content: "2"; + content: '2'; } .editor-toolbar button.heading-3:after { - content: "3"; + content: '3'; } .editor-toolbar button.heading-bigger:after { - content: "▲"; + content: '▲'; } .editor-toolbar button.heading-smaller:after { - content: "▼"; + content: '▼'; } .editor-toolbar.disabled-for-preview button:not(.no-disable) { - opacity: .6; + opacity: 0.6; pointer-events: none; } @@ -202,15 +254,15 @@ } .editor-statusbar .lines:before { - content: 'lines: ' + content: 'lines: '; } .editor-statusbar .words:before { - content: 'words: ' + content: 'words: '; } .editor-statusbar .characters:before { - content: 'characters: ' + content: 'characters: '; } .editor-preview { @@ -244,16 +296,16 @@ } .editor-preview-active-side { - display: block + display: block; } .editor-preview-active { - display: block + display: block; } .editor-preview > p, .editor-preview-side > p { - margin-top: 0 + margin-top: 0; } .editor-preview pre, @@ -303,7 +355,7 @@ } .cm-s-easymde .cm-comment { - background: rgba(0, 0, 0, .05); + background: rgba(0, 0, 0, 0.05); border-radius: 2px; } diff --git a/src/js/codemirror/tablist.js b/src/js/codemirror/tablist.js index 0ec9c8d9..b992b5b2 100644 --- a/src/js/codemirror/tablist.js +++ b/src/js/codemirror/tablist.js @@ -3,7 +3,7 @@ var CodeMirror = require('codemirror'); -CodeMirror.commands.tabAndIndentMarkdownList = function (cm) { +CodeMirror.commands.tabAndIndentMarkdownList = function(cm) { var ranges = cm.listSelections(); var pos = ranges[0].head; var eolState = cm.getStateAfter(pos.line); @@ -16,14 +16,13 @@ CodeMirror.commands.tabAndIndentMarkdownList = function (cm) { if (cm.options.indentWithTabs) { cm.execCommand('insertTab'); - } - else { + } else { var spaces = Array(cm.options.tabSize + 1).join(' '); cm.replaceSelection(spaces); } }; -CodeMirror.commands.shiftTabAndUnindentMarkdownList = function (cm) { +CodeMirror.commands.shiftTabAndUnindentMarkdownList = function(cm) { var ranges = cm.listSelections(); var pos = ranges[0].head; var eolState = cm.getStateAfter(pos.line); @@ -36,8 +35,7 @@ CodeMirror.commands.shiftTabAndUnindentMarkdownList = function (cm) { if (cm.options.indentWithTabs) { cm.execCommand('insertTab'); - } - else { + } else { var spaces = Array(cm.options.tabSize + 1).join(' '); cm.replaceSelection(spaces); } diff --git a/src/js/easymde.js b/src/js/easymde.js index fcfa951d..9f838317 100644 --- a/src/js/easymde.js +++ b/src/js/easymde.js @@ -14,55 +14,54 @@ require('codemirror/mode/xml/xml.js'); var CodeMirrorSpellChecker = require('codemirror-spell-checker'); var marked = require('marked'); - // Some variables var isMac = /Mac/.test(navigator.platform); var anchorToExternalRegex = new RegExp(/()+?/g); // Mapping of actions that can be bound to keyboard shortcuts or toolbar buttons var bindings = { - 'toggleBold': toggleBold, - 'toggleItalic': toggleItalic, - 'drawLink': drawLink, - 'toggleHeadingSmaller': toggleHeadingSmaller, - 'toggleHeadingBigger': toggleHeadingBigger, - 'drawImage': drawImage, - 'toggleBlockquote': toggleBlockquote, - 'toggleOrderedList': toggleOrderedList, - 'toggleUnorderedList': toggleUnorderedList, - 'toggleCodeBlock': toggleCodeBlock, - 'togglePreview': togglePreview, - 'toggleStrikethrough': toggleStrikethrough, - 'toggleHeading1': toggleHeading1, - 'toggleHeading2': toggleHeading2, - 'toggleHeading3': toggleHeading3, - 'cleanBlock': cleanBlock, - 'drawTable': drawTable, - 'drawHorizontalRule': drawHorizontalRule, - 'undo': undo, - 'redo': redo, - 'toggleSideBySide': toggleSideBySide, - 'toggleFullScreen': toggleFullScreen, + toggleBold: toggleBold, + toggleItalic: toggleItalic, + drawLink: drawLink, + toggleHeadingSmaller: toggleHeadingSmaller, + toggleHeadingBigger: toggleHeadingBigger, + drawImage: drawImage, + toggleBlockquote: toggleBlockquote, + toggleOrderedList: toggleOrderedList, + toggleUnorderedList: toggleUnorderedList, + toggleCodeBlock: toggleCodeBlock, + togglePreview: togglePreview, + toggleStrikethrough: toggleStrikethrough, + toggleHeading1: toggleHeading1, + toggleHeading2: toggleHeading2, + toggleHeading3: toggleHeading3, + cleanBlock: cleanBlock, + drawTable: drawTable, + drawHorizontalRule: drawHorizontalRule, + undo: undo, + redo: redo, + toggleSideBySide: toggleSideBySide, + toggleFullScreen: toggleFullScreen, }; var shortcuts = { - 'toggleBold': 'Cmd-B', - 'toggleItalic': 'Cmd-I', - 'drawLink': 'Cmd-K', - 'toggleHeadingSmaller': 'Cmd-H', - 'toggleHeadingBigger': 'Shift-Cmd-H', - 'cleanBlock': 'Cmd-E', - 'drawImage': 'Cmd-Alt-I', - 'toggleBlockquote': 'Cmd-\'', - 'toggleOrderedList': 'Cmd-Alt-L', - 'toggleUnorderedList': 'Cmd-L', - 'toggleCodeBlock': 'Cmd-Alt-C', - 'togglePreview': 'Cmd-P', - 'toggleSideBySide': 'F9', - 'toggleFullScreen': 'F11', + toggleBold: 'Cmd-B', + toggleItalic: 'Cmd-I', + drawLink: 'Cmd-K', + toggleHeadingSmaller: 'Cmd-H', + toggleHeadingBigger: 'Shift-Cmd-H', + cleanBlock: 'Cmd-E', + drawImage: 'Cmd-Alt-I', + toggleBlockquote: "Cmd-'", + toggleOrderedList: 'Cmd-Alt-L', + toggleUnorderedList: 'Cmd-L', + toggleCodeBlock: 'Cmd-Alt-C', + togglePreview: 'Cmd-P', + toggleSideBySide: 'F9', + toggleFullScreen: 'F11', }; -var getBindingName = function (f) { +var getBindingName = function(f) { for (var key in bindings) { if (bindings[key] === f) { return key; @@ -71,10 +70,18 @@ var getBindingName = function (f) { return null; }; -var isMobile = function () { +var isMobile = function() { var check = false; - (function (a) { - if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw-(n|u)|c55\/|capi|ccwa|cdm-|cell|chtm|cldc|cmd-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc-s|devi|dica|dmob|do(c|p)o|ds(12|-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(-|_)|g1 u|g560|gene|gf-5|g-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd-(m|p|t)|hei-|hi(pt|ta)|hp( i|ip)|hs-c|ht(c(-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i-(20|go|ma)|i230|iac( |-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|-[a-w])|libw|lynx|m1-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|-([1-8]|c))|phil|pire|pl(ay|uc)|pn-2|po(ck|rt|se)|prox|psio|pt-g|qa-a|qc(07|12|21|32|60|-[2-7]|i-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h-|oo|p-)|sdk\/|se(c(-|0|1)|47|mc|nd|ri)|sgh-|shar|sie(-|m)|sk-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h-|v-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl-|tdg-|tel(i|m)|tim-|t-mo|to(pl|sh)|ts(70|m-|m3|m5)|tx-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas-|your|zeto|zte-/i.test(a.substr(0, 4))) check = true; + (function(a) { + if ( + /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test( + a + ) || + /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw-(n|u)|c55\/|capi|ccwa|cdm-|cell|chtm|cldc|cmd-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc-s|devi|dica|dmob|do(c|p)o|ds(12|-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(-|_)|g1 u|g560|gene|gf-5|g-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd-(m|p|t)|hei-|hi(pt|ta)|hp( i|ip)|hs-c|ht(c(-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i-(20|go|ma)|i230|iac( |-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|-[a-w])|libw|lynx|m1-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|-([1-8]|c))|phil|pire|pl(ay|uc)|pn-2|po(ck|rt|se)|prox|psio|pt-g|qa-a|qc(07|12|21|32|60|-[2-7]|i-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h-|oo|p-)|sdk\/|se(c(-|0|1)|47|mc|nd|ri)|sgh-|shar|sie(-|m)|sk-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h-|v-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl-|tdg-|tel(i|m)|tim-|t-mo|to(pl|sh)|ts(70|m-|m3|m5)|tx-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas-|your|zeto|zte-/i.test( + a.substr(0, 4) + ) + ) + check = true; })(navigator.userAgent || navigator.vendor || window.opera); return check; }; @@ -98,7 +105,6 @@ function addAnchorTargetBlank(htmlText) { return htmlText; } - /** * Fix shortcut. Mac use Command, others use Ctrl. */ @@ -111,7 +117,6 @@ function fixShortcut(name) { return name; } - /** * Create button element for toolbar. */ @@ -120,13 +125,13 @@ function createToolbarButton(options, enableTooltips, shortcuts) { var el = document.createElement('button'); el.className = options.name; el.setAttribute('type', 'button'); - enableTooltips = (enableTooltips == undefined) ? true : enableTooltips; + enableTooltips = enableTooltips == undefined ? true : enableTooltips; // Properly hande custom shortcuts - if( options.name && options.name in shortcuts ){ - bindings[options.name] = options.action; + if (options.name && options.name in shortcuts) { + bindings[options.name] = options.action; } - + if (options.title && enableTooltips) { el.title = createTooltip(options.title, options.action, shortcuts); @@ -147,7 +152,11 @@ function createToolbarButton(options, enableTooltips, shortcuts) { // Provide backwards compatibility with simple-markdown-editor by adding custom classes to the button. var classNameParts = options.className.split(' '); var iconClasses = []; - for (var classNameIndex = 0; classNameIndex < classNameParts.length; classNameIndex++) { + for ( + var classNameIndex = 0; + classNameIndex < classNameParts.length; + classNameIndex++ + ) { var classNamePart = classNameParts[classNameIndex]; // Split icon classes from the button. // Regex will detect "fa", "fas", "fa-something" and "fa-some-icon-1", but not "fanfare". @@ -162,7 +171,11 @@ function createToolbarButton(options, enableTooltips, shortcuts) { // Create icon element and append as a child to the button var icon = document.createElement('i'); - for (var iconClassIndex = 0; iconClassIndex < iconClasses.length; iconClassIndex++) { + for ( + var iconClassIndex = 0; + iconClassIndex < iconClasses.length; + iconClassIndex++ + ) { var iconClass = iconClasses[iconClassIndex]; icon.classList.add(iconClass); } @@ -203,7 +216,8 @@ function getState(cm, pos) { var types = stat.type.split(' '); var ret = {}, - data, text; + data, + text; for (var i = 0; i < types.length; i++) { data = types[i]; if (data === 'strong') { @@ -236,7 +250,6 @@ function getState(cm, pos) { return ret; } - // Saved overflow setting var saved_overflow = ''; @@ -248,7 +261,6 @@ function toggleFullScreen(editor) { var cm = editor.codemirror; cm.setOption('fullScreen', !cm.getOption('fullScreen')); - // Prevent scrolling on body during fullscreen active if (cm.getOption('fullScreen')) { saved_overflow = document.body.style.overflow; @@ -257,17 +269,18 @@ function toggleFullScreen(editor) { document.body.style.overflow = saved_overflow; } - // Update toolbar class var wrap = cm.getWrapperElement(); if (!/fullscreen/.test(wrap.previousSibling.className)) { wrap.previousSibling.className += ' fullscreen'; } else { - wrap.previousSibling.className = wrap.previousSibling.className.replace(/\s*fullscreen\b/, ''); + wrap.previousSibling.className = wrap.previousSibling.className.replace( + /\s*fullscreen\b/, + '' + ); } - // Update toolbar button if (editor.toolbarElements && editor.toolbarElements.fullscreen) { var toolbarButton = editor.toolbarElements.fullscreen; @@ -275,22 +288,23 @@ function toggleFullScreen(editor) { if (!/active/.test(toolbarButton.className)) { toolbarButton.className += ' active'; } else { - toolbarButton.className = toolbarButton.className.replace(/\s*active\s*/g, ''); + toolbarButton.className = toolbarButton.className.replace( + /\s*active\s*/g, + '' + ); } } - // Hide side by side if needed var sidebyside = cm.getWrapperElement().nextSibling; if (/editor-preview-active-side/.test(sidebyside.className)) toggleSideBySide(editor); - if (editor.options.onToggleFullScreen) { + if (editor.options.onToggleFullScreen) { editor.options.onToggleFullScreen(cm.getOption('fullScreen') || false); } } - /** * Action for toggling bold. */ @@ -298,7 +312,6 @@ function toggleBold(editor) { _toggleBlock(editor, 'bold', editor.options.blockStyles.bold); } - /** * Action for toggling italic. */ @@ -306,7 +319,6 @@ function toggleItalic(editor) { _toggleBlock(editor, 'italic', editor.options.blockStyles.italic); } - /** * Action for toggling strikethrough. */ @@ -323,9 +335,16 @@ function toggleCodeBlock(editor) { function fencing_line(line) { /* return true, if this is a ``` or ~~~ line */ if (typeof line !== 'object') { - throw 'fencing_line() takes a \'line\' object (not a line number, or line text). Got: ' + typeof line + ': ' + line; + throw "fencing_line() takes a 'line' object (not a line number, or line text). Got: " + + typeof line + + ': ' + + line; } - return line.styles && line.styles[2] && line.styles[2].indexOf('formatting-code-block') !== -1; + return ( + line.styles && + line.styles[2] && + line.styles[2].indexOf('formatting-code-block') !== -1 + ); } function token_state(token) { @@ -341,14 +360,19 @@ function toggleCodeBlock(editor) { * To check in the middle of a line, pass in firstTok yourself. */ line = line || cm.getLineHandle(line_num); - firstTok = firstTok || cm.getTokenAt({ - line: line_num, - ch: 1, - }); - lastTok = lastTok || (!!line.text && cm.getTokenAt({ - line: line_num, - ch: line.text.length - 1, - })); + firstTok = + firstTok || + cm.getTokenAt({ + line: line_num, + ch: 1, + }); + lastTok = + lastTok || + (!!line.text && + cm.getTokenAt({ + line: line_num, + ch: line.text.length - 1, + })); var types = firstTok.type ? firstTok.type.split(' ') : []; if (lastTok && token_state(lastTok).indentedCode) { // have to check last char, since first chars of first line aren"t marked as indented @@ -356,14 +380,23 @@ function toggleCodeBlock(editor) { } else if (types.indexOf('comment') === -1) { // has to be after "indented" check, since first chars of first indented line aren"t marked as such return false; - } else if (token_state(firstTok).fencedChars || token_state(lastTok).fencedChars || fencing_line(line)) { + } else if ( + token_state(firstTok).fencedChars || + token_state(lastTok).fencedChars || + fencing_line(line) + ) { return 'fenced'; } else { return 'single'; } } - function insertFencingAtSelection(cm, cur_start, cur_end, fenceCharsToInsert) { + function insertFencingAtSelection( + cm, + cur_start, + cur_end, + fenceCharsToInsert + ) { var start_line_sel = cur_start.line + 1, end_line_sel = cur_end.line + 1, sel_multi = cur_start.line !== cur_end.line, @@ -378,13 +411,16 @@ function toggleCodeBlock(editor) { end_line_sel--; } _replaceSelection(cm, false, [repl_start, repl_end]); - cm.setSelection({ - line: start_line_sel, - ch: 0, - }, { - line: end_line_sel, - ch: 0, - }); + cm.setSelection( + { + line: start_line_sel, + ch: 0, + }, + { + line: end_line_sel, + ch: 0, + } + ); } var cm = editor.codemirror, @@ -402,13 +438,17 @@ function toggleCodeBlock(editor) { // similar to some EasyMDE _toggleBlock logic var start = line.text.slice(0, cur_start.ch).replace('`', ''), end = line.text.slice(cur_start.ch).replace('`', ''); - cm.replaceRange(start + end, { - line: cur_start.line, - ch: 0, - }, { - line: cur_start.line, - ch: 99999999999999, - }); + cm.replaceRange( + start + end, + { + line: cur_start.line, + ch: 0, + }, + { + line: cur_start.line, + ch: 99999999999999, + } + ); cur_start.ch--; if (cur_start !== cur_end) { cur_end.ch--; @@ -420,7 +460,11 @@ function toggleCodeBlock(editor) { // use selection // find the fenced line so we know what type it is (tilde, backticks, number of them) - for (block_start = cur_start.line; block_start >= 0; block_start--) { + for ( + block_start = cur_start.line; + block_start >= 0; + block_start-- + ) { line = cm.getLineHandle(block_start); if (fencing_line(line)) { break; @@ -450,7 +494,10 @@ function toggleCodeBlock(editor) { if (cur_end.ch === 0) { end_line += 1; } - } else if (cur_end.ch !== 0 && fencing_line(cm.getLineHandle(cur_end.line + 1))) { + } else if ( + cur_end.ch !== 0 && + fencing_line(cm.getLineHandle(cur_end.line + 1)) + ) { end_text = ''; end_line = cur_end.line + 1; } else { @@ -461,35 +508,47 @@ function toggleCodeBlock(editor) { // full last line selected, putting cursor at beginning of next end_line -= 1; } - cm.operation(function () { + cm.operation(function() { // end line first, so that line numbers don't change - cm.replaceRange(end_text, { - line: end_line, - ch: 0, - }, { - line: end_line + (end_text ? 0 : 1), - ch: 0, - }); - cm.replaceRange(start_text, { - line: start_line, + cm.replaceRange( + end_text, + { + line: end_line, + ch: 0, + }, + { + line: end_line + (end_text ? 0 : 1), + ch: 0, + } + ); + cm.replaceRange( + start_text, + { + line: start_line, + ch: 0, + }, + { + line: start_line + (start_text ? 0 : 1), + ch: 0, + } + ); + }); + cm.setSelection( + { + line: start_line + (start_text ? 1 : 0), ch: 0, - }, { - line: start_line + (start_text ? 0 : 1), + }, + { + line: end_line + (start_text ? 1 : -1), ch: 0, - }); - }); - cm.setSelection({ - line: start_line + (start_text ? 1 : 0), - ch: 0, - }, { - line: end_line + (start_text ? 1 : -1), - ch: 0, - }); + } + ); cm.focus(); } else { // no selection, search for ends of this fenced block var search_from = cur_start.line; - if (fencing_line(cm.getLineHandle(cur_start.line))) { // gets a little tricky if cursor is right on a fenced line + if (fencing_line(cm.getLineHandle(cur_start.line))) { + // gets a little tricky if cursor is right on a fenced line if (code_type(cm, cur_start.line + 1) === 'fenced') { block_start = cur_start.line; search_from = cur_start.line + 1; // for searching for "end" @@ -499,7 +558,11 @@ function toggleCodeBlock(editor) { } } if (block_start === undefined) { - for (block_start = search_from; block_start >= 0; block_start--) { + for ( + block_start = search_from; + block_start >= 0; + block_start-- + ) { line = cm.getLineHandle(block_start); if (fencing_line(line)) { break; @@ -508,28 +571,40 @@ function toggleCodeBlock(editor) { } if (block_end === undefined) { lineCount = cm.lineCount(); - for (block_end = search_from; block_end < lineCount; block_end++) { + for ( + block_end = search_from; + block_end < lineCount; + block_end++ + ) { line = cm.getLineHandle(block_end); if (fencing_line(line)) { break; } } } - cm.operation(function () { - cm.replaceRange('', { - line: block_start, - ch: 0, - }, { - line: block_start + 1, - ch: 0, - }); - cm.replaceRange('', { - line: block_end - 1, - ch: 0, - }, { - line: block_end, - ch: 0, - }); + cm.operation(function() { + cm.replaceRange( + '', + { + line: block_start, + ch: 0, + }, + { + line: block_start + 1, + ch: 0, + } + ); + cm.replaceRange( + '', + { + line: block_end - 1, + ch: 0, + }, + { + line: block_end, + ch: 0, + } + ); }); cm.focus(); } @@ -543,7 +618,11 @@ function toggleCodeBlock(editor) { } } else { // no selection, search for ends of this indented block - for (block_start = cur_start.line; block_start >= 0; block_start--) { + for ( + block_start = cur_start.line; + block_start >= 0; + block_start-- + ) { line = cm.getLineHandle(block_start); if (line.text.match(/^\s*$/)) { // empty or all whitespace - keep going @@ -556,7 +635,11 @@ function toggleCodeBlock(editor) { } } lineCount = cm.lineCount(); - for (block_end = cur_start.line; block_end < lineCount; block_end++) { + for ( + block_end = cur_start.line; + block_end < lineCount; + block_end++ + ) { line = cm.getLineHandle(block_end); if (line.text.match(/^\s*$/)) { // empty or all whitespace - keep going @@ -572,11 +655,15 @@ function toggleCodeBlock(editor) { // if we are going to un-indent based on a selected set of lines, and the next line is indented too, we need to // insert a blank line so that the next line(s) continue to be indented code var next_line = cm.getLineHandle(block_end + 1), - next_line_last_tok = next_line && cm.getTokenAt({ - line: block_end + 1, - ch: next_line.text.length - 1, - }), - next_line_indented = next_line_last_tok && token_state(next_line_last_tok).indentedCode; + next_line_last_tok = + next_line && + cm.getTokenAt({ + line: block_end + 1, + ch: next_line.text.length - 1, + }), + next_line_indented = + next_line_last_tok && + token_state(next_line_last_tok).indentedCode; if (next_line_indented) { cm.replaceRange('\n', { line: block_end + 1, @@ -590,10 +677,18 @@ function toggleCodeBlock(editor) { cm.focus(); } else { // insert code formatting - var no_sel_and_starting_of_line = (cur_start.line === cur_end.line && cur_start.ch === cur_end.ch && cur_start.ch === 0); + var no_sel_and_starting_of_line = + cur_start.line === cur_end.line && + cur_start.ch === cur_end.ch && + cur_start.ch === 0; var sel_multi = cur_start.line !== cur_end.line; if (no_sel_and_starting_of_line || sel_multi) { - insertFencingAtSelection(cm, cur_start, cur_end, fenceCharsToInsert); + insertFencingAtSelection( + cm, + cur_start, + cur_end, + fenceCharsToInsert + ); } else { _replaceSelection(cm, false, ['`', '`']); } @@ -648,7 +743,6 @@ function toggleHeading3(editor) { _toggleHeading(cm, undefined, 3); } - /** * Action for toggling ul. */ @@ -657,7 +751,6 @@ function toggleUnorderedList(editor) { _toggleLine(cm, 'unordered-list'); } - /** * Action for toggling ol. */ @@ -728,7 +821,6 @@ function drawHorizontalRule(editor) { _replaceSelection(cm, stat.image, options.insertTexts.horizontalRule); } - /** * Undo action. */ @@ -738,7 +830,6 @@ function undo(editor) { cm.focus(); } - /** * Redo action. */ @@ -748,7 +839,6 @@ function redo(editor) { cm.focus(); } - /** * Toggle side by side preview */ @@ -756,21 +846,29 @@ function toggleSideBySide(editor) { var cm = editor.codemirror; var wrapper = cm.getWrapperElement(); var preview = wrapper.nextSibling; - var toolbarButton = editor.toolbarElements && editor.toolbarElements['side-by-side']; + var toolbarButton = + editor.toolbarElements && editor.toolbarElements['side-by-side']; var useSideBySideListener = false; if (/editor-preview-active-side/.test(preview.className)) { preview.className = preview.className.replace( - /\s*editor-preview-active-side\s*/g, '' + /\s*editor-preview-active-side\s*/g, + '' + ); + if (toolbarButton) + toolbarButton.className = toolbarButton.className.replace( + /\s*active\s*/g, + '' + ); + wrapper.className = wrapper.className.replace( + /\s*CodeMirror-sided\s*/g, + ' ' ); - if (toolbarButton) toolbarButton.className = toolbarButton.className.replace(/\s*active\s*/g, ''); - wrapper.className = wrapper.className.replace(/\s*CodeMirror-sided\s*/g, ' '); } else { // When the preview button is clicked for the first time, // give some time for the transition from editor.css to fire and the view to slide from right to left, // instead of just appearing. - setTimeout(function () { - if (!cm.getOption('fullScreen')) - toggleFullScreen(editor); + setTimeout(function() { + if (!cm.getOption('fullScreen')) toggleFullScreen(editor); preview.className += ' editor-preview-active-side'; }, 1); if (toolbarButton) toolbarButton.className += ' active'; @@ -782,16 +880,23 @@ function toggleSideBySide(editor) { var previewNormal = wrapper.lastChild; if (/editor-preview-active/.test(previewNormal.className)) { previewNormal.className = previewNormal.className.replace( - /\s*editor-preview-active\s*/g, '' + /\s*editor-preview-active\s*/g, + '' ); var toolbar = editor.toolbarElements.preview; var toolbar_div = wrapper.previousSibling; toolbar.className = toolbar.className.replace(/\s*active\s*/g, ''); - toolbar_div.className = toolbar_div.className.replace(/\s*disabled-for-preview*/g, ''); + toolbar_div.className = toolbar_div.className.replace( + /\s*disabled-for-preview*/g, + '' + ); } - var sideBySideRenderingFunction = function () { - preview.innerHTML = editor.options.previewRender(editor.value(), preview); + var sideBySideRenderingFunction = function() { + preview.innerHTML = editor.options.previewRender( + editor.value(), + preview + ); }; if (!cm.sideBySideRenderingFunction) { @@ -799,7 +904,10 @@ function toggleSideBySide(editor) { } if (useSideBySideListener) { - preview.innerHTML = editor.options.previewRender(editor.value(), preview); + preview.innerHTML = editor.options.previewRender( + editor.value(), + preview + ); cm.on('update', cm.sideBySideRenderingFunction); } else { cm.off('update', cm.sideBySideRenderingFunction); @@ -809,7 +917,6 @@ function toggleSideBySide(editor) { cm.refresh(); } - /** * Preview action. */ @@ -817,7 +924,9 @@ function togglePreview(editor) { var cm = editor.codemirror; var wrapper = cm.getWrapperElement(); var toolbar_div = wrapper.previousSibling; - var toolbar = editor.options.toolbar ? editor.toolbarElements.preview : false; + var toolbar = editor.options.toolbar + ? editor.toolbarElements.preview + : false; var preview = wrapper.lastChild; if (!preview || !/editor-preview/.test(preview.className)) { preview = document.createElement('div'); @@ -826,17 +935,21 @@ function togglePreview(editor) { } if (/editor-preview-active/.test(preview.className)) { preview.className = preview.className.replace( - /\s*editor-preview-active\s*/g, '' + /\s*editor-preview-active\s*/g, + '' ); if (toolbar) { toolbar.className = toolbar.className.replace(/\s*active\s*/g, ''); - toolbar_div.className = toolbar_div.className.replace(/\s*disabled-for-preview*/g, ''); + toolbar_div.className = toolbar_div.className.replace( + /\s*disabled-for-preview*/g, + '' + ); } } else { // When the preview button is clicked for the first time, // give some time for the transition from editor.css to fire and the view to slide from right to left, // instead of just appearing. - setTimeout(function () { + setTimeout(function() { preview.className += ' editor-preview-active'; }, 1); if (toolbar) { @@ -853,7 +966,9 @@ function togglePreview(editor) { } function _replaceSelection(cm, active, startEnd, url) { - if (/editor-preview-active/.test(cm.getWrapperElement().lastChild.className)) + if ( + /editor-preview-active/.test(cm.getWrapperElement().lastChild.className) + ) return; var text; @@ -887,15 +1002,16 @@ function _replaceSelection(cm, active, startEnd, url) { cm.focus(); } - function _toggleHeading(cm, direction, size) { - if (/editor-preview-active/.test(cm.getWrapperElement().lastChild.className)) + if ( + /editor-preview-active/.test(cm.getWrapperElement().lastChild.className) + ) return; var startPoint = cm.getCursor('start'); var endPoint = cm.getCursor('end'); for (var i = startPoint.line; i <= endPoint.line; i++) { - (function (i) { + (function(i) { var text = cm.getLine(i); var currHeadingLevel = text.search(/[^#]/); @@ -945,21 +1061,26 @@ function _toggleHeading(cm, direction, size) { } } - cm.replaceRange(text, { - line: i, - ch: 0, - }, { - line: i, - ch: 99999999999999, - }); + cm.replaceRange( + text, + { + line: i, + ch: 0, + }, + { + line: i, + ch: 99999999999999, + } + ); })(i); } cm.focus(); } - function _toggleLine(cm, name) { - if (/editor-preview-active/.test(cm.getWrapperElement().lastChild.className)) + if ( + /editor-preview-active/.test(cm.getWrapperElement().lastChild.className) + ) return; var listRegexp = /^(\s*)(\*|-|\+|\d*\.)(\s+)/; @@ -969,14 +1090,14 @@ function _toggleLine(cm, name) { var startPoint = cm.getCursor('start'); var endPoint = cm.getCursor('end'); var repl = { - 'quote': /^(\s*)>\s+/, + quote: /^(\s*)>\s+/, 'unordered-list': listRegexp, 'ordered-list': listRegexp, }; - var _getChar = function (name, i) { + var _getChar = function(name, i) { var map = { - 'quote': '>', + quote: '>', 'unordered-list': '*', 'ordered-list': '%%i.', }; @@ -984,9 +1105,9 @@ function _toggleLine(cm, name) { return map[name].replace('%%i', i); }; - var _checkChar = function (name, char) { + var _checkChar = function(name, char) { var map = { - 'quote': '>', + quote: '>', 'unordered-list': '*', 'ordered-list': 'd+.', }; @@ -997,7 +1118,7 @@ function _toggleLine(cm, name) { var line = 1; for (var i = startPoint.line; i <= endPoint.line; i++) { - (function (i) { + (function(i) { var text = cm.getLine(i); if (stat[name]) { text = text.replace(repl[name], '$1'); @@ -1008,29 +1129,43 @@ function _toggleLine(cm, name) { if (_checkChar(name, arr[2])) { char = ''; } - text = arr[1] + char + arr[3] + text.replace(whitespacesRegexp, '').replace(repl[name], '$1'); + text = + arr[1] + + char + + arr[3] + + text + .replace(whitespacesRegexp, '') + .replace(repl[name], '$1'); } else { text = char + ' ' + text; } line += 1; } - cm.replaceRange(text, { - line: i, - ch: 0, - }, { - line: i, - ch: 99999999999999, - }); + cm.replaceRange( + text, + { + line: i, + ch: 0, + }, + { + line: i, + ch: 99999999999999, + } + ); })(i); } cm.focus(); } function _toggleBlock(editor, type, start_chars, end_chars) { - if (/editor-preview-active/.test(editor.codemirror.getWrapperElement().lastChild.className)) + if ( + /editor-preview-active/.test( + editor.codemirror.getWrapperElement().lastChild.className + ) + ) return; - end_chars = (typeof end_chars === 'undefined') ? start_chars : end_chars; + end_chars = typeof end_chars === 'undefined' ? start_chars : end_chars; var cm = editor.codemirror; var stat = getState(cm); @@ -1055,13 +1190,17 @@ function _toggleBlock(editor, type, start_chars, end_chars) { start = start.replace(/(\*\*|~~)(?![\s\S]*(\*\*|~~))/, ''); end = end.replace(/(\*\*|~~)/, ''); } - cm.replaceRange(start + end, { - line: startPoint.line, - ch: 0, - }, { - line: startPoint.line, - ch: 99999999999999, - }); + cm.replaceRange( + start + end, + { + line: startPoint.line, + ch: 0, + }, + { + line: startPoint.line, + ch: 99999999999999, + } + ); if (type == 'bold' || type == 'strikethrough') { startPoint.ch -= 2; @@ -1096,7 +1235,9 @@ function _toggleBlock(editor, type, start_chars, end_chars) { } function _cleanBlock(cm) { - if (/editor-preview-active/.test(cm.getWrapperElement().lastChild.className)) + if ( + /editor-preview-active/.test(cm.getWrapperElement().lastChild.className) + ) return; var startPoint = cm.getCursor('start'); @@ -1107,13 +1248,17 @@ function _cleanBlock(cm) { text = cm.getLine(line); text = text.replace(/^[ ]*([# ]+|\*|-|[> ]+|[0-9]+(.|\)))[ ]*/, ''); - cm.replaceRange(text, { - line: line, - ch: 0, - }, { - line: line, - ch: 99999999999999, - }); + cm.replaceRange( + text, + { + line: line, + ch: 0, + }, + { + line: line, + ch: 99999999999999, + } + ); } } @@ -1122,13 +1267,18 @@ function _mergeProperties(target, source) { for (var property in source) { if (source.hasOwnProperty(property)) { if (source[property] instanceof Array) { - target[property] = source[property].concat(target[property] instanceof Array ? target[property] : []); + target[property] = source[property].concat( + target[property] instanceof Array ? target[property] : [] + ); } else if ( source[property] !== null && typeof source[property] === 'object' && source[property].constructor === Object ) { - target[property] = _mergeProperties(target[property] || {}, source[property]); + target[property] = _mergeProperties( + target[property] || {}, + source[property] + ); } else { target[property] = source[property]; } @@ -1154,7 +1304,7 @@ function wordCount(data) { var count = 0; if (m === null) return count; for (var i = 0; i < m.length; i++) { - if (m[i].charCodeAt(0) >= 0x4E00) { + if (m[i].charCodeAt(0) >= 0x4e00) { count += m[i].length; } else { count += 1; @@ -1164,27 +1314,27 @@ function wordCount(data) { } var toolbarBuiltInButtons = { - 'bold': { + bold: { name: 'bold', action: toggleBold, className: 'fa fa-bold', title: 'Bold', default: true, }, - 'italic': { + italic: { name: 'italic', action: toggleItalic, className: 'fa fa-italic', title: 'Italic', default: true, }, - 'strikethrough': { + strikethrough: { name: 'strikethrough', action: toggleStrikethrough, className: 'fa fa-strikethrough', title: 'Strikethrough', }, - 'heading': { + heading: { name: 'heading', action: toggleHeadingSmaller, className: 'fa fa-header fa-heading', @@ -1224,13 +1374,13 @@ var toolbarBuiltInButtons = { 'separator-1': { name: 'separator-1', }, - 'code': { + code: { name: 'code', action: toggleCodeBlock, className: 'fa fa-code', title: 'Code', }, - 'quote': { + quote: { name: 'quote', action: toggleBlockquote, className: 'fa fa-quote-left', @@ -1260,21 +1410,21 @@ var toolbarBuiltInButtons = { 'separator-2': { name: 'separator-2', }, - 'link': { + link: { name: 'link', action: drawLink, className: 'fa fa-link', title: 'Create Link', default: true, }, - 'image': { + image: { name: 'image', action: drawImage, className: 'fa fa-image', title: 'Insert Image', default: true, }, - 'table': { + table: { name: 'table', action: drawTable, className: 'fa fa-table', @@ -1289,7 +1439,7 @@ var toolbarBuiltInButtons = { 'separator-3': { name: 'separator-3', }, - 'preview': { + preview: { name: 'preview', action: togglePreview, className: 'fa fa-eye', @@ -1306,7 +1456,7 @@ var toolbarBuiltInButtons = { title: 'Toggle Side by Side', default: true, }, - 'fullscreen': { + fullscreen: { name: 'fullscreen', action: toggleFullScreen, className: 'fa fa-arrows-alt', @@ -1318,7 +1468,7 @@ var toolbarBuiltInButtons = { 'separator-4': { name: 'separator-4', }, - 'guide': { + guide: { name: 'guide', action: 'https://www.markdownguide.org/basic-syntax/', className: 'fa fa-question-circle', @@ -1329,14 +1479,14 @@ var toolbarBuiltInButtons = { 'separator-5': { name: 'separator-5', }, - 'undo': { + undo: { name: 'undo', action: undo, className: 'fa fa-undo', noDisable: true, title: 'Undo', }, - 'redo': { + redo: { name: 'redo', action: redo, className: 'fa fa-repeat fa-redo', @@ -1348,7 +1498,10 @@ var toolbarBuiltInButtons = { var insertTexts = { link: ['[', '](#url#)'], image: ['![](', '#url#)'], - table: ['', '\n\n| Column 1 | Column 2 | Column 3 |\n| -------- | -------- | -------- |\n| Text | Text | Text |\n\n'], + table: [ + '', + '\n\n| Column 1 | Column 2 | Column 3 |\n| -------- | -------- | -------- |\n| Text | Text | Text |\n\n', + ], horizontalRule: ['', '\n\n-----\n\n'], }; @@ -1358,9 +1511,9 @@ var promptTexts = { }; var blockStyles = { - 'bold': '**', - 'code': '```', - 'italic': '*', + bold: '**', + code: '```', + italic: '*', }; /** @@ -1383,10 +1536,13 @@ function EasyMDE(options) { 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) continue; - if (styleSheets[i].href.indexOf('//maxcdn.bootstrapcdn.com/font-awesome/') > -1) { + if ( + styleSheets[i].href.indexOf( + '//maxcdn.bootstrapcdn.com/font-awesome/' + ) > -1 + ) { autoDownloadFA = false; } } @@ -1395,11 +1551,11 @@ function EasyMDE(options) { if (autoDownloadFA) { var link = document.createElement('link'); link.rel = 'stylesheet'; - link.href = 'https://maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css'; + 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; @@ -1409,13 +1565,11 @@ function EasyMDE(options) { return; } - // Handle toolbar if (options.toolbar === undefined) { // Initialize options.toolbar = []; - // Loop over the built in buttons, to get the preferred order for (var key in toolbarBuiltInButtons) { if (toolbarBuiltInButtons.hasOwnProperty(key)) { @@ -1423,70 +1577,75 @@ function EasyMDE(options) { options.toolbar.push('|'); } - if (toolbarBuiltInButtons[key].default === true || (options.showIcons && options.showIcons.constructor === Array && options.showIcons.indexOf(key) != -1)) { + if ( + toolbarBuiltInButtons[key].default === true || + (options.showIcons && + options.showIcons.constructor === Array && + options.showIcons.indexOf(key) != -1) + ) { options.toolbar.push(key); } } } } - // Handle status bar if (!options.hasOwnProperty('status')) { options.status = ['autosave', 'lines', 'words', 'cursor']; } - // Add default preview rendering function if (!options.previewRender) { - options.previewRender = function (plainText) { + options.previewRender = function(plainText) { // Note: "this" refers to the options object return this.parent.markdown(plainText); }; } - // Set default options for parsing config - options.parsingConfig = extend({ - highlightFormatting: true, // needed for toggleCodeBlock to detect types of code - }, options.parsingConfig || {}); - + options.parsingConfig = extend( + { + highlightFormatting: true, // needed for toggleCodeBlock to detect types of code + }, + options.parsingConfig || {} + ); // Merging the insertTexts, with the given options options.insertTexts = extend({}, insertTexts, options.insertTexts || {}); - // Merging the promptTexts, with the given options options.promptTexts = extend({}, promptTexts, options.promptTexts || {}); - // Merging the blockStyles, with the given options options.blockStyles = extend({}, blockStyles, options.blockStyles || {}); - // Merging the shortcuts, with the given options options.shortcuts = extend({}, shortcuts, options.shortcuts || {}); options.minHeight = options.minHeight || '300px'; - // Change unique_id to uniqueId for backwards compatibility - if (options.autosave != undefined && options.autosave.unique_id != undefined && options.autosave.unique_id != '') + if ( + options.autosave != undefined && + options.autosave.unique_id != undefined && + options.autosave.unique_id != '' + ) options.autosave.uniqueId = options.autosave.unique_id; - // 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 - if (options.initialValue && (!this.options.autosave || this.options.autosave.foundSavedValue !== true)) { + if ( + options.initialValue && + (!this.options.autosave || + this.options.autosave.foundSavedValue !== true) + ) { this.value(options.initialValue); } } @@ -1494,31 +1653,42 @@ function EasyMDE(options) { /** * Default markdown render. */ -EasyMDE.prototype.markdown = function (text) { +EasyMDE.prototype.markdown = function(text) { if (marked) { // Initialize var markedOptions; - if (this.options && this.options.renderingConfig && this.options.renderingConfig.markedOptions) { + if ( + this.options && + this.options.renderingConfig && + this.options.renderingConfig.markedOptions + ) { markedOptions = this.options.renderingConfig.markedOptions; } else { markedOptions = {}; } // Update options - if (this.options && this.options.renderingConfig && this.options.renderingConfig.singleLineBreaks === false) { + if ( + this.options && + this.options.renderingConfig && + this.options.renderingConfig.singleLineBreaks === false + ) { markedOptions.breaks = false; } else { markedOptions.breaks = true; } - if (this.options && this.options.renderingConfig && this.options.renderingConfig.codeSyntaxHighlighting === true) { - + if ( + this.options && + this.options.renderingConfig && + this.options.renderingConfig.codeSyntaxHighlighting === true + ) { /* Get HLJS from config or window */ var hljs = this.options.renderingConfig.hljs || window.hljs; /* Check if HLJS loaded */ if (hljs) { - markedOptions.highlight = function (code) { + markedOptions.highlight = function(code) { return hljs.highlightAuto(code).value; }; } @@ -1540,7 +1710,7 @@ EasyMDE.prototype.markdown = function (text) { /** * Render editor to the given element. */ -EasyMDE.prototype.render = function (el) { +EasyMDE.prototype.render = function(el) { if (!el) { el = this.element || document.getElementsByTagName('textarea')[0]; } @@ -1559,8 +1729,8 @@ EasyMDE.prototype.render = function (el) { for (var key in options.shortcuts) { // null stands for "do not bind this command" if (options.shortcuts[key] !== null && bindings[key] !== null) { - (function (key) { - keyMaps[fixShortcut(options.shortcuts[key])] = function () { + (function(key) { + keyMaps[fixShortcut(options.shortcuts[key])] = function() { var action = bindings[key]; if (typeof action === 'function') { action(self); @@ -1575,17 +1745,22 @@ EasyMDE.prototype.render = function (el) { keyMaps['Enter'] = 'newlineAndIndentContinueMarkdownList'; keyMaps['Tab'] = 'tabAndIndentMarkdownList'; keyMaps['Shift-Tab'] = 'shiftTabAndUnindentMarkdownList'; - keyMaps['Esc'] = function (cm) { + keyMaps['Esc'] = function(cm) { if (cm.getOption('fullScreen')) toggleFullScreen(self); }; - document.addEventListener('keydown', function (e) { - e = e || window.event; + document.addEventListener( + 'keydown', + function(e) { + e = e || window.event; - if (e.keyCode == 27) { - if (self.codemirror.getOption('fullScreen')) toggleFullScreen(self); - } - }, false); + if (e.keyCode == 27) { + if (self.codemirror.getOption('fullScreen')) + toggleFullScreen(self); + } + }, + false + ); var mode, backdrop; if (options.spellChecker !== false) { @@ -1613,17 +1788,21 @@ EasyMDE.prototype.render = function (el) { this.codemirror = CodeMirror.fromTextArea(el, { mode: mode, backdrop: backdrop, - theme: (options.theme != undefined) ? options.theme : 'easymde', - tabSize: (options.tabSize != undefined) ? options.tabSize : 2, - indentUnit: (options.tabSize != undefined) ? options.tabSize : 2, - indentWithTabs: (options.indentWithTabs === false) ? false : true, + theme: options.theme != undefined ? options.theme : 'easymde', + tabSize: options.tabSize != undefined ? options.tabSize : 2, + indentUnit: options.tabSize != undefined ? options.tabSize : 2, + indentWithTabs: options.indentWithTabs === false ? false : true, lineNumbers: false, - autofocus: (options.autofocus === true) ? true : false, + autofocus: options.autofocus === true ? true : false, extraKeys: keyMaps, - lineWrapping: (options.lineWrapping === false) ? false : true, + lineWrapping: options.lineWrapping === false ? false : true, allowDropFileTypes: ['text/plain'], - placeholder: options.placeholder || el.getAttribute('placeholder') || '', - styleSelectedText: (options.styleSelectedText != undefined) ? options.styleSelectedText : !isMobile(), + placeholder: + options.placeholder || el.getAttribute('placeholder') || '', + styleSelectedText: + options.styleSelectedText != undefined + ? options.styleSelectedText + : !isMobile(), configureMouse: configureMouse, }); @@ -1631,7 +1810,7 @@ EasyMDE.prototype.render = function (el) { if (options.forceSync === true) { var cm = this.codemirror; - cm.on('change', function () { + cm.on('change', function() { cm.save(); }); } @@ -1652,12 +1831,14 @@ EasyMDE.prototype.render = function (el) { this._rendered = this.element; - // Fixes CodeMirror bug (#344) var temp_cm = this.codemirror; - setTimeout(function () { - temp_cm.refresh(); - }.bind(temp_cm), 0); + setTimeout( + function() { + temp_cm.refresh(); + }.bind(temp_cm), + 0 + ); }; // Safari, in Private Browsing Mode, looks like it supports localStorage but all calls to setItem throw QuotaExceededError. We're going to detect this and set a variable accordingly. @@ -1676,43 +1857,67 @@ function isLocalStorageAvailable() { return true; } -EasyMDE.prototype.autosave = function () { +EasyMDE.prototype.autosave = function() { if (isLocalStorageAvailable()) { var easyMDE = this; - if (this.options.autosave.uniqueId == undefined || this.options.autosave.uniqueId == '') { - console.log('EasyMDE: You must set a uniqueId to use the autosave feature'); + if ( + this.options.autosave.uniqueId == undefined || + this.options.autosave.uniqueId == '' + ) { + console.log( + 'EasyMDE: You must set a uniqueId to use the autosave feature' + ); return; } - - if(this.options.autosave.binded !== true) { - if (easyMDE.element.form != null && easyMDE.element.form != undefined) { - easyMDE.element.form.addEventListener('submit', function () { - clearTimeout(easyMDE.autosaveTimeoutId); - easyMDE.autosaveTimeoutId = undefined; - - localStorage.removeItem('smde_' + easyMDE.options.autosave.uniqueId); - - // Restart autosaving in case the submit will be cancelled down the line - setTimeout(function() { - easyMDE.autosave(); - }, easyMDE.options.autosave.delay || 10000); - }); - } - - this.options.autosave.binded = true; + + if (this.options.autosave.binded !== true) { + if ( + easyMDE.element.form != null && + easyMDE.element.form != undefined + ) { + easyMDE.element.form.addEventListener('submit', function() { + clearTimeout(easyMDE.autosaveTimeoutId); + easyMDE.autosaveTimeoutId = undefined; + + localStorage.removeItem( + 'smde_' + easyMDE.options.autosave.uniqueId + ); + + // Restart autosaving in case the submit will be cancelled down the line + setTimeout(function() { + easyMDE.autosave(); + }, easyMDE.options.autosave.delay || 10000); + }); + } + + this.options.autosave.binded = true; } if (this.options.autosave.loaded !== true) { - if (typeof localStorage.getItem('smde_' + this.options.autosave.uniqueId) == 'string' && localStorage.getItem('smde_' + this.options.autosave.uniqueId) != '') { - this.codemirror.setValue(localStorage.getItem('smde_' + this.options.autosave.uniqueId)); + if ( + typeof localStorage.getItem( + 'smde_' + this.options.autosave.uniqueId + ) == 'string' && + localStorage.getItem( + 'smde_' + this.options.autosave.uniqueId + ) != '' + ) { + this.codemirror.setValue( + localStorage.getItem( + 'smde_' + this.options.autosave.uniqueId + ) + ); this.options.autosave.foundSavedValue = true; } this.options.autosave.loaded = true; } - localStorage.setItem('smde_' + this.options.autosave.uniqueId, easyMDE.value()); + localStorage.setItem( + 'smde_' + this.options.autosave.uniqueId, + easyMDE.value() + ); var el = document.getElementById('autosaved'); if (el != null && el != undefined && el != '') { @@ -1733,7 +1938,7 @@ EasyMDE.prototype.autosave = function () { el.innerHTML = 'Autosaved: ' + h + ':' + m + ' ' + dd; } - this.autosaveTimeoutId = setTimeout(function () { + this.autosaveTimeoutId = setTimeout(function() { easyMDE.autosave(); }, this.options.autosave.delay || 10000); } else { @@ -1741,10 +1946,16 @@ EasyMDE.prototype.autosave = function () { } }; -EasyMDE.prototype.clearAutosavedValue = function () { +EasyMDE.prototype.clearAutosavedValue = function() { if (isLocalStorageAvailable()) { - if (this.options.autosave == undefined || this.options.autosave.uniqueId == undefined || this.options.autosave.uniqueId == '') { - console.log('EasyMDE: You must set a uniqueId to clear the autosave value'); + if ( + this.options.autosave == undefined || + this.options.autosave.uniqueId == undefined || + this.options.autosave.uniqueId == '' + ) { + console.log( + 'EasyMDE: You must set a uniqueId to clear the autosave value' + ); return; } @@ -1754,7 +1965,7 @@ EasyMDE.prototype.clearAutosavedValue = function () { } }; -EasyMDE.prototype.createSideBySide = function () { +EasyMDE.prototype.createSideBySide = function() { var cm = this.codemirror; var wrapper = cm.getWrapperElement(); var preview = wrapper.nextSibling; @@ -1769,7 +1980,7 @@ EasyMDE.prototype.createSideBySide = function () { // Syncs scroll editor -> preview var cScroll = false; var pScroll = false; - cm.on('scroll', function (v) { + cm.on('scroll', function(v) { if (cScroll) { cScroll = false; return; @@ -1782,7 +1993,7 @@ EasyMDE.prototype.createSideBySide = function () { }); // Syncs scroll preview -> editor - preview.onscroll = function () { + preview.onscroll = function() { if (pScroll) { pScroll = false; return; @@ -1790,13 +2001,15 @@ EasyMDE.prototype.createSideBySide = function () { cScroll = true; var height = preview.scrollHeight - preview.clientHeight; var ratio = parseFloat(preview.scrollTop) / height; - var move = (cm.getScrollInfo().height - cm.getScrollInfo().clientHeight) * ratio; + var move = + (cm.getScrollInfo().height - cm.getScrollInfo().clientHeight) * + ratio; cm.scrollTo(0, move); }; return preview; }; -EasyMDE.prototype.createToolbar = function (items) { +EasyMDE.prototype.createToolbar = function(items) { items = items || this.options.toolbar; if (!items || items.length === 0) { @@ -1821,48 +2034,60 @@ EasyMDE.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) + if ( + self.options.hideIcons && + self.options.hideIcons.indexOf(items[i].name) != -1 + ) continue; // Fullscreen does not work well on mobile devices (even tablets) // In the future, hopefully this can be resolved - if ((items[i].name == 'fullscreen' || items[i].name == 'side-by-side') && isMobile()) + if ( + (items[i].name == 'fullscreen' || + items[i].name == 'side-by-side') && + isMobile() + ) continue; - // Don't include trailing separators if (items[i] === '|') { var nonSeparatorIconsFollow = false; - for (var x = (i + 1); x < items.length; x++) { - if (items[x] !== '|' && (!self.options.hideIcons || self.options.hideIcons.indexOf(items[x].name) == -1)) { + for (var x = i + 1; x < items.length; x++) { + if ( + items[x] !== '|' && + (!self.options.hideIcons || + self.options.hideIcons.indexOf(items[x].name) == -1) + ) { nonSeparatorIconsFollow = true; } } - if (!nonSeparatorIconsFollow) - continue; + if (!nonSeparatorIconsFollow) continue; } - // Create the icon and append to the toolbar - (function (item) { + (function(item) { var el; if (item === '|') { el = createSep(); } else { - el = createToolbarButton(item, self.options.toolbarTips, self.options.shortcuts); + el = createToolbarButton( + item, + self.options.toolbarTips, + self.options.shortcuts + ); } // bind events, special for info if (item.action) { if (typeof item.action === 'function') { - el.onclick = function (e) { + el.onclick = function(e) { e.preventDefault(); item.action(self); }; } else if (typeof item.action === 'string') { - el.onclick = function (e) { + el.onclick = function(e) { e.preventDefault(); window.open(item.action, '_blank'); }; @@ -1877,11 +2102,11 @@ EasyMDE.prototype.createToolbar = function (items) { self.toolbarElements = toolbarData; var cm = this.codemirror; - cm.on('cursorActivity', function () { + cm.on('cursorActivity', function() { var stat = getState(cm); for (var key in toolbarData) { - (function (key) { + (function(key) { var el = toolbarData[key]; if (stat[key]) { el.className += ' active'; @@ -1897,17 +2122,14 @@ EasyMDE.prototype.createToolbar = function (items) { return bar; }; -EasyMDE.prototype.createStatusbar = function (status) { +EasyMDE.prototype.createStatusbar = function(status) { // Initialize status = status || this.options.status; var options = this.options; var cm = this.codemirror; - // Make sure the status variable is valid - if (!status || status.length === 0) - return; - + if (!status || status.length === 0) return; // Set up the built-in items var items = []; @@ -1918,7 +2140,6 @@ EasyMDE.prototype.createStatusbar = function (status) { onUpdate = undefined; defaultValue = undefined; - // Handle if custom or not if (typeof status[i] === 'object') { items.push({ @@ -1930,30 +2151,33 @@ EasyMDE.prototype.createStatusbar = function (status) { var name = status[i]; if (name === 'words') { - defaultValue = function (el) { + defaultValue = function(el) { el.innerHTML = wordCount(cm.getValue()); }; - onUpdate = function (el) { + onUpdate = function(el) { el.innerHTML = wordCount(cm.getValue()); }; } else if (name === 'lines') { - defaultValue = function (el) { + defaultValue = function(el) { el.innerHTML = cm.lineCount(); }; - onUpdate = function (el) { + onUpdate = function(el) { el.innerHTML = cm.lineCount(); }; } else if (name === 'cursor') { - defaultValue = function (el) { + defaultValue = function(el) { el.innerHTML = '0:0'; }; - onUpdate = function (el) { + onUpdate = function(el) { var pos = cm.getCursor(); el.innerHTML = pos.line + ':' + pos.ch; }; } else if (name === 'autosave') { - defaultValue = function (el) { - if (options.autosave != undefined && options.autosave.enabled === true) { + defaultValue = function(el) { + if ( + options.autosave != undefined && + options.autosave.enabled === true + ) { el.setAttribute('id', 'autosaved'); } }; @@ -1967,45 +2191,41 @@ EasyMDE.prototype.createStatusbar = function (status) { } } - // Create element for the status bar var bar = document.createElement('div'); bar.className = 'editor-statusbar'; - // Create a new span for each item for (i = 0; i < items.length; i++) { // Store in temporary variable var item = items[i]; - // Create span element var el = document.createElement('span'); el.className = item.className; - // Ensure the defaultValue is a function if (typeof item.defaultValue === 'function') { item.defaultValue(el); } - // Ensure the onUpdate is a function if (typeof item.onUpdate === 'function') { // Create a closure around the span of the current action, then execute the onUpdate handler - this.codemirror.on('update', (function (el, item) { - return function () { - item.onUpdate(el); - }; - }(el, item))); + this.codemirror.on( + 'update', + (function(el, item) { + return function() { + item.onUpdate(el); + }; + })(el, item) + ); } - // Append the item to the status bar bar.appendChild(el); } - // Insert the status bar into the DOM var cmWrapper = this.codemirror.getWrapperElement(); cmWrapper.parentNode.insertBefore(bar, cmWrapper.nextSibling); @@ -2015,7 +2235,7 @@ EasyMDE.prototype.createStatusbar = function (status) { /** * Get or set the text content. */ -EasyMDE.prototype.value = function (val) { +EasyMDE.prototype.value = function(val) { var cm = this.codemirror; if (val === undefined) { return cm.getValue(); @@ -2030,7 +2250,6 @@ EasyMDE.prototype.value = function (val) { } }; - /** * Bind static methods for exports. */ @@ -2060,74 +2279,74 @@ EasyMDE.toggleFullScreen = toggleFullScreen; /** * Bind instance methods for exports. */ -EasyMDE.prototype.toggleBold = function () { +EasyMDE.prototype.toggleBold = function() { toggleBold(this); }; -EasyMDE.prototype.toggleItalic = function () { +EasyMDE.prototype.toggleItalic = function() { toggleItalic(this); }; -EasyMDE.prototype.toggleStrikethrough = function () { +EasyMDE.prototype.toggleStrikethrough = function() { toggleStrikethrough(this); }; -EasyMDE.prototype.toggleBlockquote = function () { +EasyMDE.prototype.toggleBlockquote = function() { toggleBlockquote(this); }; -EasyMDE.prototype.toggleHeadingSmaller = function () { +EasyMDE.prototype.toggleHeadingSmaller = function() { toggleHeadingSmaller(this); }; -EasyMDE.prototype.toggleHeadingBigger = function () { +EasyMDE.prototype.toggleHeadingBigger = function() { toggleHeadingBigger(this); }; -EasyMDE.prototype.toggleHeading1 = function () { +EasyMDE.prototype.toggleHeading1 = function() { toggleHeading1(this); }; -EasyMDE.prototype.toggleHeading2 = function () { +EasyMDE.prototype.toggleHeading2 = function() { toggleHeading2(this); }; -EasyMDE.prototype.toggleHeading3 = function () { +EasyMDE.prototype.toggleHeading3 = function() { toggleHeading3(this); }; -EasyMDE.prototype.toggleCodeBlock = function () { +EasyMDE.prototype.toggleCodeBlock = function() { toggleCodeBlock(this); }; -EasyMDE.prototype.toggleUnorderedList = function () { +EasyMDE.prototype.toggleUnorderedList = function() { toggleUnorderedList(this); }; -EasyMDE.prototype.toggleOrderedList = function () { +EasyMDE.prototype.toggleOrderedList = function() { toggleOrderedList(this); }; -EasyMDE.prototype.cleanBlock = function () { +EasyMDE.prototype.cleanBlock = function() { cleanBlock(this); }; -EasyMDE.prototype.drawLink = function () { +EasyMDE.prototype.drawLink = function() { drawLink(this); }; -EasyMDE.prototype.drawImage = function () { +EasyMDE.prototype.drawImage = function() { drawImage(this); }; -EasyMDE.prototype.drawTable = function () { +EasyMDE.prototype.drawTable = function() { drawTable(this); }; -EasyMDE.prototype.drawHorizontalRule = function () { +EasyMDE.prototype.drawHorizontalRule = function() { drawHorizontalRule(this); }; -EasyMDE.prototype.undo = function () { +EasyMDE.prototype.undo = function() { undo(this); }; -EasyMDE.prototype.redo = function () { +EasyMDE.prototype.redo = function() { redo(this); }; -EasyMDE.prototype.togglePreview = function () { +EasyMDE.prototype.togglePreview = function() { togglePreview(this); }; -EasyMDE.prototype.toggleSideBySide = function () { +EasyMDE.prototype.toggleSideBySide = function() { toggleSideBySide(this); }; -EasyMDE.prototype.toggleFullScreen = function () { +EasyMDE.prototype.toggleFullScreen = function() { toggleFullScreen(this); }; -EasyMDE.prototype.isPreviewActive = function () { +EasyMDE.prototype.isPreviewActive = function() { var cm = this.codemirror; var wrapper = cm.getWrapperElement(); var preview = wrapper.lastChild; @@ -2135,8 +2354,7 @@ EasyMDE.prototype.isPreviewActive = function () { return /editor-preview-active/.test(preview.className); }; - -EasyMDE.prototype.isSideBySideActive = function () { +EasyMDE.prototype.isSideBySideActive = function() { var cm = this.codemirror; var wrapper = cm.getWrapperElement(); var preview = wrapper.nextSibling; @@ -2144,19 +2362,19 @@ EasyMDE.prototype.isSideBySideActive = function () { return /editor-preview-active-side/.test(preview.className); }; -EasyMDE.prototype.isFullscreenActive = function () { +EasyMDE.prototype.isFullscreenActive = function() { var cm = this.codemirror; return cm.getOption('fullScreen'); }; -EasyMDE.prototype.getState = function () { +EasyMDE.prototype.getState = function() { var cm = this.codemirror; return getState(cm); }; -EasyMDE.prototype.toTextArea = function () { +EasyMDE.prototype.toTextArea = function() { var cm = this.codemirror; var wrapper = cm.getWrapperElement(); From f861b998fee97f9b618055ebc08379110ac4dceb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedikt=20R=C3=B6tsch?= Date: Thu, 18 Apr 2019 20:26:55 +0700 Subject: [PATCH 2/2] apply eslint aswell --- package.json | 2 +- src/js/easymde.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 3fdaff15..3ba229c1 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "scripts": { "prepare": "gulp", "test:types": "tsc --project types/tsconfig.json", - "format": "prettier --write 'src/**/*'" + "format": "prettier --write 'src/**/*' && eslint --fix" }, "prettier": { "trailingComma": "es5", diff --git a/src/js/easymde.js b/src/js/easymde.js index 9f838317..105096ac 100644 --- a/src/js/easymde.js +++ b/src/js/easymde.js @@ -52,7 +52,7 @@ var shortcuts = { toggleHeadingBigger: 'Shift-Cmd-H', cleanBlock: 'Cmd-E', drawImage: 'Cmd-Alt-I', - toggleBlockquote: "Cmd-'", + toggleBlockquote: 'Cmd-\'', toggleOrderedList: 'Cmd-Alt-L', toggleUnorderedList: 'Cmd-L', toggleCodeBlock: 'Cmd-Alt-C', @@ -335,7 +335,7 @@ function toggleCodeBlock(editor) { function fencing_line(line) { /* return true, if this is a ``` or ~~~ line */ if (typeof line !== 'object') { - throw "fencing_line() takes a 'line' object (not a line number, or line text). Got: " + + throw 'fencing_line() takes a \'line\' object (not a line number, or line text). Got: ' + typeof line + ': ' + line;