mirror of
https://github.com/Ionaru/easy-markdown-editor
synced 2025-09-24 16:40:55 -06:00
Merge 5ecb1e9ee2fc71db4eda83ae3eecd31e6029c04d into 43abcaf655f0b86579ed6f58d090e80e0f6da9d5
This commit is contained in:
commit
d541288392
@ -23,6 +23,7 @@ var anchorToExternalRegex = new RegExp(/(<a.*?https?:\/\/.*?[^a]>)+?/g);
|
|||||||
var bindings = {
|
var bindings = {
|
||||||
'toggleBold': toggleBold,
|
'toggleBold': toggleBold,
|
||||||
'toggleItalic': toggleItalic,
|
'toggleItalic': toggleItalic,
|
||||||
|
'toggleUnderline': toggleUnderline,
|
||||||
'drawLink': drawLink,
|
'drawLink': drawLink,
|
||||||
'toggleHeadingSmaller': toggleHeadingSmaller,
|
'toggleHeadingSmaller': toggleHeadingSmaller,
|
||||||
'toggleHeadingBigger': toggleHeadingBigger,
|
'toggleHeadingBigger': toggleHeadingBigger,
|
||||||
@ -48,6 +49,7 @@ var bindings = {
|
|||||||
var shortcuts = {
|
var shortcuts = {
|
||||||
'toggleBold': 'Cmd-B',
|
'toggleBold': 'Cmd-B',
|
||||||
'toggleItalic': 'Cmd-I',
|
'toggleItalic': 'Cmd-I',
|
||||||
|
'toggleUnderline': 'Cmd-U',
|
||||||
'drawLink': 'Cmd-K',
|
'drawLink': 'Cmd-K',
|
||||||
'toggleHeadingSmaller': 'Cmd-H',
|
'toggleHeadingSmaller': 'Cmd-H',
|
||||||
'toggleHeadingBigger': 'Shift-Cmd-H',
|
'toggleHeadingBigger': 'Shift-Cmd-H',
|
||||||
@ -195,6 +197,8 @@ function getState(cm, pos) {
|
|||||||
ret.quote = true;
|
ret.quote = true;
|
||||||
} else if (data === 'em') {
|
} else if (data === 'em') {
|
||||||
ret.italic = true;
|
ret.italic = true;
|
||||||
|
} else if (data === 'u') {
|
||||||
|
ret.underline = true;
|
||||||
} else if (data === 'quote') {
|
} else if (data === 'quote') {
|
||||||
ret.quote = true;
|
ret.quote = true;
|
||||||
} else if (data === 'strikethrough') {
|
} else if (data === 'strikethrough') {
|
||||||
@ -283,6 +287,14 @@ function toggleItalic(editor) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Action for toggling underline.
|
||||||
|
*/
|
||||||
|
function toggleUnderline(editor) {
|
||||||
|
_toggleBlock(editor, 'underline', editor.options.blockStyles.underline);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Action for toggling strikethrough.
|
* Action for toggling strikethrough.
|
||||||
*/
|
*/
|
||||||
@ -1022,11 +1034,14 @@ function _toggleBlock(editor, type, start_chars, end_chars) {
|
|||||||
start = text.slice(0, startPoint.ch);
|
start = text.slice(0, startPoint.ch);
|
||||||
end = text.slice(startPoint.ch);
|
end = text.slice(startPoint.ch);
|
||||||
if (type == 'bold') {
|
if (type == 'bold') {
|
||||||
start = start.replace(/(\*\*|__)(?![\s\S]*(\*\*|__))/, '');
|
start = start.replace(/\*\*(?![\s\S]*\*\*)/, '');
|
||||||
end = end.replace(/(\*\*|__)/, '');
|
end = end.replace(/\*\*/, '');
|
||||||
} else if (type == 'italic') {
|
} else if (type == 'italic') {
|
||||||
start = start.replace(/(\*|_)(?![\s\S]*(\*|_))/, '');
|
start = start.replace(/(\*|_)(?![\s\S]*(\*|_))/, '');
|
||||||
end = end.replace(/(\*|_)/, '');
|
end = end.replace(/(\*|_)/, '');
|
||||||
|
} else if (type == 'underline') {
|
||||||
|
start = start.replace(/__(?![\s\S]*__)/, '');
|
||||||
|
end = end.replace(/__/, '');
|
||||||
} else if (type == 'strikethrough') {
|
} else if (type == 'strikethrough') {
|
||||||
start = start.replace(/(\*\*|~~)(?![\s\S]*(\*\*|~~))/, '');
|
start = start.replace(/(\*\*|~~)(?![\s\S]*(\*\*|~~))/, '');
|
||||||
end = end.replace(/(\*\*|~~)/, '');
|
end = end.replace(/(\*\*|~~)/, '');
|
||||||
@ -1039,7 +1054,7 @@ function _toggleBlock(editor, type, start_chars, end_chars) {
|
|||||||
ch: 99999999999999
|
ch: 99999999999999
|
||||||
});
|
});
|
||||||
|
|
||||||
if (type == 'bold' || type == 'strikethrough') {
|
if (type == 'bold' || type == 'underline' || type == 'strikethrough') {
|
||||||
startPoint.ch -= 2;
|
startPoint.ch -= 2;
|
||||||
if (startPoint !== endPoint) {
|
if (startPoint !== endPoint) {
|
||||||
endPoint.ch -= 2;
|
endPoint.ch -= 2;
|
||||||
@ -1058,6 +1073,8 @@ function _toggleBlock(editor, type, start_chars, end_chars) {
|
|||||||
} else if (type == 'italic') {
|
} else if (type == 'italic') {
|
||||||
text = text.split('*').join('');
|
text = text.split('*').join('');
|
||||||
text = text.split('_').join('');
|
text = text.split('_').join('');
|
||||||
|
} else if (type == 'underline') {
|
||||||
|
text = text.split('__').join('');
|
||||||
} else if (type == 'strikethrough') {
|
} else if (type == 'strikethrough') {
|
||||||
text = text.split('~~').join('');
|
text = text.split('~~').join('');
|
||||||
}
|
}
|
||||||
@ -1154,6 +1171,12 @@ var toolbarBuiltInButtons = {
|
|||||||
title: 'Italic',
|
title: 'Italic',
|
||||||
default: true
|
default: true
|
||||||
},
|
},
|
||||||
|
'underline': {
|
||||||
|
name: 'underline',
|
||||||
|
action: toggleUnderline,
|
||||||
|
className: 'fa fa-underline',
|
||||||
|
title: 'Underline'
|
||||||
|
},
|
||||||
'strikethrough': {
|
'strikethrough': {
|
||||||
name: 'strikethrough',
|
name: 'strikethrough',
|
||||||
action: toggleStrikethrough,
|
action: toggleStrikethrough,
|
||||||
@ -1336,7 +1359,8 @@ var promptTexts = {
|
|||||||
var blockStyles = {
|
var blockStyles = {
|
||||||
'bold': '**',
|
'bold': '**',
|
||||||
'code': '```',
|
'code': '```',
|
||||||
'italic': '*'
|
'italic': '*',
|
||||||
|
'underline': '__'
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1995,6 +2019,7 @@ EasyMDE.prototype.value = function (val) {
|
|||||||
*/
|
*/
|
||||||
EasyMDE.toggleBold = toggleBold;
|
EasyMDE.toggleBold = toggleBold;
|
||||||
EasyMDE.toggleItalic = toggleItalic;
|
EasyMDE.toggleItalic = toggleItalic;
|
||||||
|
EasyMDE.toggleUnderline = toggleUnderline;
|
||||||
EasyMDE.toggleStrikethrough = toggleStrikethrough;
|
EasyMDE.toggleStrikethrough = toggleStrikethrough;
|
||||||
EasyMDE.toggleBlockquote = toggleBlockquote;
|
EasyMDE.toggleBlockquote = toggleBlockquote;
|
||||||
EasyMDE.toggleHeadingSmaller = toggleHeadingSmaller;
|
EasyMDE.toggleHeadingSmaller = toggleHeadingSmaller;
|
||||||
@ -2025,6 +2050,9 @@ EasyMDE.prototype.toggleBold = function () {
|
|||||||
EasyMDE.prototype.toggleItalic = function () {
|
EasyMDE.prototype.toggleItalic = function () {
|
||||||
toggleItalic(this);
|
toggleItalic(this);
|
||||||
};
|
};
|
||||||
|
EasyMDE.prototype.toggleUnderline = function () {
|
||||||
|
toggleUnderline(this);
|
||||||
|
};
|
||||||
EasyMDE.prototype.toggleStrikethrough = function () {
|
EasyMDE.prototype.toggleStrikethrough = function () {
|
||||||
toggleStrikethrough(this);
|
toggleStrikethrough(this);
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user