mirror of
https://github.com/Ionaru/easy-markdown-editor
synced 2025-07-30 21:34:28 -06:00
Added option to supply an additional code-mirror overlay mode
This commit is contained in:
parent
00215ecaeb
commit
4ce74e904b
@ -5,6 +5,10 @@ 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).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- `overlayMode` options to supply an additional codemirror mode ([#243]).
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Corrected default size units from `b,Kb,Mb` to ` B, KB, MB` ([#239]).
|
- Corrected default size units from `b,Kb,Mb` to ` B, KB, MB` ([#239]).
|
||||||
|
|
||||||
|
@ -1745,6 +1745,10 @@ function EasyMDE(options) {
|
|||||||
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;
|
options.autosave.uniqueId = options.autosave.unique_id;
|
||||||
|
|
||||||
|
// If overlay mode is specified and combine is not provided, default it to true
|
||||||
|
if (options.overlayMode && options.overlayMode.combine === undefined) {
|
||||||
|
options.overlayMode.combine = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Update this options
|
// Update this options
|
||||||
this.options = options;
|
this.options = options;
|
||||||
@ -1981,7 +1985,25 @@ EasyMDE.prototype.render = function (el) {
|
|||||||
document.addEventListener('keydown', this.documentOnKeyDown, false);
|
document.addEventListener('keydown', this.documentOnKeyDown, false);
|
||||||
|
|
||||||
var mode, backdrop;
|
var mode, backdrop;
|
||||||
if (options.spellChecker !== false) {
|
|
||||||
|
// CodeMirror overlay mode
|
||||||
|
if (options.overlayMode) {
|
||||||
|
CodeMirror.defineMode('overlay-mode', function(config) {
|
||||||
|
return CodeMirror.overlayMode(CodeMirror.getMode(config, options.spellChecker !== false ? 'spell-checker' : 'gfm'), options.overlayMode.mode, options.overlayMode.combine);
|
||||||
|
});
|
||||||
|
|
||||||
|
mode = 'overlay-mode';
|
||||||
|
backdrop = options.parsingConfig;
|
||||||
|
backdrop.gitHubSpice = false;
|
||||||
|
|
||||||
|
if (options.spellChecker !== false) {
|
||||||
|
backdrop.name = 'gfm';
|
||||||
|
|
||||||
|
CodeMirrorSpellChecker({
|
||||||
|
codeMirrorInstance: CodeMirror,
|
||||||
|
});
|
||||||
|
|
||||||
|
} else if (options.spellChecker !== false) {
|
||||||
mode = 'spell-checker';
|
mode = 'spell-checker';
|
||||||
backdrop = options.parsingConfig;
|
backdrop = options.parsingConfig;
|
||||||
backdrop.name = 'gfm';
|
backdrop.name = 'gfm';
|
||||||
@ -1990,6 +2012,7 @@ EasyMDE.prototype.render = function (el) {
|
|||||||
CodeMirrorSpellChecker({
|
CodeMirrorSpellChecker({
|
||||||
codeMirrorInstance: CodeMirror,
|
codeMirrorInstance: CodeMirror,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
mode = options.parsingConfig;
|
mode = options.parsingConfig;
|
||||||
mode.name = 'gfm';
|
mode.name = 'gfm';
|
||||||
|
7
types/easymde.d.ts
vendored
7
types/easymde.d.ts
vendored
@ -159,6 +159,11 @@ declare namespace EasyMDE {
|
|||||||
importError?: string;
|
importError?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface OverlayModeOptions {
|
||||||
|
mode: CodeMirror.Mode<any>
|
||||||
|
combine?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
interface Options {
|
interface Options {
|
||||||
autoDownloadFontAwesome?: boolean;
|
autoDownloadFontAwesome?: boolean;
|
||||||
autofocus?: boolean;
|
autofocus?: boolean;
|
||||||
@ -205,6 +210,8 @@ declare namespace EasyMDE {
|
|||||||
|
|
||||||
promptTexts?: PromptTexts;
|
promptTexts?: PromptTexts;
|
||||||
syncSideBySidePreviewScroll?: boolean;
|
syncSideBySidePreviewScroll?: boolean;
|
||||||
|
|
||||||
|
overlayMode?: OverlayModeOptions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user