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

Expose the CodeMirror library object, so static methods like defineExtension can be called on it #263

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

brondsem
Copy link

Hi,

This is a very small change to enable more customization of EasyMDE/CodeMirror, like allowing addons to be used (fixes [#188] then). Otherwise there is no way to run CodeMirror static methods.

It is very similar to [#76] but more cautious (not setting global window.CodeMirror).
In that pull request it was suggested to just package another copy of CodeMirror, but that doesn't work because running CodeMirror.defineExtension(...) would only affect the separate copy and not the one used by EasyMDE.

Steps to enable a CodeMirror addon would be:

  • include easymde.min.js on page as usual
  • EasyMDE.CodeMirror.defineExtension(...)
  • or if you want to use a standard addon: window.CodeMirror = EasyMDE.CodeMirror and include the addon .js file

@Ionaru
Copy link
Owner

Ionaru commented Oct 30, 2020

I'm tempted to raise the same argument I did back then: The editor cannot guarantee that the entire unchanged CodeMirror library will be included with it. With this change, you, and others, will assume that it does by using methods from that library.

I think the solution offered by @coconutpalm in his comment on PR #76 is better.

@brondsem
Copy link
Author

brondsem commented Nov 2, 2020

Ok, I've added a commit that does that.

Standard codemirror.js is currently 389K (129K on gzip) so I think there's still a case for avoiding 2 instances of the library on a page. Exposing the internal instance seems simple (if folks use it at their own risk). Maybe another option would be an EasyMDE build that doesn't include codemirror.

@Ionaru
Copy link
Owner

Ionaru commented Nov 2, 2020

I'm asuming 129K is unminified and can be reduced further because the EasyMDE package is only 95.7K.

@brondsem
Copy link
Author

brondsem commented Nov 2, 2020

Yes, that's lib/codemirror.js straight from CodeMirror's release zip - they don't provide a minified version. Minified I get it at 168K; 66K gzipped.

@@ -2863,4 +2863,6 @@ EasyMDE.prototype.toTextArea = function () {
}
};

EasyMDE.CodeMirror = CodeMirror;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't needed anymore, right?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for your preferred approach, correct. I'd still find it useful to avoid ~66K duplication though.

savvan0h added a commit to udzuki/easy-markdown-editor that referenced this pull request Sep 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants