Skip to content

Commit

Permalink
Merge pull request #244 from czynskee/cm_overlay_mode_param
Browse files Browse the repository at this point in the history
Cm overlay mode param
  • Loading branch information
Ionaru committed Sep 29, 2020
2 parents 3c99ac8 + dc6074d commit 14a5029
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 20 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

## [Unreleased]

### Added
- `overlayMode` options to supply an additional codemirror mode ([#243]).

### Fixed
- Corrected default size units from `b,Kb,Mb` to ` B, KB, MB` ([#239]).

Expand Down
43 changes: 24 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,27 @@ The editor is entirely customizable, from theming to toolbar buttons and javascr

## Quick access

- [Install EasyMDE](#install-easymde)
- [How to use](#how-to-use)
- [Loading the editor](#loading-the-editor)
- [Editor functions](#editor-functions)
- [Configuration](#configuration)
- [Options list](#options-list)
- [Options example](#options-example)
- [Toolbar icons](#toolbar-icons)
- [Toolbar customization](#toolbar-customization)
- [Keyboard shortcuts](#keyboard-shortcuts)
- [Advanced use](#advanced-use)
- [Event handling](#event-handling)
- [Removing EasyMDE from text area](#removing-easymde-from-text-area)
- [Useful methods](#useful-methods)
- [How it works](#how-it-works)
- [SimpleMDE fork](#simplemde-fork)
- [Hacking EasyMDE](#hacking-easymde)
- [Contributing](#contributing)
- [License](#license)
- [EasyMDE - Markdown Editor](#easymde---markdown-editor)
- [Quick access](#quick-access)
- [Install EasyMDE](#install-easymde)
- [How to use](#how-to-use)
- [Loading the editor](#loading-the-editor)
- [Editor functions](#editor-functions)
- [Configuration](#configuration)
- [Options list](#options-list)
- [Options example](#options-example)
- [Toolbar icons](#toolbar-icons)
- [Toolbar customization](#toolbar-customization)
- [Keyboard shortcuts](#keyboard-shortcuts)
- [Advanced use](#advanced-use)
- [Event handling](#event-handling)
- [Removing EasyMDE from text area](#removing-easymde-from-text-area)
- [Useful methods](#useful-methods)
- [How it works](#how-it-works)
- [SimpleMDE fork](#simplemde-fork)
- [Hacking EasyMDE](#hacking-easymde)
- [Contributing](#contributing)
- [License](#license)


## Install EasyMDE
Expand Down Expand Up @@ -147,6 +149,9 @@ easyMDE.value('New input for **EasyMDE**');
- **allowAtxHeaderWithoutSpace**: If set to `true`, will render headers without a space after the `#`. Defaults to `false`.
- **strikethrough**: If set to `false`, will not process GFM strikethrough syntax. Defaults to `true`.
- **underscoresBreakWords**: If set to `true`, let underscores be a delimiter for separating words. Defaults to `false`.
- **overlayMode**: Pass a custom codemirror [overlay mode](https://codemirror.net/doc/manual.html#modeapi) to parse and style the Markdown during editing.
- **mode**: A codemirror mode object.
- **combine**: If set to `false`, will *replace* CSS classes returned by the default Markdown mode. Otherwise the classes returned by the custom mode will be combined with the classes returned by the default mode. Defaults to `true`.
- **placeholder**: If set, displays a custom placeholder message.
- **previewClass**: A string or array of strings that will be applied to the preview screen when activated. Defaults to `"editor-preview"`.
- **previewRender**: Custom function for parsing the plaintext Markdown and returning HTML. Used when user previews.
Expand Down
25 changes: 24 additions & 1 deletion src/js/easymde.js
Original file line number Diff line number Diff line change
Expand Up @@ -1745,6 +1745,10 @@ function EasyMDE(options) {
if (options.autosave != undefined && options.autosave.unique_id != undefined && 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
this.options = options;
Expand Down Expand Up @@ -1981,7 +1985,25 @@ EasyMDE.prototype.render = function (el) {
document.addEventListener('keydown', this.documentOnKeyDown, false);

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';
backdrop = options.parsingConfig;
backdrop.name = 'gfm';
Expand All @@ -1990,6 +2012,7 @@ EasyMDE.prototype.render = function (el) {
CodeMirrorSpellChecker({
codeMirrorInstance: CodeMirror,
});
}
} else {
mode = options.parsingConfig;
mode.name = 'gfm';
Expand Down
7 changes: 7 additions & 0 deletions types/easymde.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ declare namespace EasyMDE {
importError?: string;
}

interface OverlayModeOptions {
mode: CodeMirror.Mode<any>
combine?: boolean
}

interface Options {
autoDownloadFontAwesome?: boolean;
autofocus?: boolean;
Expand Down Expand Up @@ -205,6 +210,8 @@ declare namespace EasyMDE {

promptTexts?: PromptTexts;
syncSideBySidePreviewScroll?: boolean;

overlayMode?: OverlayModeOptions
}
}

Expand Down

0 comments on commit 14a5029

Please sign in to comment.