From a12ba4790a475f9705d4bfde9cef9040c562ffa7 Mon Sep 17 00:00:00 2001 From: kolaente Date: Sat, 14 Mar 2020 22:18:23 +0100 Subject: [PATCH 1/7] Add support for custom icon markup --- src/js/easymde.js | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/src/js/easymde.js b/src/js/easymde.js index 761f604..dfcda5c 100644 --- a/src/js/easymde.js +++ b/src/js/easymde.js @@ -167,29 +167,35 @@ function createToolbarButton(options, enableActions, enableTooltips, shortcuts, el.classList.add('no-mobile'); } - // 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++) { - 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". - if (classNamePart.match(/^fa([srlb]|(-[\w-]*)|$)/)) { - iconClasses.push(classNamePart); - } else { - el.classList.add(classNamePart); + // If there is a custom icon, use that + if (typeof options.icon !== 'undefined') { + el.innerHTML = options.icon; + } else { + // 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++) { + 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". + if (classNamePart.match(/^fa([srlb]|(-[\w-]*)|$)/)) { + iconClasses.push(classNamePart); + } else { + el.classList.add(classNamePart); + } } - } - el.tabIndex = -1; + el.tabIndex = -1; - // Create icon element and append as a child to the button - var icon = document.createElement('i'); - for (var iconClassIndex = 0; iconClassIndex < iconClasses.length; iconClassIndex++) { - var iconClass = iconClasses[iconClassIndex]; - icon.classList.add(iconClass); + // Create icon element and append as a child to the button + var icon = document.createElement('i'); + for (var iconClassIndex = 0; iconClassIndex < iconClasses.length; iconClassIndex++) { + var iconClass = iconClasses[iconClassIndex]; + icon.classList.add(iconClass); + } + el.appendChild(icon); } - el.appendChild(icon); if (options.action && enableActions) { if (typeof options.action === 'function') { From 9a20111767336135433793d3affdba45edeaf95d Mon Sep 17 00:00:00 2001 From: kolaente Date: Sat, 14 Mar 2020 22:26:42 +0100 Subject: [PATCH 2/7] Remove unused empty line --- src/js/easymde.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/js/easymde.js b/src/js/easymde.js index dfcda5c..3ecb3cd 100644 --- a/src/js/easymde.js +++ b/src/js/easymde.js @@ -172,7 +172,6 @@ function createToolbarButton(options, enableActions, enableTooltips, shortcuts, el.innerHTML = options.icon; } else { // 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++) { From 693db8bf17931bcf4d059463db2c8eef05b2ccb2 Mon Sep 17 00:00:00 2001 From: A-312 Date: Sat, 21 Mar 2020 11:46:25 +0100 Subject: [PATCH 3/7] Updated codemirror to version 5.52.2 (fix:#160) --- CHANGELOG.md | 1 + package.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3855035..f79d6cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add `watch` task for gulp (Thanks to [@A-312], [#150]. ### Fixed - Issue with Marked when using IE11 and webpack (Thanks to [@felipefdl], [#169]). +- Updated codemirror to version 5.52.2 ([#174]). ## [2.9.0] - 2020-01-13 ### Added diff --git a/package.json b/package.json index 1bea8dd..e0832c4 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "license": "MIT", "author": "Jeroen Akkerman", "dependencies": { - "codemirror": "^5.51.0", + "codemirror": "^5.52.2", "codemirror-spell-checker": "1.1.2", "marked": "^0.8.0" }, From 753bed4772d492006a6a65503b8b5f7f5662fe94 Mon Sep 17 00:00:00 2001 From: A-312 Date: Sat, 21 Mar 2020 12:08:59 +0100 Subject: [PATCH 4/7] Update package-lock.json --- package-lock.json | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index 737ce69..3f0c4f0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,14 +13,20 @@ "@babel/highlight": "^7.8.3" } }, + "@babel/helper-validator-identifier": { + "version": "7.9.0", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.9.0.tgz", + "integrity": "sha512-6G8bQKjOh+of4PV/ThDm/rRqlU7+IGoJuofpagU5GlEl29Vv0RGqqt86ZGRV8ZuSOY3o+8yXl5y782SMcG7SHw==", + "dev": true + }, "@babel/highlight": { - "version": "7.8.3", - "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.8.3.tgz", - "integrity": "sha512-PX4y5xQUvy0fnEVHrYOarRPXVWafSjTW9T0Hab8gVIawpl2Sj0ORyrygANq+KjcNlSSTw0YCLSNA8OyZ1I4yEg==", + "version": "7.9.0", + "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.9.0.tgz", + "integrity": "sha512-lJZPilxX7Op3Nv/2cvFdnlepPXDxi29wxteT57Q965oc5R9v86ztx0jfxVrTcBk8C2kcPkkDa2Z4T3ZsPPVWsQ==", "dev": true, "requires": { + "@babel/helper-validator-identifier": "^7.9.0", "chalk": "^2.0.0", - "esutils": "^2.0.2", "js-tokens": "^4.0.0" } }, @@ -40,9 +46,9 @@ "dev": true }, "@types/estree": { - "version": "0.0.43", - "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.43.tgz", - "integrity": "sha512-WfOySUnBpyKXbkC9QuZguwOGhGnugDXT2f2P6X8EIis7qlnd5NI1Nr4kRi357NtguxezyizIcaFlQe0wx23XnA==", + "version": "0.0.44", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.44.tgz", + "integrity": "sha512-iaIVzr+w2ZJ5HkidlZ3EJM8VTZb2MJLCjw3V+505yVts0gRC4UMvjw0d1HPtGqI/HQC/KdsYtayfzl+AXY2R8g==", "dev": true }, "@types/marked": { From 03ba544095f161c35435afa9af5fe9aca1fd24f2 Mon Sep 17 00:00:00 2001 From: A-312 Date: Sat, 21 Mar 2020 13:06:27 +0100 Subject: [PATCH 5/7] Update CHANGELOG.md (Add Thanks) Co-Authored-By: Situphen --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f79d6cb..4a8dd94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add `watch` task for gulp (Thanks to [@A-312], [#150]. ### Fixed - Issue with Marked when using IE11 and webpack (Thanks to [@felipefdl], [#169]). -- Updated codemirror to version 5.52.2 ([#174]). +- Updated codemirror to version 5.52.2 (Thanks to [@A-312], [#173]). ## [2.9.0] - 2020-01-13 ### Added From cc0706bfc2722875c4375df2524b07c001c7f5b8 Mon Sep 17 00:00:00 2001 From: kolaente Date: Mon, 23 Mar 2020 18:07:52 +0100 Subject: [PATCH 6/7] Also still add custom classes when using custom icon markup --- src/js/easymde.js | 56 ++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/src/js/easymde.js b/src/js/easymde.js index 3b17d15..6c8200b 100644 --- a/src/js/easymde.js +++ b/src/js/easymde.js @@ -167,33 +167,39 @@ function createToolbarButton(options, enableActions, enableTooltips, shortcuts, el.classList.add('no-mobile'); } - // If there is a custom icon, use that + // Prevent errors if there is no class name in custom options + var className = ''; + if(typeof options.className !== 'undefined') { + className = options.className; + } + + // Provide backwards compatibility with simple-markdown-editor by adding custom classes to the button. + var classNameParts = className.split(' '); + var iconClasses = []; + 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". + if (classNamePart.match(/^fa([srlb]|(-[\w-]*)|$)/)) { + iconClasses.push(classNamePart); + } else { + el.classList.add(classNamePart); + } + } + + el.tabIndex = -1; + + // Create icon element and append as a child to the button + var icon = document.createElement('i'); + for (var iconClassIndex = 0; iconClassIndex < iconClasses.length; iconClassIndex++) { + var iconClass = iconClasses[iconClassIndex]; + icon.classList.add(iconClass); + } + el.appendChild(icon); + + // If there is a custom icon markup set, use that if (typeof options.icon !== 'undefined') { el.innerHTML = options.icon; - } else { - // 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++) { - 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". - if (classNamePart.match(/^fa([srlb]|(-[\w-]*)|$)/)) { - iconClasses.push(classNamePart); - } else { - el.classList.add(classNamePart); - } - } - - el.tabIndex = -1; - - // Create icon element and append as a child to the button - var icon = document.createElement('i'); - for (var iconClassIndex = 0; iconClassIndex < iconClasses.length; iconClassIndex++) { - var iconClass = iconClasses[iconClassIndex]; - icon.classList.add(iconClass); - } - el.appendChild(icon); } if (options.action && enableActions) { From de1f32bd1fae2cdd7797ba291d70e6d2a02d5213 Mon Sep 17 00:00:00 2001 From: kolaente Date: Mon, 23 Mar 2020 18:18:04 +0100 Subject: [PATCH 7/7] Fix icon class handling if no custom icon classes are provided --- src/js/easymde.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/js/easymde.js b/src/js/easymde.js index 6c8200b..d64a52f 100644 --- a/src/js/easymde.js +++ b/src/js/easymde.js @@ -168,13 +168,12 @@ function createToolbarButton(options, enableActions, enableTooltips, shortcuts, } // Prevent errors if there is no class name in custom options - var className = ''; + var classNameParts = []; if(typeof options.className !== 'undefined') { - className = options.className; + classNameParts = options.className.split(' '); } // Provide backwards compatibility with simple-markdown-editor by adding custom classes to the button. - var classNameParts = className.split(' '); var iconClasses = []; for (var classNameIndex = 0; classNameIndex < classNameParts.length; classNameIndex++) { var classNamePart = classNameParts[classNameIndex];