-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Migrate rich text editor to Slate backed by Unified #254
Conversation
Very promising! One thing I noticed is that it looks like we're missing the "tight" parameter for lists somewhere. Try going to https://deploy-preview-254--cms-demo.netlify.com and edit the first blog post. Double click to select a word and click the In the current version I worked around this by modifying ProseMirror's example Markdown parser to always set the |
Cool! Yeah Remark has that attribute too I noticed — just need to copy it over I guess. |
Ok pushed another commit supporting the remaining block elements + adding support for parsing inline markdown elements into the Prosemirror schema. Fenced code blocks w/ languages are now correctly handled (apparently Prosemirror always handled it but the default markdown parser didn't add the language attribute ProseMirror/prosemirror#272 (comment)). |
Also just tested html in code and it works just fine now. |
What was the problem with nested lists? I did a bit of testing and they seem fine. Also since issues with pasting from Dropbox is a separate issue, perhaps let's merge this and work on that in a separate issue? |
TODOs here that I could use help with are handling plugins + drag-n-dropped images as I don't entirely understand what's intended there. |
For plugins: If you go to the in-memory demo and use the editor, there's currently a "Youtube plugin" defined by the fictional user. https://cms-demo.netlify.com/#/collections/posts/entries/2015-02-14-this-is-a-post When you have the cursor on a new line where you can add a new block level element, you'll get the option of inserting a new Youtube embed: The example component is defined here: https://github.com/netlify/netlify-cms/blob/master/example/index.html#L132 In this case adding a youtube embed will insert a hugo style shortcode, but it could just as well be an HTML snippet, a JSX component, or whatever the static site generator building the content wants to process. In the current version of the editor, the inserted component is an opaque bloque, and you can't edit it once inserted. Ideally clicking the box should open up the same form used to create it so you can edit the values. There's some more context around this in my comments on the RTA design issue #288 For drag and dropped images, we currently use the |
@KyleAMathews awesome work on this man. I'm considering taking a step back in our trajectory for the editor and I'd like your input. So here's my thing: I'm not convinced we need to work as hard as we are, and I'm looking to avoid the overhead of maintaining so much editor customization for Netlify CMS contributors. I've got my eye on Ian Storm Taylor's new-ish Slate framework. I see a lot of benefits, but I'm curious if you've seen this particular library and your thoughts on using it, given all of the time you spent digging into the RTE. Thoughts? cc/ @biilmann |
No matter which editor framework we do, we'll want to put quite a bit of work into this component to get things like editorComponents to work etc. If you dig through the early commits you'll see we initially started out using Slate as the backend for the editor component, but had to scratch it because the core editor performance got unworkably slow for larger documents. Prose mirror and slate are very similar architecturally (both have an internal immutable document model, and requires some form of serialization/deserialization back and forth between the final output and the editors internal representation). The author of ProseMirror have managed to get corporate sponsors for a lot of his work and it's progressing really well for that reason, so I think it'll turn out to be the best choice also in the longer run... |
Perhaps just reach out to Ian and chat with him? He's in SF. I'm sure would be incredibly interested in making sure Slate works really well for the Netlify CMS in the short and long term. |
@KyleAMathews nice! Thanks for pointing that out. @biilmann good points, can't go wrong with Marijnh + corporate sponsors. It seems on Slate's demo site that it still may have issues with larger documents. |
@KyleAMathews somehow I missed your more recent updates - didn't realize this is more or less merge ready, very solid improvements! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@erquhart I think it needs support for |
Oh actually nvm, doesn't look like anything changed there. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't realize editorComponents was out, so we've still some work to do here.
package.json
Outdated
@@ -9,7 +9,6 @@ | |||
"test:watch": "jest --watch", | |||
"build": "NODE_ENV=production webpack --config webpack.prod.js", | |||
"build:scripts": "NODE_ENV=production webpack --config webpack.cli.js", | |||
"prepublish": "npm run build", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@KyleAMathews guessing this was meant to be added back in
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eh... maybe? I find prepublish scripts like this super annoying. But I can add it back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree on the annoyance front, but publishing a broken build is worth avoiding. We did recently drop the precommit hook, which should take the annoyance factor down by an order of magnitude.
this.plugins = {}; | ||
// TODO add back support for this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, missed this
import { EditorState } from 'prosemirror-state'; | ||
import { EditorView } from 'prosemirror-view'; | ||
import history from 'prosemirror-history'; | ||
import React, { Component, PropTypes } from "react"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guessing a package update is causing our linter to require double quotes?
Just got back from a trip — will finish this up in next day or two. |
Thanks @KyleAMathews - hope you had a good trip! The primary concern here is ensuring against breaks to existing functionality such as |
c635fb4
to
fe40c01
Compare
Could someone explain the relationship between plugins and tokens? In this line https://github.com/netlify/netlify-cms/pull/254/files#diff-5d32b738f6c2db4fdf6fce8e1c55e110L103 It seems like plugins are relying on the token names provided by the default ProseMirror markdown parser? |
If so, they'd need to be updated to rely on the AST provided by Remark. |
@KyleAMathews I'd have to dig in to understand that part myself. I'll have a look soon if no one else beats me to it. |
I know this is sort of at the end of this PR lifecycle, but I was wondering where this issues falls within the overall scope. Generators like Hexio.io use "tag plugins" to extend markup, which the current solution breaks (they get rewritten as "code"). Also, the same generator allows HTML, which also gets rewritten. Does this PR address any of those issues or offer a path to resolving them? Basically, need a "don't clean this, just pass it through" switch. |
@jholmes033169 this branch does run - pull it down and try it out for your use case. I don't know much about Hexo (yet), but we do want max compatibility. |
@KyleAMathews the tokenization is more related to our use of MarkupIt, but the plugin tokens are created in the CMS - see the augmented syntax function here: https://github.com/netlify/netlify-cms/blob/e66b3597ef7b67862705f1e6f42b9af8f82162c2/src/components/Widgets/richText.js#L27 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to make sure I don't forget to double check this before it's merged. Please, make sure the branch is properly rebased and there are no extra commits that don't belong to this change.
This is awesome @erquhart. Good job 💪 |
broken by rebase after #254 merge
broken by rebase after #254 merge
broken by rebase after #254 merge
broken by rebase after decaporg#254 merge
broken by rebase after #254 merge
broken by rebase after #254 merge
broken by rebase after #254 merge
broken by rebase after #254 merge
broken by rebase after #254 merge
broken by rebase after #254 merge
broken by rebase after #254 merge
broken by rebase after #254 merge
broken by rebase after #254 merge
fixes #246
- Summary
Currently netlify-cms uses three different libraries for handling Markdown. markup-it for the render preview, markdown-it transforming markdown src to Prosemirror's document model, and finally Prosemirror's internal deserialization from their internal model back to Markdown.
There's been several inconsistencies that develop because of this. Also using multiple libraries raises the barrier to contributing bug fixes and new features.
This WIP PR consolidates all of these on the Remark library as it exposes a very nice AST for Markdown that makes it easy to do the conversions we need.
What's done currently is switching in Remark for markup-it for rendering markdown plus most of the compilation process from markdown source to the prosemirror document model.
So that part needs finished plus writing the deserialization method for converting prosemirror to remark to raw markdown. Also looking into the paste from dropbox problem (not related to the markdown conversion though so could be pushed into a different PR).
Also need to restore plugin support which I'll want to talk to you about @biilmann as not entirely sure how that should work.