From 5df842b63051041669ec537b44a1295454ad6678 Mon Sep 17 00:00:00 2001 From: Zignature Date: Tue, 11 Jan 2022 15:45:36 +0100 Subject: [PATCH 1/4] Fix for issue #386 Show '-' instead of '*' for unordered list Added unorderedListStyle to the options --- README.md | 2 ++ src/js/easymde.js | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2a13104..6718436 100644 --- a/README.md +++ b/README.md @@ -136,6 +136,7 @@ easyMDE.value('New input for **EasyMDE**'); - **bold**: Can be set to `**` or `__`. Defaults to `**`. - **code**: Can be set to ```` ``` ```` or `~~~`. Defaults to ```` ``` ````. - **italic**: Can be set to `*` or `_`. Defaults to `*`. +- **unorderedListStyle**: can be `*`, `-` or `+`. Defaults to `*`. - **scrollbarStyle**: Chooses a scrollbar implementation. The default is "native", showing native scrollbars. The core library also provides the "null" style, which completely hides the scrollbars. Addons can implement additional scrollbar models. - **element**: The DOM element for the TextArea to use. Defaults to the first TextArea on the page. - **forceSync**: If set to `true`, force text changes made in EasyMDE to be immediately stored in original text area. Defaults to `false`. @@ -242,6 +243,7 @@ const editor = new EasyMDE({ bold: "__", italic: "_", }, + unorderedListStyle: "-", element: document.getElementById("MyID"), forceSync: true, hideIcons: ["guide", "heading"], diff --git a/src/js/easymde.js b/src/js/easymde.js index 3ee79e1..d729570 100644 --- a/src/js/easymde.js +++ b/src/js/easymde.js @@ -793,7 +793,17 @@ function toggleHeading3(editor) { */ function toggleUnorderedList(editor) { var cm = editor.codemirror; - _toggleLine(cm, 'unordered-list'); + var liststyle = editor.options.unorderedListStyle; + + liststyle = ( + liststyle != undefined + && liststyle !== '' + && liststyle.length == 1 + ) + ? liststyle + : '*'; + + _toggleLine(cm, 'unordered-list', liststyle); } @@ -1171,7 +1181,7 @@ function _toggleHeading(cm, direction, size) { } -function _toggleLine(cm, name) { +function _toggleLine(cm, name, liststyle) { if (/editor-preview-active/.test(cm.getWrapperElement().lastChild.className)) return; @@ -1190,7 +1200,7 @@ function _toggleLine(cm, name) { var _getChar = function (name, i) { var map = { 'quote': '>', - 'unordered-list': '*', + 'unordered-list': liststyle, 'ordered-list': '%%i.', }; @@ -1200,7 +1210,7 @@ function _toggleLine(cm, name) { var _checkChar = function (name, char) { var map = { 'quote': '>', - 'unordered-list': '\\*', + 'unordered-list': '\\'.liststyle, 'ordered-list': '\\d+.', }; var rt = new RegExp(map[name]); From 2cdc11848abbc374064915356a3ef76d537b261c Mon Sep 17 00:00:00 2001 From: Zignature Date: Tue, 11 Jan 2022 17:16:38 +0100 Subject: [PATCH 2/4] Requested changes applied --- src/js/easymde.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/js/easymde.js b/src/js/easymde.js index d729570..9da0b55 100644 --- a/src/js/easymde.js +++ b/src/js/easymde.js @@ -793,17 +793,13 @@ function toggleHeading3(editor) { */ function toggleUnorderedList(editor) { var cm = editor.codemirror; - var liststyle = editor.options.unorderedListStyle; - liststyle = ( - liststyle != undefined - && liststyle !== '' - && liststyle.length == 1 - ) - ? liststyle - : '*'; + var listStyle = '*'; // Default + if (['-', '+', '*'].includes(editor.options.unorderedListStyle)) { + listStyle = editor.options.unorderedListStyle; + } - _toggleLine(cm, 'unordered-list', liststyle); + _toggleLine(cm, 'unordered-list', listStyle); } @@ -1210,7 +1206,7 @@ function _toggleLine(cm, name, liststyle) { var _checkChar = function (name, char) { var map = { 'quote': '>', - 'unordered-list': '\\'.liststyle, + 'unordered-list': '\\' + liststyle, 'ordered-list': '\\d+.', }; var rt = new RegExp(map[name]); From 9862ecf98c0cf0e0f476b78a9b47a5320247a338 Mon Sep 17 00:00:00 2001 From: Jeroen Akkerman Date: Tue, 11 Jan 2022 19:49:39 +0100 Subject: [PATCH 3/4] Add unorderedListStyle option to type declaration --- types/easymde-test.ts | 3 +++ types/easymde.d.ts | 1 + 2 files changed, 4 insertions(+) diff --git a/types/easymde-test.ts b/types/easymde-test.ts index 2a47ed2..5a269c3 100644 --- a/types/easymde-test.ts +++ b/types/easymde-test.ts @@ -38,6 +38,7 @@ const editor2 = new EasyMDE({ autoDownloadFontAwesome: undefined, previewClass: ['my-custom-class', 'some-other-class'], nativeSpellcheck: true, + unorderedListStyle: '-', inputStyle: 'contenteditable', toolbar: [ { @@ -104,6 +105,7 @@ const editorImages = new EasyMDE({ previewImagesInEditor: false, imageAccept: 'image/png, image/bmp', imageCSRFToken: undefined, + unorderedListStyle: '+', imageMaxSize: 10485760, imageUploadEndpoint: 'https://my.domain/image-upload/', imageTexts: { @@ -170,6 +172,7 @@ const editorImagesCustom = new EasyMDE({ new EasyMDE({ sideBySideFullscreen: true, lineNumbers: false, + unorderedListStyle: '*', autosave: { enabled: true, delay: 2000, diff --git a/types/easymde.d.ts b/types/easymde.d.ts index aaec8f7..02f06c8 100644 --- a/types/easymde.d.ts +++ b/types/easymde.d.ts @@ -206,6 +206,7 @@ declare namespace EasyMDE { onToggleFullScreen?: (goingIntoFullScreen: boolean) => void; theme?: string; scrollbarStyle?: string; + unorderedListStyle?: '*' | '-' | '+'; uploadImage?: boolean; imageMaxSize?: number; From 267db2dbe3e89a45394dcbce05332e80365a0308 Mon Sep 17 00:00:00 2001 From: Jeroen Akkerman Date: Tue, 11 Jan 2022 19:55:29 +0100 Subject: [PATCH 4/4] Update changelog --- CHANGELOG.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9da7c99..091a709 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,10 @@ All notable changes to easymde will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - +## [Unreleased] +### Added +- `unorderedListStyle` option to change the character used for unordered lists (Thanks to [@Zignature], [#389]). + ## [2.16.0] - 2021-10-28 ### Added - `direction` option to enable RTL mode (Thanks to [@souljuse], [#358]). @@ -232,6 +235,7 @@ Project forked from [SimpleMDE](https://github.com/sparksuite/simplemde-markdown [#9]: https://github.com/Ionaru/easy-markdown-editor/issues/9 +[#389]: https://github.com/Ionaru/easy-markdown-editor/pull/389 [#364]: https://github.com/Ionaru/easy-markdown-editor/pull/364 [#358]: https://github.com/Ionaru/easy-markdown-editor/pull/358 [#357]: https://github.com/Ionaru/easy-markdown-editor/pull/357 @@ -329,6 +333,7 @@ Project forked from [SimpleMDE](https://github.com/sparksuite/simplemde-markdown [@ukjinjang]: https://github.com/ukjinjang [@robjean9]: https://github.com/robjean9 [@Offerel]: https://github.com/Offerel +[@Zignature]: https://github.com/Zignature [Unreleased]: https://github.com/Ionaru/easy-markdown-editor/compare/2.16.0...HEAD