Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for issue #386 Show '-' instead of '*' for unordered list #389

Merged
merged 4 commits into from
Jan 11, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -242,6 +243,7 @@ const editor = new EasyMDE({
bold: "__",
italic: "_",
},
unorderedListStyle: "-",
element: document.getElementById("MyID"),
forceSync: true,
hideIcons: ["guide", "heading"],
Expand Down
14 changes: 10 additions & 4 deletions src/js/easymde.js
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,13 @@ function toggleHeading3(editor) {
*/
function toggleUnorderedList(editor) {
var cm = editor.codemirror;
_toggleLine(cm, 'unordered-list');

var listStyle = '*'; // Default
if (['-', '+', '*'].includes(editor.options.unorderedListStyle)) {
listStyle = editor.options.unorderedListStyle;
}

_toggleLine(cm, 'unordered-list', listStyle);
}


Expand Down Expand Up @@ -1171,7 +1177,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;

Expand All @@ -1190,7 +1196,7 @@ function _toggleLine(cm, name) {
var _getChar = function (name, i) {
var map = {
'quote': '>',
'unordered-list': '*',
'unordered-list': liststyle,
'ordered-list': '%%i.',
};

Expand All @@ -1200,7 +1206,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]);
Expand Down