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

Allow passing a code mirror overlay mode into easymde #243

Closed
czynskee opened this issue Sep 15, 2020 · 1 comment
Closed

Allow passing a code mirror overlay mode into easymde #243

czynskee opened this issue Sep 15, 2020 · 1 comment

Comments

@czynskee
Copy link

Is your feature request related to a problem? Please describe.
First off thanks for maintaining easymde! In my app I need to do a bit of extra styling/logic based on certain tokens found in the editor (above and beyond markdown syntax). By far the easiest and best way to do this that I have found is to define a codemirror overlay mode. The overlay mode preserves all of the classes returned by the gfm mode but adds a few extra ones.

Describe the solution you'd like
An option that takes a codemirror mode and applies it as an overlay mode to the editor.

Describe alternatives you've considered
One potential alternative that may work for many people in a similar situation is to define a simple mode. This can be added to the editor after instantiation using cm.addOverlay. The limitation is that modes using this API must be stateless. In my case I needed to have a stateful mode so it was not an option.

Additional context
Here is the entry in the CM docs for overlay modes:
mode/overlay.js
Mode combinator that can be used to extend a mode with an 'overlay' — a secondary mode is run over the stream, along with the base mode, and can color specific pieces of text without interfering with the base mode. Defines CodeMirror.overlayMode, which is used to create such a mode. See this demo for a detailed example. overlay.js contains the glue code that would be needed to include the optional mode.

Here are the code mirror docs on modes: https://codemirror.net/doc/manual.html#modeapi

If a user of easymde wanted to define their own mode, they could import overlay.js and define the mode in their code. I think it would have to be on the user to make sure they properly pass 'gfm' or 'spell-checker' to their overlay mode since that part has to be passed in in the overlay mode that is being defined. Take a look at the mustache example to see what I mean.

I was able to get all of this working for my app by just cloning the repo locally, defining my mode, and passing it in to the codemirror instance that is created by easymde. If you think other folks would find this useful I've already done most of the work and would be happy to make a PR. Then I would be able to get future updates to the library as well :).

Thanks.

@Ionaru
Copy link
Owner

Ionaru commented Sep 29, 2020

Closed by #244

@Ionaru Ionaru closed this as completed Sep 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants